How do I add / insert a before or after pseudo element into Chrome's Inspector?

回眸只為那壹抹淺笑 提交于 2019-12-18 11:16:17

问题


I can add a regular style rule via the + sign (New Style Rule) but I can't add one under the "Pseudo ::before Element" or "Pseudo ::after Element" sections of the Style Inspector. If I try to add the ::before or ::after element into the HTML via "Edit as HTML", it comes out as text. My workaround is to add <span class="pseudo_before"></span> and then style that. Am I missing something?


回答1:


This is the easiest way and the way I do it:

  1. Inspect the element you want to add the ::before or ::after to by right clicking it and going to "Inspect Element".

  2. Now in the Developer Tools Console, click on the plus sign icon aka. "New Style Rule". See the image below, the plus sign is next to the "Toggle Element State" button.

  3. Next, you will be able to edit the selector so add ::before / ::after to it:

  4. Now edit the content to whatever you like, i.e.

Like so:

.grp-row::before {       
   content: '> '; 
}

That's all there is to it :)




回答2:


Open the stylesheet you want in the inspector by holding Ctrl and clicking on a style property from that stylesheet (on Windows, click here for Mac). Then you can add whatever you want and it updates in realtime.

For example:

p::before {
    content:'TEST';
}

This will add the word 'TEST' as a prefix to any <p> tags it finds. Check it out on MDN

You can even save the stylesheet so you don't have to do it twice. Right-click inside the stylesheet and hit 'Save as'.



来源:https://stackoverflow.com/questions/22023952/how-do-i-add-insert-a-before-or-after-pseudo-element-into-chromes-inspector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!