我有3个并排的div,但当我在div中放入太多文本时,它会将其推到新行上。
.consoleRed {
background: #d83435;
border-radius: 5px;
border: 1px #000 solid;
color: #fff;
margin: 5px;
}
.consoleIcon {
float: left;
}
.consoleDesc {
float: left;
vertical-align: top;
}
.consoleDesc h3 {
margin: 1px;
padding: 1px;
font-size: 14px;
}

<div class="container">
<h2>Select a Console</h2>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">Little Text is fine</div>
<div class="clearfix"></div>
</div>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">When i add too much text it ends up pushing the whole div onto the new line</div>
<div class="clearfix"></div>
</div>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">Not sure why</div>
<div class="clearfix"></div>
</div>
</div>
&#13;
答案 0 :(得分:1)
您可以使用 flexbox 。这非常适合处理CSS中的并排处理。
您可以尝试以下代码:
.replace(..., '')
.consoleRed {
background: #d83435;
border-radius: 5px;
border: 1px #000 solid;
color: #fff;
margin: 5px;
display : flex;
}
.consoleDesc {
float: left;
vertical-align: top;
}
.consoleDesc h3 {
margin: 1px;
padding: 1px;
font-size: 14px;
}
答案 1 :(得分:0)
Added the row class and aligned text using CSS:
<div class="container">
<h2>Select a Console</h2>
<div class="row">
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">Little Text is fine</div>
<div class="clearfix"></div>
</div>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">When i add too much text it ends up pushing the whole div onto the new line</div>
<div class="clearfix"></div>
</div>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">Not sure whyffsdfsdfsdfsdfsdfsdfsdfdsfdsfdsfsdfsdfsdfsdfsdfdsfdsfsdfdsfsdfdsfsdfdfdsfdsfdf</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<style>
.consoleRed {
background: #d83435;
border-radius: 5px;
border: 1px #000 solid;
color: #fff;
margin: 5px;
}
.consoleIcon {
float: left;
}
.consoleDesc h3{
margin: 1px;
padding: 1px;
font-size: 14px;
text-align:justify;
}
</style>
答案 2 :(得分:0)
只需删除float:left
.consoleDesc {
float: left;<-------------Remove this
//more code...
}
.consoleRed {
background: #d83435;
border-radius: 5px;
border: 1px #000 solid;
color: #FFF;
margin: 5px;
}
.consoleIcon {
float: left;
}
.consoleDesc {
vertical-align: top;
}
.consoleDesc h3 {
margin: 1px;
padding: 1px;
font-size: 14px;
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<h2>Select a Console</h2>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">Little Text is fine</div>
<div class="clearfix"></div>
</div>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">When i add too much text it ends up pushing the whole div onto the new line</div>
<div class="clearfix"></div>
</div>
<div class="col-lg-4 consoleRed">
<div class="consoleIcon"><img width="64" height="64" src="images/3ds.png"></div>
<div class="consoleDesc">Not sure why</div>
<div class="clearfix"></div>
</div>
</div>
&#13;