首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当出现多余文本时,Div将移至下一行

当出现多余文本时,Div将移至下一行
EN

Stack Overflow用户
提问于 2018-02-21 17:22:53
回答 3查看 69关注 0票数 0

只要.story类中有多余的文本,<div>就会移到下一行。设置固定宽度是不可能的,因为它需要响应,而且文本无论如何都不会在<div>周围换行。

隐藏溢出只会隐藏<div>,而white-space: nowrap没有任何效果。我是不是漏掉了什么简单的东西?非常感谢!

代码语言:javascript
复制
.break{
    margin-top: 40px;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
      background: #fff;
}
.breakBox{
    width: 100%;
    font-size: 12px;
    background: #000000;
    color: #000000;
    display: block;
    font-size: 20px;
    height: 40px;
    position: relative;
    width: 1088px;
    margin: 0 auto;
    text-transform: uppercase;
    top: 10px;
    margin-bottom: 10px;
}
.breakBox>div.title {
    font-weight: bold;
    width: 160px;
    float: left;
    width: auto;
    background: #FFEF00;
    color: #000000;
}
.breakBox>div {
    display: block;
    height: 40px;
    line-height: 40px;
    padding: 0 12px;
    text-align: left;
    vertical-align: middle;
}
.breakBox>div.story {
    left: 160px;
    overflow: hidden;
    top: 0;
    display: block;
    float: left;
    width: auto;
    background: #000;
    color: #fff;
    font-weight: bold;
}
代码语言:javascript
复制
<div class="break">
			    
    <div class="breakBox">
        <div class="title">some text here</div>
	    <div class="story">
            
            More text goes here... More text goes here... More text goes here... More text
            
        </div>
    </div>

		    </div>

EN

回答 3

Stack Overflow用户

发布于 2018-02-21 17:35:03

你只需要减小.story div的字体大小。如果您向.story添加更多内容,则需要再次相应地减少font-size

代码语言:javascript
复制
.break{
    margin-top: 40px;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
      background: #fff;
}
.breakBox{
    width: 100%;
    font-size: 12px;
    background: #000000;
    color: #000000;
    display: block;
    font-size: 20px;
    height: 40px;
    position: relative;
    width: 1088px;
    margin: 0 auto;
    text-transform: uppercase;
    top: 10px;
    margin-bottom: 10px;
}
.breakBox>div.title {
    font-weight: bold;
    width: 160px;
    float: left;
    width: auto;
    background: #FFEF00;
    color: #000000;
}
.breakBox>div {
    display: block;
    height: 40px;
    line-height: 40px;
    padding: 0 12px;
    text-align: left;
    vertical-align: middle;
}
.breakBox>div.story {
    left: 160px;
    overflow: hidden;
    top: 0;
    display: block;
    float: left;
    width: auto;
    background: #000;
    color: #fff;
    font-weight: bold;
    font-size:18px;
}
代码语言:javascript
复制
<div class="break">
			    
    <div class="breakBox">
        <div class="title">some text here</div>
	    <div class="story">
            
            More text goes here... More text goes here... More text goes here... More text
            
        </div>
    </div>

		    </div>

票数 0
EN

Stack Overflow用户

发布于 2018-02-21 17:43:51

您好,请在.breakBox>div中使用height:auto。你使用了height:40px,这就是问题所在。谢谢

票数 0
EN

Stack Overflow用户

发布于 2018-02-21 18:12:01

.breakBox>div.story中删除display: block;float: left;怎么样?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48902170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档