How to horizontally center an HTML <div> with CSS

2 Answers

0 votes
<!DOCTYPE html>
<html>
    <head>
        <style>
            div.hc {
                width: 220px;
                display: block;
                margin-left: auto;
                margin-right: auto;
            }
        </style>
    </head>
    <body>
        <div class="hc">Horizontally center a div</div>
    </body>
</html>

 



answered Nov 20, 2018 by avibootz
0 votes
<!DOCTYPE html>
<html>
    <head>
        <style>
            div.hc {
                width: 220px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="hc">Horizontally center a div</div>
    </body>
</html>

 



answered Nov 20, 2018 by avibootz

Related questions

2 answers 313 views
1 answer 236 views
1 answer 208 views
208 views asked Dec 18, 2018 by avibootz
4 answers 502 views
2 answers 278 views
1 answer 219 views
1 answer 276 views
...