HTML+CSS: How to force div contents to stay in one line?

后端 未结 10 1941
小蘑菇
小蘑菇 2020-11-30 17:52

I have a long text inside a div with defined width:

HTML:

Stack Overflow is the BEST !!!

CSS:



        
10条回答
  •  抹茶落季
    2020-11-30 18:06

    Try setting a height so the block cannot grow to accommodate your text, and keep the overflow: hidden parameter

    EDIT: Here is an example of what you might like if you need to display 2 lines high:

    div {
        border: 1px solid black;
        width: 70px;
        height: 2.2em;
        overflow: hidden;
    }
    

提交回复
热议问题