How can I center a box of unknown width in CSS?

后端 未结 7 760
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 19:39

I have this html:

This is the caption &l
相关标签:
7条回答
  • 2020-12-13 20:12

    A div tag didn't seem to work; however, a span tag shrinked to fit. Hopefully the code explains itself. I added a few alignments as well.

    <html>
        <head>
            <title>TEST!</title>
            <style type="text/css"> 
                .object-box-wrapper{width:100%;text-align:center;}
                .object-box {
                    border: 1px solid;
                    text-align:left;
                }
            </style>
        </head>
        <body>
            <div class="object-box-wrapper">
                <span class="object-box">
                    <span class="caption">This is the caption</span>
                </span>
            </div>
        </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题