内容简介:翻译自:https://stackoverflow.com/questions/26449590/make-css-pseudoelement-before-same-height-as-main-element
问题是,如果段落稍微长一点,文本的其余部分将在我的计数器伪元素下面.我想拉伸:在计数器之前与段落的高度相同.
我试过在段落和位置上使用position:relative:absolute;高度:p = 100%之前的伪元素,如下所述: How can the pseudo element detect the height of the non-pseudo element?
这在我的情况下不起作用,因为我不希望p:before元素重复并覆盖段落,我只想要与现在相同的行为,只是希望p:before元素拉伸到与之相同的高度主要的
我也不希望线条拉伸超过包装容器的宽度.我一直在尝试很多方法,但未能找到解决方案.
而不是高度使用位置:p的相对值和之前的绝对值
在css中添加了新属性
.editor p {
position:relative;
padding-left:3.5em;
}
.editor p:before {
position:absolute;
top:0;
bottom:0;
left:0;
}
编辑
这应该是第二个问题:D
按下输入即不创建br而在现代浏览器中它使用以下方法创建br:修复问题以便p标记不会保持为空
.editor {
display: inline-block;
border: 1px black solid;
font-family: "Consolas", "Monaco", "Courier New", monospace;
counter-reset: line;
width: 90%;
height: 350px;
overflow: scroll;
padding-left: 0;
margin-left: 0;
z-index: 1;
}
.editor p {
display: block;
counter-increment: line;
background-color: #FFF;
text-align: left;
margin: 0px;
z-index: 2;
outline: none;
position: relative;
padding-left: 3.5em;
}
.editor p:before {
display: inline-block;
width: 2em;
height: 100%;
border-right: 1px black solid;
padding-right: 1em;
margin-right: 1em;
content: counter(line);
color: #FFF;
background-color: #006;
text-align: right;
position: absolute;
top: 0;
bottom: 0;
left: 0;
/*-webkit-user-select: none;
user-select: none;*/
}
.editor p:after {
content: " "
}
<div class="editor" contenteditable="true" spellcheck="false">
<p>Some paragraph</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas aliquet nunc non pulvinar luctus. Cras finibus turpis at arcu mollis, nec fermentum mi pretium. Aliquam suscipit lacus sapien, eu fringilla enim malesuada quis. Sed ut tincidunt erat.
In posuere vulputate venenatis. Mauris quis porta magna. Phasellus pharetra in nisl et luctus. Etiam in ultrices risus. Morbi vel dapibus ex. Suspendisse gravida libero non malesuada congue. Pellentesque ut nunc diam.</p>
<p>one</p>
<p>two</p>
<p>three</p>
</div>
翻译自:https://stackoverflow.com/questions/26449590/make-css-pseudoelement-before-same-height-as-main-element
以上所述就是小编给大家介绍的《使CSS伪元素:在与主元素相同的高度之前》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
释放潜能:平台型组织的进化路线图
穆胜 / 人民邮电出版社 / 2017-12 / 59.80元
传统的组织模式中,企业逃不出“员工动不起来”和“创新乏力”的宿命。互联网改变商业逻辑的同时也改变了组织逻辑。平台型组织是匹配互联网商业逻辑的组织模式,它赋予了基层员工更多的责权利,能够在需求侧灵敏获取用户刚需、在供给侧灵活整合各类资源、用“分好钱”的机制激活个体去整合各类资源满足用户刚需,形 成供需之间的高效连接。 打造平台型组织有两大主题:一是通过设计精巧的激励机制让每个人都能感受到市场的压力,......一起来看看 《释放潜能:平台型组织的进化路线图》 这本书的介绍吧!