How to horizontally center an element in CSS

2 Answers

0 votes
<!-- HTML -->

<!DOCTYPE html>
<html>
<body>
<div id="divid">Horizontally center this element</div>
</body>
</html>
 

/* CSS */

#divid {
  display: table;
  margin: 0 auto;
  border: 1px solid green;
}

 



answered Dec 25, 2021 by avibootz
edited Dec 25, 2021 by avibootz
0 votes
<!-- HTML -->

<!DOCTYPE html>
<html>
<body>
<div id="divid">
    <p>Horizontally center div element</p>
</div>
</body>
</html>
/* CSS */

#divid {
  margin: auto;
  width: 50%;
  border: 1px solid green;
  padding: 10px;
}

 



answered Dec 25, 2021 by avibootz

Related questions

1 answer 223 views
1 answer 286 views
1 answer 242 views
2 answers 324 views
2 answers 295 views
1 answer 229 views
1 answer 271 views
...