[英]“display='block'” not keeping my DIVs on the same line
I'm trying to get two DIVs to stay on the same horizontal plane. 我试图使两个DIV保持在同一水平面。 I have 我有
<div id="timeChanges">
<div id="oneDayChange" class="change">
One day change
<div>
<div id="downArrow" class="downArrow arrow"></div>
- 14.961 / -7.66 %
</div>
</div>
<div id="oneWeekChange" class="change">
One week change
<div>
<div id="upArrow" class="upArrow arrow"></div>
+ 34.863 / 17.851 %
</div>
</div>
</div>
and have tried the CSS 并尝试了CSS
#timeChanges {
display: inline-block;
}
I've also tried just "block" for the above. 我也尝试了上述的“阻止”。 But as you can see, https://jsfiddle.net/Ldk7ovjp/1/ , my two DIVs are on different lines. 但是正如您所看到的, https: //jsfiddle.net/Ldk7ovjp/1/,我的两个DIV位于不同的行上。 How do I keep them on the same one? 如何使它们保持同一状态?
Using display:inline-block
on the change
class seems to work: 在change
类上使用display:inline-block
似乎有效:
.change {
display:inline-block;
}
You have to apply the inline-block to both div elements: 您必须将inline-block应用于两个div元素:
.change{
display: inline-block;
}
Add below css in the end. 最后在css下面添加。
#oneWeekChange , #oneDayChange{
float:left
}
Full CSS is as below for your reference 完整的CSS如下供您参考
#timeChanges {
display: inline-block;
float:left;
}
.arrow {
display: inline-block;
vertical-align: middle;
}
.arrow:after {
height: 30px;
width: 30px;
display: inline-block;
content: '';
}
.upArrow:after {
background: linear-gradient(60deg, transparent 63%, #fff 63%), linear-gradient(-60deg, transparent 63%, #fff 63%), linear-gradient(to bottom, #ccc, #000);
}
.downArrow:after {
background: linear-gradient(120deg, transparent 63%, #fff 63%), linear-gradient(-120deg, transparent 63%, #fff 63%), linear-gradient(to top, #ccc, #000);
}
#oneWeekChange , #oneDayChange{
float:left
}
If you want to add display inline block, make sure to the class change. 如果要添加显示内联块,请确保对类进行更改。
.change {
display:inline-block;
}
If you want to horizontally divs with id timeChanges, you can use inline-flex or flex. 如果要使用id timeChanges来水平分割div,则可以使用inline-flex或flex。 For example : 例如 :
#timeChanges {
display:inline-flex;
//display: flex;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.