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