Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ::before pseudo-element not working with :visited pseudo-class?

Tags:

I'm trying to style my element with pseudo-class and pseudo-element. like hover::before is working perfectly but :visited::before is not working.

enter image description here

I want to show "Seen" if link is visited but :visited::before isn't working.

*, *:before, *:after {          box-sizing: border-box;      }      body {          background-color: #eee;          font-size: 23px;          padding: 50px;          font-family: 'Ubuntu Condensed', sans-serif;      }      .style-3 {          margin: 20px;          float: left;          padding: 20px 80px 20px 20px;          border: 1px solid #ccc;          background-color: #fff;          position: relative;          text-decoration: none;      }      .style-3 {          color: green;      }      .style-3:visited {          color: red;      }      .style-3:hover::before {          content: "Hover";          position: absolute;          right: 20px;          color: yellow;      }      .style-3:visited::before {          content: "Seen";          position: absolute;          right: 20px;          color: blue;      }
<a href="#1" class="style-3">Seen Effects</a>  <a href="#2" class="style-3">Seen Effects</a>  <a href="#3" class="style-3">Seen Effects</a>
like image 562
Usman Arshad Avatar asked Jun 15 '15 17:06

Usman Arshad


People also ask

What does the pseudo element :: Before do?

::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.

What does the pseudo selectors allows us to do before and after?

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.

Is visited a pseudo-class?

The :visited CSS pseudo-class represents links that the user has already visited. For privacy reasons, the styles that can be modified using this selector are very limited.

Can I have multiple before pseudo-elements for the same element?

In CSS2. 1, an element can only have at most one of any kind of pseudo-element at any time. (This means an element can have both a :before and an :after pseudo-element — it just cannot have more than one of each kind.)


1 Answers

It may be possible, but don't take it for granted. According to the spec,

Note: It is possible for style sheet authors to abuse the :link and :visited pseudo-classes to determine which sites a user has visited without the user's consent.

UAs may therefore treat all links as unvisited links, or implement other measures to preserve the user's privacy while rendering visited and unvisited links differently.

Inserting content can change the size of the element, so it would be trivial to detect this and know if the user has visited some sites. Therefore, most browsers won't allow you to do so.

like image 114
Oriol Avatar answered Oct 05 '22 14:10

Oriol