我有一个包含键值对信息的框。如果值框太宽并且遇到密钥框,则值框必须在密钥框下方下拉
https://jsfiddle.net/nwpems8w/
第三行的值必须在密钥框下面下拉?怎么做?
.box {
background: #aaa;
width: 150px;
}
.box_prop {
clear: both;
text-align: right;
}
.box_key {
float: left;
}
.box_value {
font-weight: bold;
}

<div class="box">
<div class="box_prop">
<div class="box_key">key</div>
<div class="box_value">value</div>
</div>
<div class="box_prop">
<div class="box_key">key long</div>
<div class="box_value">value long</div>
</div>
<div class="box_prop">
<div class="box_key">key giga long</div>
<div class="box_value">value giga long</div>
</div>
</div>
&#13;
答案 0 :(得分:1)
在float: right
上使用.box-value
并在父级上设置布局。
.box_value {
float: right;
}
.box {
background:#aaa;
width:150px;
}
.box_prop {
overflow: hidden;
}
.box_key {
float:left;
}
.box_value {
font-weight:bold;
text-align: right;
float: right;
}
&#13;
<div class="box">
<div class="box_prop">
<div class="box_key">key</div>
<div class="box_value">value</div>
</div>
<div class="box_prop">
<div class="box_key">key long</div>
<div class="box_value">value long</div>
</div>
<div class="box_prop">
<div class="box_key">key giga long</div>
<div class="box_value">value giga long value giga longvalue giga long</div>
</div>
</div>
&#13;
答案 1 :(得分:0)
您可以使用Flexbox
执行此操作,只需使用flex-wrap: wrap
上的.box_prop
.box {
background: #aaa;
width: 150px;
}
.box_prop {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.box_value {
font-weight: bold;
}
.box_value {
margin-left: auto;
}
<div class="box">
<div class="box_prop">
<div class="box_key">key</div>
<div class="box_value">value</div>
</div>
<div class="box_prop">
<div class="box_key">key long</div>
<div class="box_value">value long</div>
</div>
<div class="box_prop">
<div class="box_key">key giga long</div>
<div class="box_value">value giga long</div>
</div>
</div>