html - CSS:当文本很长时,具有自动宽度的内联 Div 会下推

标签 html css

我面临与 inline-div 有关的 css 问题。 当文本(或句子)很长时,内联 div 会向下推,如下图所示:enter image description here

但是,当我添加换行符时,它工作得很好。 enter image description here

如何使其工作而无需使用 <br>

要发布的主要内容是动态的,并且还需要响应。 谢谢

Please Note: This is a simplified version of my actual code. In the actual code the width of the main container is 100%

HTML

<div id="container">
<div id="firstDiv">FIRST</div>
<div id="secondDiv">SECOND</div>
<div id="thirdDiv">THIRD
<br>some more content<br> some more content
</div>

CSS

body{
    width: 350px;
    margin: 0px auto;
}
#container {
    border: 15px solid orange;   
}
#firstDiv{
    border: 10px solid brown;     
    display:inline-block;
    width: 70px;      
    overflow:hidden; 
    vertical-align:top;
}
#secondDiv{
    border: 10px solid skyblue;         
    float:left;
    width: 70px;     
}
#thirdDiv{
    display:inline-block;
    border: 5px solid yellowgreen; 
    vertical-align:top;    
}

最佳答案

使用:white-space: nowrap;作为包含长句子的div。

关于html - CSS:当文本很长时,具有自动宽度的内联 Div 会下推,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43148548/

相关文章:

css - 为什么动态生成的内容不改变包含div的高度?

html - 多个属性的CSS?

javascript - 在加载时应用选择背景颜色?

css - 禁用边框(边框 : 0 none)

css - 我应该使用 Div、Span、Nav 还是标题标签

javascript - 如何在纯 HTML5/CSS/Jquery 中显示 epub 格式的书

javascript - 从 xml 响应中获取 svg 元素

javascript - 正则表达式替换包含变量的字符串

javascript - 在页面加载时将相同的随机颜色分配给多个 div

css - 在 2 个 div 之间加载 CSS 作为 stylesheet.css