Center Text Larger than Container? (Without using separate child element)

后端 未结 3 838
鱼传尺愫
鱼传尺愫 2021-02-08 14:21

Using CSS, it\'s easy to horizontally center text in a container using text-align:center;, but if any single word of that text is larger than the width of the c

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-08 14:34

    That damned horizontal scrollbar!

    http://jsfiddle.net/sqKU6/

    aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa

    CSS:

    .inner {
        text-align: center;
        position: relative;
        left: +450%;
    }
    .inner:before {
        content: '';
        display: inline-block;
        margin-right: -900%;
    }
    ​
    

提交回复
热议问题