css - 使用 css 和外部文本每行显示一个元素

标签 css

我有以下 html 片段:

<div>
    <a class="item" href="http://google.com">Google</a>,
    <a class="item" href="http://yahoo.com">Yahoo</a>,
    <a class="item" href="http://yandex.com">Yandex</a>
</div>

现在是这样显示的:

Google, Yahoo, Yandex

我需要它像这样显示:

Google,
Yahoo,
Yandex

是否可以仅通过修改 .item 类的 CSS 属性来完成? (不插入新标签(例如 BR)并且不触及逗号)?

我试过

.item {
    clear: both;
    float: left;    
}

但是所有逗号都留在第一行。

最佳答案

也许这可行,

添加一个空字符串,而不是在 css 中添加一个新的逗号并删除或更改旧逗号的颜色

a:before {
    content:'';
    display: block; 
}

jsFiddle DEMO

关于css - 使用 css 和外部文本每行显示一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20124635/

相关文章:

html - Bootstrap : Extra Space in Collapsed Navbar between the brand name and the 3 Horizontal bars drop-down button

javascript - 基于内容将 SVG viewbox X 和 Y 居中

html - 如何创建一个标题,在整个宽度上用一种颜色填充背景

html - 表格中的 Css、gif、视口(viewport)高度的 100%

javascript - 将 JQuery 对话框置于前面

html - 如何在html中链接图像和文本?

html - 内部显示 flex 和自动高度 (100%)

html - Firefox 中奇怪的表格呈现

css - 尝试仅使用 div 和 css 而不是表格来实现格式化

css - 覆盖在 IE8 中不可点击