Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

::after on background images ?

Featured Replies

#inner {background-image:url("");position:relative;}
#inner::after {content:"";background-image:url("");opacity:0.8;background-repeat:repeat;position:relative;}

The above code works, only because #inner has a background-image. If I make #inner have a background-color of orange the after pseudo-element after doesn't work ? How do I get ::after to work on a background image ?

You need to add

position:absolute;
z-index:1; 

for to make ::after pseudo-element to be visible.

  • Author

You need to add

position:absolute;
z-index:1; 

for to make ::after pseudo-element to be visible.

Must I have a position ? :tv7: It's just a background image !

And can I remove the background image from the #inner selector, I haven't had any positive workings when I remove it !

A background image is not an element, a background image gets applied to an element.

 

Fiirstly do not use ID's for styling.

 

For a psuedo element you do not need two colons you only need one:

.classname:after {

}

 

To position the psuedo element as an overlay (which I am assuming you are trying to do)

you need:

.className:after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

There's no need to add a Z-index as the element will come later in the DOM so will automatically be layered over the top. Your background image url is empty.

Edited by rbrtsmith

  • Author

A background image is not an element, a background image gets applied to an element.

 

Fiirstly do not use ID's for styling.

 

 

I know ID's are mostly used for JS purposes; I don't mind using them sparingly.

 

For a psuedo element you do not need two colons you only need one:

.classname:after {

}

 

 

 

I wasn't sure if one colon or two colons was causing the issue.

 

 

To position the psuedo element as an overlay (which I am assuming you are trying to do)

you need:

.className:after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

There's no need to add a Z-index as the element will come later in the DOM so will automatically be layered over the top. Your background image url is empty.

 

 

It worked so I must use positioning for the element & pseudo element even if the positioning has no value as in top,right,bottom,left: 0 ?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.