How to horizontally center an HTML <div> within another <div> in CSS

2 Answers

0 votes
<!DOCTYPE html>
<html>
    <head>
        <style>
            div.hc {
                width: 300px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div>
            <div class="hc">Horizontally center a div within another div</div>
        </div>
    </body>
</html>

 



answered Nov 20, 2018 by avibootz
0 votes
<!DOCTYPE html>
<html>
    <head>
        <style>
            div.ohc {
                text-align: center;
            }
            div.ihc {
                display: inline-block;
            }
        </style>
    </head>
    <body>
        <div class="ohc">
            <div class="ihc">Horizontally center a div within another div</div>
        </div>
    </body>
</html>

 



answered Nov 20, 2018 by avibootz

Related questions

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