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 331 views
1 answer 254 views
1 answer 217 views
217 views asked Dec 18, 2018 by avibootz
4 answers 521 views
2 answers 299 views
1 answer 229 views
1 answer 293 views
...