我的观点如下
p {
width: 50%;
float: left;
}
<div>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
</div>
我不允许对html进行任何更改。我要在每两个
标记之后插入一行,如下图所示。(p标记的数量不限于四个。它们可以增加。)
有人可以告诉我该怎么做吗?甚至有可能吗?
答案 0 :(得分:3)
div {
display: flex;
flex-wrap: wrap;
}
div p {
max-width: 50%;
flex-grow: 1;
flex-basis: 0;
border-bottom: 1px solid black;
}
答案 1 :(得分:2)
这是使用::after
伪元素和伪类nth-of-type
的一种方式:
p {
width: 50%;
float: left;
}
p:nth-of-type(2n)::after {
content: '';
border-bottom: 1px solid black;
display: block;
width: 200%;
margin-left: -100%;
}
<div>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
</div>
答案 2 :(得分:0)
我尝试了一些东西。添加了段落标记的类。
<!DOCTYPE html>
<html>
<head>
<style>
p {
width: 50%;
float: left;
}
.sample_line {
border-bottom: solid;
max-height: 18px;
overflow: auto;
}
</style>
</head>
<body>
<div>
<p class="sample_line">The first paragraph.</p>
<p class="sample_line">The second paragraph.</p>
<p class="sample_line">>The third paragraph.</p>
<p class="sample_line">><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
</div>
</body>
</html>
答案 3 :(得分:0)
这是一个带有阴影的想法:
p {
width: 50%;
float: left;
margin: 0;
padding: 20px 5px;
box-sizing: border-box;
}
p:nth-child(odd) {
clear: both;
}
div {
overflow:auto;
box-shadow: 0 -2px 0 black inset;
}
p:nth-child(n+3) {
box-shadow: 0 -2px 0 black;
}
<div>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.<b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
<p>The third paragraph.</p>
<p>The third paragraph.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
</div>
答案 4 :(得分:0)
您还可以使用border-top和margins;因此无需理会段落的高度。
无论如何,如今,您将使用flex或grid而不是float。
div {
border-bottom: 1px solid;
overflow: hidden;
}
p {
width: 50%;
float: left;
border-top: 1px solid;
margin: -2px 0 2px;
}
<div>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
<p><b>Note:</b> Internet Explorer 8 and earlier versions do not support the :nth-child() selector.</p>
<p>The last paragraph.</p>
</div>
答案 5 :(得分:-2)
只需在p处添加border-bottom即可,就像您问的那样。没有别的办法了。
p {
border-bottom: 1px solid black;
}