Questions tagged [pseudo-element]

CSS pseudo-elements allow for an enhanced display of content within elements or the ability to generate extra beginning or ending content for elements.

CSS pseudo-elements (literally, "false elements") allow for an enhanced display of content within elements or the ability to generate extra beginning or ending content for elements. It allows for many CSS properties typically only available to real elements to be applied directly to content. Pseudo-elements are not to be confused with pseudo-classes.

List of CSS Pseudo-Elements

This is a list of all pseudo-elements that are currently included in CSS specifications (not any editor's drafts or upcoming specifications).

  • ::first-line and ::first-letter
    Selects the first line or letter within the text of the element.

  • ::before and ::after
    Used to insert content before or after the content of the element using the content property. The content may be set to text and embellished by other properties, or it may be left blank by setting content: '', allowing the pseudo-element to be used to make boxes, display background images, etc., without any textual content being generated. You cannot use these pseudo-elements to insert additional HTML, and you cannot use them with replaced elements (see below) which do not have actual content. This is because the generated content resides within the element.

Replaced Elements and Other Elements not allowing Pseudo-Elements

Any element whose appearance and/or dimensions are determined by some external resource is considered to be a replaced element, and are outside the scope of the CSS formatting model. Because of this, some pseudo-elements cannot be applied to replaced elements, in large part because they have no "content" themselves or they get replaced with something (such as user interface controls). Elements replaced or not holding content include images (<img>), inline frames (<iframe>), line breaks (<br />), horizontal rules (<hr>), plugins (<object>), some form elements (<textarea>, <input>, and <select>), videos (<video>), audio sounds (<audio>), and canvases (<canvas>). Any other element is considered to be a non-replaced element, or is at least an element that contains content with which pseudo-elements may be used. For further information on replaced elements, see the HTML5 draft of the spec.

2189 questions
0
votes
2 answers

When hovering element, affect :before pseudo element

How can I affect the :before pseudo element when I hover on the main element? I want the pseudo element to obtain a height value when I hover over the main element. My code is like this: HTML
CSS .object:hover…
Mr No
  • 113
  • 1
  • 10
0
votes
1 answer

Background Image on pseudo elements

I am trying to insert background images into each tab as per the screenshot below but because the arrow is created using pseduo elements I am not sure how to do it. Please see below a snippet of where I am upto so far. The final product should look…
0
votes
3 answers

Why CSS Pseudo Element not Working in Image

first I have tried to find answers on the stack overflow with a similar question but the results are still the same it doesn't show the image I mean. so this is my html structure:
Heru Wijayanto
  • 439
  • 3
  • 5
  • 16
0
votes
1 answer

How can make the 2nd line of text align with the 1st line while using a pseudo element?

I have some buttons with text on them that drop down text when they are clicked. The buttons have a pseudo element before the text. It looks good on desktop view but when I view it in mobile, the text wraps down to two lines and the second line…
pkc21
  • 27
  • 6
0
votes
3 answers

extend :after inline-block for the rest of the element

I have a h3 tag with :before (a small square) and as :after I would like a line that extends for the rest of width. both the :before and the :after are set to display:inline-block , so that I can set the width and height. setting the width:100% for…
Jakob Cosoroaba
  • 1,702
  • 4
  • 24
  • 34
0
votes
1 answer

aligning CSS3 pseudo :before shape with list image

I'm trying to align a css shape with the list icon. Right now it looks like this: But It should look like: I tried using position: absolute; relative; and margin, still nothing. Heres a live test: http://jsfiddle.net/fzSrL/ css: .services-info ul…
nowayyy
  • 917
  • 1
  • 17
  • 45
0
votes
2 answers

Can the ::after content of a pseudo element be a whole div? The ideia is to make a popover

I am trying to make big popover when hovering a div, and the content of this popover is going to be another div. Is this possible using pseudo element?
Gui Oliveira
  • 155
  • 2
  • 9
0
votes
1 answer

Different content value of pseudo element basing on input type atribute

i would like to have different content of ::before pseudo element for each input type atribute i mean: if mark up looks like this (type="email") i would like to make…
qRx.
  • 31
  • 4
0
votes
1 answer

Using a pseudo-element (::before) as jump link target not working in CSS

I'm having an issue when using a pseudo-element (::before) as an anchor-link, because the page doesn't recognize it as the anchor, and keeps going to the section itself. I've tried every option suggested in Nicolas Gallagher's blog, but nothing…
JS3DX
  • 11
  • 2
0
votes
0 answers

Change class of the last instance of an item within a loop with WordPress/ACF

I want to insert an arrow image between each div with the class product-icon in a WordPress loop using the ::after CSS pseudo-element. Right now the arrow shows up after every product-icon div the loop populates, but I want it to be hidden after the…
0
votes
1 answer

basic :nth-child(odd) /even selection on li does not work : All of them rendered as odd

Totally puzzled by this very basic rules of giving a background color differently to odd and even to each list element (each
  • ) In the rendered html code, ALL li are seen as odd.. ?????? so they all got the same background color instead of the…
  • user1011212
    • 39
    • 1
    • 8
    0
    votes
    0 answers

    :after in attribute style

    How can I do .sas:after{ content: "stas"; }

    In attribute