Chrome shows me the ::after
and ::before
definitions (and inherited definitions etc..) in the Matched CSS Rules pane when I inspect an element. But the Computed Styles pane displays only the computed styles for the root element.
I have a whole CSS class hierarchy for the pseudo elements with some properties inherited and some overridden etc, and would like to know if there is any way I can see the set of styles that actually got applied (i.e. what the computed styles pane shows for the root element)
If anyone can shed any light on this, that'll be extremely helpful.
Edit - 13th Feb, 2014
Recent versions of Chrome indeed has this feature built-in Perhaps this little thread had something to do with them including it?? :-)
The ::before selector inserts something before the content of each selected element(s). Use the content property to specify the content to insert. Use the ::after selector to insert something after the content.
The content attribute. This property is used with the :before and :after pseudo-elements to generate content in a document.
::before. ::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.
CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.
window.getComputedStyle( element[, pseudoElt] )
pseudoElt
OptionalA string specifying the pseudo-element to match. Must be omitted (or null) for regular elements. Pseudo-classes can be specified like ":focus".
I'm possibly misunderstanding what you're trying to accomplish, but here's some JavaScript to play with. I hope it's useful.
It iterates through every element in the document and attempts to get the content
of its :before
s and :after
s.
If it finds any, it outputs the details to the console
.
Simple, but demonstrable.
document.querySelectorAll( "*" ).forEach( ( e ) => {
const ebc = window.getComputedStyle( e, ":before" ).content,
eac = window.getComputedStyle( e, ":after" ).content;
if ( ebc || eac ) {
console.log( e );
console.log( ( ebc ? "Before content = " + ebc : "No :before content" ) );
console.log( ( eac ? "After content = " + eac : "No :after content" ) );
}
} );
div:before {
content: "This is a test.";
}
p:after {
content: attr( data-content );
}
span:after {
content: " dolor";
}
<div>
<p data-content="…">Lorem <span>ipsum</span></p>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With