Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS container pseudo element?

In CSS, there are pseudo elements like "before" and "after". That creates virtual elements before or after an element.

Container pseudo element?

Is there a "container" pseudo element?

Problem example 1:

I need to create 15 borders around an element (I know this particular example can be done by using box-shadow).

Problem example 2:

I need to create 15 transparent background colors on top of eachother.

A lot of unnecessary markup

I know that is possible by adding containing divs, but that creates a lot of unnecessary markup.

like image 771
Jens Törnell Avatar asked Jul 20 '12 19:07

Jens Törnell


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.

Why do we use :: before in CSS?

::before (:before) In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.

Can we create pseudo elements in inline CSS?

You can't specify inline styles for pseudo-elements. This is because pseudo-elements, like pseudo-classes (see my answer to this other question), are defined in CSS using selectors as abstractions of the document tree that can't be expressed in HTML.

How do you add multiple pseudo elements in CSS?

Adding multiple pseudo elements You can combine several CSS pseudo-elements for one element. However, you cannot use CSS ::after two times or ::before two times. In the example below, the first letter of <div> is green and has x-large font size. The first line of <div> element is red and has small capital letters.


1 Answers

The old CSS3 Generated and Replaced Content Module had a proposal for an ::outside pseudo-element which seems close to what you describe, but there are no implementations, and the module itself is slated for a rewrite... someday.

In other words, there's currently no way to achieve this using only CSS, and there probably won't be any for a while.

Of course, there are ways to emulate wrapping elements using JavaScript to manipulate the DOM, but that's just about the only way you can achieve this besides hardcoding in the extra markup. Some trivial jQuery methods with respect to the fabled ::outside pseudo-element are described here:

Enable support for CSS3 ::outside pseudoelement

like image 182
BoltClock Avatar answered Oct 02 '22 16:10

BoltClock