Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which elements support the ::before and ::after pseudo-elements?

Tags:

I'm trying to come up with some good default styling for <input>s in HTML5 and tried the following:

input::after         { display: inline; } input:valid::after   { content: ' ✓ '; color: #ddf0dd; } input:invalid::after { content: ' ✗ '; color: #f0dddd; } 

Alas, the ::after content never shows up. It's not a problem with double- versus single colons for the pseudo-elements; I've tried both. It's also not a problem with having a pseudo-element and a pseudo-class; I've tried it without the :valid and :invalid. I get the same behavior in Chrome, Safari, and Firefox (Firefox doesn't have the :valid and :invalid pseudo-classes, but I tried it without those.)

The pseudo-elements work fine on <div>, <span>, <p>, and <q> elements -- some of which are block elements and some are inline.

So, my question is: why do browsers agree that <input>s don't have an ::after? I can't find anything in the spec that would indicate this.

like image 452
James A. Rosen Avatar asked Aug 21 '10 18:08

James A. Rosen


People also ask

When would you use the :: before or :: after pseudo element in your CSS?

Special welcome offer: get $100 of free credit. 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.

What is :: before and :: after used for?

::before Represents a styleable child pseudo-element immediately before the originating element's actual content. ::after Represents a styleable child pseudo-element immediately after the originating element's actual content. By default, this new element will be an inline element.

What does :: before and :: after do in HTML?

Definition and UsageThe ::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.


1 Answers

As you can read here http://www.w3.org/TR/CSS21/generate.html, :after only works on elements that have a (document tree) content. <input> has no content, as well as <img> or <br>.

like image 120
davehauser Avatar answered Oct 19 '22 00:10

davehauser