Utilize the ::before pseudo-element exclusively for the initial node

Here is the text I need to generate :

https://i.sstatic.net/HzKP9.png

This represents my HTML code :

<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="style5.css">
<title> Département TI </title>
</head>

<body>
<h1>Département TI</h1>
    
<ul>

  <li>TC</li>
  <li>2ème année
  <ul>
      <li id="a">DSI</li>
      <li id="a">SEM</li>
      <li id="a">RSI</li>
    </ul>
  
  </li>
  <li>3ème année</li>
</ul>


</body>

</html>

Additionally, here is my CSS code :

li {list-style-type: none;}
li::before
{
content: "-*-"; 
}

The output I am currently receiving looks like this:

https://i.sstatic.net/Az1YH.png

Answer №1

When using the :first-child selector, it will still target both elements. To address this, you can apply the li:before rule as you already have, and then override that rule for ul > li > ul. Here is an example:

li {
  list-style-type: none;
}

ul > li::before {
  content: "-*-";
}

ul > li > ul > li:before {
  content: none;
}

Alternatively, you could wrap your ul tags inside another element so that you can use :first-child on the ul itself. Here's how you can do that:

<h1>Information Technology Department</h1>

<div>
  <ul>
    <li>TC</li>
    <li>2nd year
      <ul>
        <li id="a">DSI</li>
        <li id="a">SEM</li>
        <li id="a">RSI</li>
      </ul>
    </li>
    <li>3rd year</li>
  </ul>
</div>

And here is the corresponding CSS:

li {
  list-style-type: none;
}

div > ul > li:before {
    content: "-*-";
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript does not function properly with dynamically loaded content

Trying to load the page content using the JQuery load() method. See below for the code snippet: $(window).ready(function() { $('#content').load('views/login.html'); }); .mdl-layout { align-items: center; justify-content: center ...

Arrange CSS to distribute list items across two rows with an unlimited number of items

I need my list items to be arranged in 2 rows like the following: item 1 item 3 item 5 item 7 item 9 .... item 2 item 4 item 6 item 8 ...... My CSS skills are not great, so I am struggling to find a solution for this. I have at ...

Guide on How to Include data (PDF Base 64) in angular 6 component

Within my Angular 6 application, I am presenting data (a report) in a new window using the following code snippet. *** The 'result' variable contains Base64 data *** if (result != null) { const pdfWindow = window.open(""); ...

What are the steps to position this bootstrap drop-down menu above a fixed page header?

Could someone please advise on what changes need to be made in the code snippet below from http://jsfiddle.net/ufkkdbja/? I am looking to ensure that when the hamburger menu is clicked, the entire menu appears without being cut off by the fixed page header ...

Transform Angular Material Table selection color with selection

Is it possible to customize the color of the selector in an Angular Material table when using selection? Learn more about it https://i.sstatic.net/5ZJQT.png ...

You can move freely between classes A and B, as well as classes A and C, but there is no transition allowed between

A Brief Overview... Take a look at the HTML structure below: <div class="wrapper"> <div class="item above"></div> <div class="item active"></div> <div class="item below"></div> <div class="item ...

JavaScript: a single function and two calls to Document.getElementById() results in both returning "undefined"

Within my JavaScript file, I have a function that utilizes two variables: choice and courseChosen. The latter variable must be converted into an object first. In the HTML, the tags courseName and courseInfo are used for choice and courseChosen respectively ...

Delivering seamless css integration using express.js

Lately, I've been struggling with serving CSS using Express.js. After some trial and error, I managed to make it work. However, I'm puzzled as to why my new code works while the old one doesn't. Here's the code that now works for me: co ...

Guide to creating an uncomplicated quiz using PHP

My goal is to create a quiz with 15 questions. Every time a user lands on the page, they will see a random selection of 5 questions. Each question will have 4 multiple choice answers, with one being correct. The marks allocated for each question are 20, 15 ...

Storing dropdown selection as a variable in a PHP Ajax form

I have created a PHP form that allows the user to select an option from a dropdown menu in order to view a specific data set. The data is refreshed on the screen using an AJAX call and I am utilizing the 'html' datatype to update the output withi ...

Switch the ng-bind-html option

Dealing with a string in my scope, I must determine whether I want the HTML escaped or not. A boolean value helps to decide if the HTML should be escaped or left as is. Snippet Check out some of my code examples below: $scope.result = "<b>foo</ ...

showing text from chosen selection with an additional element included in the output

I could use some assistance with this code snippet. My goal is to showcase the options in the format: "Fried Rice = 10.000" as the outcome. However, the issue I am facing is that the select option box also contains the price. What I actually need is for th ...

Connect-busboy: The file being piped to the write stream is either empty or incorrect, depending on its type

My current project involves testing a file upload feature using connect-busboy. Interestingly, I have encountered a peculiar issue when uploading PNG files - although the file gets uploaded, the content seems to be incorrect and unable to open. Upon furthe ...

Which is more accessible: a disabled textbox or a div with role="textbox"?

Imagine I have a form in which one of the fields (name) is always disabled. When it comes to accessibility, would it be more effective to use an input <label> Name <input role="textbox" aria-readonly="true" value="Joe Shmoe" /> < ...

Exchanging items through Drag and Drop

My current project involves using drag and drop functionality to allow students to rearrange pieces of an image that has been jumbled up. They can drag these pieces onto a grid to recreate the original image. Both the jumbled up grid and the reconstructio ...

Issue with SVG mask not functioning when transform is applied

I am struggling to apply a mask to a transformed SVG element. When I try to do this with a path, the structure is the same. If I apply the mask to an element outside of the transformed group, it works as expected. However, if I try to do the same inside, t ...

Unraveling AngularJS: Mastering the Art of Interpolating Interpol

Trying to interpolate a string retrieved from the database, such as "Users({{users_count || 0}})", poses a problem. Using {{}} or ng-bind for interpolation does not work properly. The HTML code written is {{data.usersCount}}, but instead of ren ...

A guide on changing the background color to complement the light/dark theme in Bootstrap 5.3

In the latest version of Bootstrap, 5.3, users have the ability to select a theme for their websites. The built-in options include a Dark theme and a Light theme. For instance, by setting <html data-bs-theme="dark">, you can specify that t ...

Child div set to 100% height within parent div with auto height

After scouring the internet for hours in search of an answer, I found myself reading articles like Floats 101 on alistapart and browsing through countless similar questions on stackoverflow. I have reached a point where I feel like I must ask my question b ...

Seeking Assistance with Customizing HTML Uniform Panels

Looking at the HTML provided, I have two requirements: Request: I need to center the green boxes regardless of their height, without having to adjust the top:-10px/bottom:-10px values when the height changes. Eliminate the fixed top/bottom value (as the ...