我需要实现以下标记:
问题是我只能使用HTML + CSS和XSLT来制作它。
我想过编写一个模板,将文本拆分为XSL行,并将每行打印为<p>
设置为border-bottom
的不同段落。是否有更简单的方法通过HTML + CSS实现这一目标?
小更新:这里的要点是让此下划线延伸到文本之后并获取所有可用宽度。因此,所有行都具有相同的长度(如副本中的行),除了第一行可能更短
答案 0 :(得分:10)
您可以使用内联元素,例如<span>
,它会将border-bottom
视为下划线:
<p>
<span>
<del>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</del> sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam
</span>
</p>
和CSS:
span {
border-bottom: 4px solid black;
}
del {
color: red;
}
使用上面标记的结果:
修改强>
<强> 1 强>
扩展@ aefxx的answer,如果你可以使用CSS3试试这个:
.strike {
background-image: -moz-linear-gradient(top , rgba(255, 255, 255, 0) 34px, #000000 34px, #000000 38px);
background-image: -webkit-linear-gradient(rgba(255, 255, 255, 0) 34px, #000000 34px, #000000 38px);
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 34px, #000000 34px, #000000 38px);
background-repeat: repeat-y;
background-size: 100% 38px;
}
p {
line-height: 38px;
}
p:before {
background: #fff;
content:"\00a0";
display: inline-block;
height: 38px;
width: 50px;
}
del span {
color: red;
}
Demo here - 这只适用于最新的浏览器,包括Firefox和Chrome。
Chrome中的结果:
<强> 2 强>
如果您对合理的文本感到满意:
p,span {
border-bottom: 4px solid black;
line-height: 30px;
text-align: justify;
text-indent: 50px;
}
p>span {
padding-bottom: 5px;
vertical-align: top;
}
del span {
border-bottom: 0 none;
color: red;
}
Demo here.行高存在一些问题,但应该很容易理解。
Chrome中的结果:
除此之外,我担心你可能不得不把你的线包裹在一些容器中。
答案 1 :(得分:1)
使用纯标记可能不会比这更好: jsfiddle demo 。
修改强>
根据问卷评论更新:
预览强>
p span.indent {
width: 160px; height: 30px;
vertical-align: top;
background: #fff;
display: inline-block;
}
p span.strike {
color: #000;
text-decoration: line-through;
}
p del {
color: #ff0000;
text-decoration: none;
}
p {
width: 490px;
font-family: Arial, sans-serif;
line-height: 30px;
background: url('http://img84.imageshack.us/img84/1889/63051094.gif') left top;
}
<p>
<span class="indent"></span><span class="strike"><del>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod</del></span> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
</p>
答案 2 :(得分:0)
在您想要格式化的内容周围创建一个div,并在CSS中使用该div进行必要的格式化。
答案 3 :(得分:0)
<强> HTML 强>
<div id="content">
<p><span id="strike">some content that you need to display</span>
<span id="underline">Some more content that will come here</span></p>
</div>
<强> CSS 强>
#content
{
height:auto;
width:200px;
}
#content #strike
{
text-decoration:line-through;
color:Red;
}
#content #underline
{
text-decoration:underline;
}
span
{
border-bottom:4px solid Black;
}
<强> Live Sample 强>
答案 4 :(得分:0)
实际上,您并不需要每行都在其自己的HTML元素中以具有底部边框。您可以将边框应用于内嵌元素,边框将应用于元素中的每一行。
为了使透视颜色与文本颜色不同,您还需要一个额外的HTML元素。 (虽然Firefox has implemented -moz-text-decoration-color
。)
<span class="fake-underline">
<del><span>Final blitz by Obama and Romney as election arrives.</span></del> Candidates attend rallies late into the night as US prepares to go to the polls.
</span>
.fake-underline {
line-height: 2;
border-bottom: solid 5px black;
}
del {
text-decoration: line-through;
}
del span {
color: red;
}