简体   繁体   English

在工具中更改值之前,填充不应用于伪元素

[英]Padding not Applying to Pseudo Element until Changing a Value in the Tools

I have no idea why, but (at least in Chrome anyway) I'm trying to separate the links with a pipe '|'. 我不知道为什么,但是(至少无论如何在Chrome中)我都试图用管道'|'分隔链接。 I can achieve this by adding padding of 0 10% - but whenever I reload the page, there is no padding, at least until I change the value of the padding and then back to 0 10%. 我可以通过添加0 10%的填充来实现此目的-但是每当我重新加载页面时,就没有填充,至少直到我更改了填充的值然后又回到0 10%为止。

If you open this codepen: 如果您打开此代码笔:

https://codepen.io/anon/pen/aXpRJv https://codepen.io/anon/pen/aXpRJv

It initially appears with no padding. 最初显示时没有填充。 Then if you change to 0 1% and then 0 10%, the padding shows correctly. 然后,如果您更改为0 1%,然后更改为0 10%,则填充将正确显示。

Why is this happening, and how can it be fixed? 为什么会这样,如何解决? Thanks for any help 谢谢你的帮助

 #headerHomeLogIn:after { content: '|'; padding: 0 10%; } #headerHomeLogIn { white-space: nowrap } #headerAccountLinks { background: lightgreen; position: absolute; z-index: 1; bottom: 50px; width: 100%; height: 50px; padding-left: 25%; display: flex; align-items: center; } 
 <div id="headerAccountLinks"> <span id="headerHomeLogIn">Log In</span> <span>Sign Up</span> </div> 

I got it to work by adding display:inline-block; 我通过添加display:inline-block;使其起作用display:inline-block;

#headerHomeLogIn:after {
  content: '|';
  padding: 0 10%; 
  display:inline-block;
}

You can try using px instead of percentages like this: 您可以尝试使用px代替这样的百分比:

(I added a margin: 0 10px; to space it evenly) (我添加了一个margin: 0 10px;将其均匀隔开)

 #headerHomeLogIn:after { content: '|'; padding: 0 10px; margin: 0 10px; } #headerHomeLogIn { white-space: nowrap } #headerAccountLinks { background: lightgreen; position: absolute; z-index: 1; bottom: 50px; width: 100%; height: 50px; padding-left: 25%; display: flex; align-items: center; } 
 <div id="headerAccountLinks"> <span id="headerHomeLogIn">Log In</span> <span>Sign Up</span> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM