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
1 answer

Underline on hover with an after div : result differs between Safari and Chrome

I used the css "trick" to underline a div which consists in adding a pseudo-elment div::after with empty content and set borders : .is-hightlighted:after { content: ""; height: 0; width: 100%; border: solid 1px black; position: absolute; …
Pisk
  • 3
  • 5
0
votes
0 answers

How to make pseudo-element follow text across line break?

I've created CSS for anchor text that transitions a background-color and a border-bottom using opacity. (This is done to meet the Chrome Lighthouse auditor's spec on avoiding transitions except on compositor-only effects.) The CSS puts the…
Tom
  • 1,836
  • 4
  • 16
  • 30
0
votes
1 answer

CSS animation for all clientRects

I was playing around with CSS animations to get some eye candy - and I found following result pretty nice: body { font-size: xx-large; font-family: 'Courier New'; color: white; background: black; } a { …
PjotrC
  • 311
  • 1
  • 6
  • 16
0
votes
1 answer

Is there a way to vertically align text with an image in the CSS content property (chrome)?

I would like to vertically align text next to an image in a before pseudo-element. The way it's working now is that my image is displayed to the left of my text, but both the image and text sit on the same baseline. I tried using vertical-align, but…
Frank
  • 2,050
  • 6
  • 22
  • 40
0
votes
1 answer

::after element not showing on a page, but is visible in live-server page

I've got a ::after element on label for a checkbox input. Everything works on live-server in an editor, element is visible, :checked animation works, everything is ok. I pushed the code on a repository on github and when I open the page, ::after…
Sandro
  • 35
  • 1
  • 5
0
votes
1 answer

3 column 3 row HTML table breaks in Mobile Safari but works fine in Chrome and Firefox

Chrome & Firefox Mobile Safari on IOS 14 Z-index seems to be ignored and it appears as though the pseudo elements aren't anchored correctly to the tbody element and stretch well beyond their parent. What can be adjusted so Mobile Safari behaves…
Lynel Hudson
  • 2,335
  • 1
  • 18
  • 34
0
votes
1 answer

Python webScraping - Betclic URL's

EDIT: So I found a way to do it by clicking on the Countries elements, see my answer. Still have one question that would make this better: When I execute the scrollIntoView(true) on a country
  • it goes under another element (
    Drew
    • 113
    • 1
    • 14
  • 0
    votes
    1 answer

    Displaying a shadow ontop of pseudo element

    I am trying to achieve the following effect: The code I have is as follows: .box { background: #fff; width: 600px; height: 100px; position: relative; z-index: 999; box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.75); } .box::after { …
    Ruben Kretek
    • 55
    • 1
    • 8
    0
    votes
    1 answer

    Quote pseudo-elements don't align evenly within element padding

    I've styled a blockquote to add opening and closing quotation marks via CSS pseudo-elements, but they don't evenly center horizontally within the element's padding, so the closing quotation mark usually appears further away from the text. In my…
    Mario Parra
    • 1,504
    • 3
    • 21
    • 46
    0
    votes
    0 answers

    Change opacity of pseudo element with javascript

    I have a tooltip which is a pseudo element shown when hovering over an image. It works well, the tooltip animates in and out. I'd also like to be able to trigger showing the pseudo element tooltip with javascript. I've read many posts about…
    Brad
    • 1,019
    • 1
    • 9
    • 22
    0
    votes
    1 answer

    How to use before and after CSS pseudo classes with z-index

    I'm trying to achieve this result At the moment I'm using a
    in my React component to make the shape that will have the shadow and setting its z-index behind the gray box, then its ::before pseudo element to make the…
    0
    votes
    1 answer

    Psuedo After element not showing

    Trying to display a little chevron as an psuedo after element but I can't get it to display for some reason. I've tried playing the z-index but that doesn't do anything for the image one way or another. Any ideas what I'm doing wrong here? This…
    RRhodes
    • 501
    • 6
    • 19
    0
    votes
    2 answers

    how to make triangle hover ithe specified element?

    I have a navigation bar of two parts. The left side is a logo pic. The right side bar consists of 4 list elements. I want a triangle to appear at the bottom of the element hovered. I floated the list to the right. Now I tried the pseudo class…
    tata
    • 67
    • 2
    • 9
    0
    votes
    2 answers

    Change css of child on parent's pseudo-element (::after/::before) hover with CSS

    Here's a fiddle of what I've tried and what I want to do: #child {color:white;} #parent::after{ content:"This"; color:black; } #parent::after:hover + #child{ color:black; } #parent::after:hover ~ #child{ color:black; }
    0
    votes
    2 answers

    How to set CSS property of ::before pseudo element in Angular component?

    Is there any way to access the TypeScript variables in my SCSS code in my Angular component? I want to do something like this: