LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-25-2024, 01:36 AM   #1
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
CSS :has() not working to select pseudo-class :link


I can see that the :has() selector in CSS can work with pseudo-clases, as exhibited with the :hover pseudo-class:

Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test Hover</title>
  <style type="text/css" media="screen">
  /*<![CDATA[*/
    div {
    background-color: #f88;
    }
    div:has(ul li a:hover) {
    background-color: #88f;
    }
  /*]]>*/
  </style>
</head>
<body>
  <h1>Hover</h1>
  <div>
    <ul>
      <li> <a href="http://127.0.0.1/a">A</a> (visited) </li>
      <li> <a href="http://127.0.0.1/b">B</a> (visited) </li>
      <li> <a href="http://127.0.0.1/c">C</a> (visited) </li>
    </ul>
  </div>
  <div>
    <ul>
      <li> <a href="http://127.0.0.1/d">D</a> (not visted) </li>
      <li> <a href="http://127.0.0.1/e">E</a> (not visted) </li>
      <li> <a href="http://127.0.0.1/f">F</a> (not visted) </li>
    </ul>
  </div>
</body>
</html>
However, the problem I am running into is that neither Firefox nor Chromium allow the same selection of the :link pseudo-class:

Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test Link</title>
  <style type="text/css" media="screen">
  /*<![CDATA[*/
    div {
    background-color: #f88;
    }
    div:has(ul li a:link) {
    background-color: #88f;
    }
  /*]]>*/
  </style>
</head>
<body>
  <div>
    <h1>Link</h1>
    <ul>
      <li> <a href="http://127.0.0.1/a">A</a> (visited) </li>
      <li> <a href="http://127.0.0.1/b">B</a> (visited) </li>
      <li> <a href="http://127.0.0.1/c">C</a> (visited) </li>
    </ul>
  </div>
  <div>
    <ul>
      <li> <a href="http://127.0.0.1/d">D</a> (not visted) </li>
      <li> <a href="http://127.0.0.1/e">E</a> (not visted) </li>
      <li> <a href="http://127.0.0.1/f">F</a> (not visted) </li>
    </ul>
  </div>
</body>
</html>
The above tests assume that the links are either visited or not visited as according to their annotation.

While the document with :hover allows for the background to change for the parent div when a child anchor is hovered over, the same cannot be said for document with the div with child anchors pointing to unvisited links. The div with visited and unvisted links are getting treated the same by CSS. I would have expected the background to change for the div with the unvisited links.

Is this a flaw in both Chromium and Firefox? Or have I misunderstood how to use :has() in CSS?

Code:
$ apt-cache policy firefox | head -n 2
firefox:
  Installed: 124.0.1+linuxmint1+virginia

$ apt-cache policy chromium | head -n 2
chromium:
  Installed: 123.0.6312.58~linuxmint1+virginia

Last edited by Turbocapitalist; 03-25-2024 at 02:23 AM. Reason: tweak HTML for readability
 
Old 03-30-2024, 12:43 AM   #2
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled
I did not know, pseudo classes could be part of selectors in :has().
On the other hand, I have never used :has(). It may be relatively new and not (yet) supported by all browsers.

Edit: Where I need to select elements by such filigree detail, I would most probably replace CSS by XSL ( div[selectors] or other kind of match in a dedicated template).

Can you point me at a doc where pseudo-classes are explicitly said to be allowed selectors ?

Thank you in advance.

Michael

Last edited by Michael Uplawski; 03-30-2024 at 12:46 AM. Reason: xsl
 
Old 03-30-2024, 01:12 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310

Original Poster
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by Michael Uplawski View Post
Can you point me at a doc where pseudo-classes are explicitly said to be allowed selectors ?
The CSS waters have become quite muddy of late. Perhaps this example counts?

https://developer.mozilla.org/en-US/docs/Web/CSS/:has
 
Old 03-30-2024, 01:17 AM   #4
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,622
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
The CSS waters have become quite muddy of late. Perhaps this example counts?

https://developer.mozilla.org/en-US/docs/Web/CSS/:has
functional pseudo-class”. When will they just stop?

Read here: https://developer.mozilla.org/en-US/..._selector_list
Quote:
Note that pseudo-elements and the :has() selector are not valid within the :has() relative selector list.
From memory, Paul Lutus (who is not quoted often enough) once wrote: The W3C must learn a new word. The word is “No”!

Last edited by Michael Uplawski; 04-06-2024 at 01:02 AM. Reason: Kraut2English
 
  


Reply

Tags
chromium, css, firefox, has(), selectors



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Making GTK3 themes – Part 2: The gtk.css and gtk-widgets.css file LXer Syndicated Linux News 0 07-24-2012 01:50 PM
CSS - Is there a way to put several lines of HTML into one line using CSS? Chronothread Programming 12 01-05-2011 06:06 AM
HTML/CSS/JS: Problem with <p> not having an absolute position with CSS. RHLinuxGUY Programming 7 03-03-2007 12:21 AM
Which C++ editor in Linux has the class view/class browser feature imaginationworks Programming 7 05-21-2006 11:09 PM
Regarding Pseudo tty, Pseudo terminals ? mqureshi Programming 0 07-30-2005 10:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration