我必须在li标签内的一行中显示span标签内容。你能帮帮我吗?
ul {
list-style: none;
}
ul li {
display: inline;
}
ul li h2 {
display: inline-block;
}
<ul>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
</ul>
答案 0 :(得分:2)
您必须向display: inline-block
,li
和h2
提供span
。
使您的范围适当width
,以便它适应li
之间的空间。
要全屏查看,请查看小提琴:https://jsfiddle.net/nashcheez/s4tqwcmr/
参考代码:
ul {
list-style: none;
}
ul li {
display: inline-block;
width: 49%;
}
ul li h2 {
display: inline-block;
margin: 0;
height: 100%;
vertical-align: top;
}
span {
display: inline-block;
width: 110px;
}
&#13;
<ul>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
</ul>
&#13;
答案 1 :(得分:1)
为你的li添加内联块,这将使它们具有特定的宽度,而不像内联元素......
Official Documentation
&#13;
ul
{
list-style: none;
}
ul li{
display: inline-block;
width: 40%;
margin: 10px;
}
ul li h2{
display: inline-block;
width:40%;
vertical-align: top;
}
ul li span{
display:inline-block;
width:39%;
vertical-align: top;
}
ul li button{
display: inline-block;
width: 19%;
min-width: 60px;
vertical-align: top;
}
&#13;
答案 2 :(得分:0)
ul
{
list-style: none;
}
ul li{
width: 40%;
display: -webkit-inline-box;
}
ul li h2{
display: inline-block;
}
&#13;
<ul>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
</ul>
&#13;