且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在CSS中居中元素?

更新时间:2022-06-03 09:53:59

三个相同的 span 100px宽度的元素,其中 display:inline-block 嵌套在 div $ c> with text-align 设为中心: http:// jsfiddle .net / e9sru /

I would use three identical span elements of 100px width, with display: inline-block nested inside a div with text-align set to center: http://jsfiddle.net/e9sru/

HTML:

HTML:

<div id="container">
    <span class="inner">
        <div class="overflow">Lorem ipsum dolor est mori. I am overflowing but still to the left of number two</div>
    </span>
    <span class="inner">Two</span>
    <span class="inner">Three</span>
</div>

CSS:

CSS:

#container {
    text-align: center;
}

.inner {
    display: inline-block;
    position: relative;
}

.overflow {
    float: right;
}