Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 964
Andrew Tibbetts Avatar asked Feb 25 '14 19:02

Andrew Tibbetts


People also ask

What is :: before in inspect?

::before is a generated content element that represents a styleable abstract first child of the respective element. The content inserted using ::before is inserted before other content inside the element and is displayed inline by default. The value of the content is specified using the content property.

Which pseudo element can be used to insert some content before the content of an element?

The ::before pseudo-element can be used to insert some content before the content of an element.

How do you add tags to inspect element?

Right-click an element in the inspector, and select "Edit as HTML". You can then add whatever HTML you want inside of it. Warning: this will destroy the element with all its descendants, and will then recreate them once you're done editing the HTML.

How can you force pseudo class styles to display using chrome Devtools?

Pseudo classes on elements can be triggered to investigate how an element may react if it were to be hovered over for example. You can right click on a node in the Elements panel and select Force element state. Alternatively, the Toggle element state icon can be clicked on in the Styles sub-pane.


1 Answers

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.

    enter image description here

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

    enter image description here

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

Like so:

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

That's all there is to it :)

like image 179
radtek Avatar answered Oct 13 '22 05:10

radtek