Website Development Prices

Search Blog

Wednesday, December 9, 2020

How to move a div element?

How to move to the right div element or any other element.

Solution: add block property.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>css Tips and Tricks</title>
      <link href="css/style.css" rel="stylesheet" />
  </head>
  <body>
    <div id="div1">Center this sentence.</div>
  </body>
</html>

Save this file as, for example, css-tricks.html, in your css-tricks folder. 


Now add css.

#div1 {
  display: block;
  margin: auto;
  width: 50% 
}

Save this file as, for example style.css, in your css folder, which is in your css-tricks folder.



I added one more div element with more text and some css in order to see it better (I'm wearing glasses and I can see only 70% with them, that was 3 years ago, might got worse) so my standard font size is 18px :)





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.