我正在尝试使用before选择器来模拟列表项在应用于元素时的某些行为。我不能使用列表项,所以我必须能够使样式工作。
这是一个显示问题的小提琴:http://jsfiddle.net/7g6ncg7u/
.container {
width:300px;
}
.up:before{
content:'\25B2';
color:green;
padding-right:10px;
margin:1px;
}
.down:before{
content:'\25BC';
color:red;
padding-right:10px;
margin:1px;
}
我想要发生的是第二个跨度的第二行与上面的文本对齐,而不是像现在这样的行的开头。
答案 0 :(得分:2)
您可以像这样使用float
:
.down {
clear:both;
}
.down:before{
content:'\25BC';
float:left; /**ADD THIS**/
color:red;
padding-right:10px;
margin:1px;
}
.container {
width: 300px;
}
.down {
clear: both;
}
.up:before {
content: '\25B2';
color: green;
padding-right: 10px;
margin: 1px;
}
.down:before {
content: '\25BC';
float: left;
color: red;
padding-right: 10px;
margin: 1px;
}
<div class="container">
<span class="down" style="display: block;">regular bullet point text</span>
<span class="down" style="display: block;">regular bullet point text but this one is longer and will wrap</span>
</div>
答案 1 :(得分:0)
尝试将标记内容包装在标记中,例如p
标记。这会将子弹与文本分开,并允许您单独处理它们。在那里,您可以将span
更改为display: table;
,将p
更改为display:table-cell;
。
答案 2 :(得分:0)
这是我使用的,它似乎工作得很好。
HTML:
<div class="container">
<div class="down" style="display: block;">
regular bullet point text
</div>
<div class="down" style="display: block;">
regular bullet point text but this one is longer and will wrap
</div>
</div>
CSS:
.container{
width:300px;
}
.down
.up:before{
content:'\25B2';
color:green;
padding-right:10px;
margin:1px;
}
.down:before{
content:'\25BC';
color:red;
padding-right:10px;
margin:1px;
}
div {
padding-left: 1.5em;
text-indent:-2.0em;
}