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 327 views
1 answer 247 views
1 answer 213 views
213 views asked Dec 18, 2018 by avibootz
4 answers 518 views
2 answers 295 views
1 answer 226 views
1 answer 289 views
...