Utilization of CSS with the symbols of greater than and asterisk

I've been experimenting with Sequence.js and finding it really impressive. There's one line of code that I'm having trouble understanding:

#sequence .seq-canvas > *  {...}

I discovered that the > symbol selects only direct descendants of a specific class. So, if it were written like this:

CSS

#sequence .seq-canvas > li   {color: red}

It would apply to all li elements directly under the .seq-canvas class. For example:

HTML

<div id="sequence">
<ul class="seq-canvas">
  <li>This text is red</li>
  <li>So is this one</li>
  <li>
    <ul>
      <li>But what about this?</li>
      <li>And this?</li>
    </ul>
 <li>However, this one is also red</li>
</ul>
</div> <!-- end sequence -->

... Are you following so far?

As for using * which targets all elements, it becomes confusing when combined with >. Here's an example:

CSS

#sequence .seq-canvas > *  {color: blue;}

HTML

<div id="sequence">
<ul class="seq-canvas">
  <li>This should be blue</li>
  <li>As well as this one</li>
  <li>
    <ul>
      <li>But is this considered blue?</li>
    </ul>
 <li>This one must also be blue...</li>
 <li>What about <span>SPANS</span> - will they turn blue too?</li>
 <div>Or let's say I insert a div here (even though 
   I know it's incorrect), does this mean it'll turn blue?
 </div>
</ul>
</div> <!-- end sequence -->

Do you have any thoughts on this?

Answer №1

Your understanding is correct for them individually. When combined, it means all elements under the specified element (.seq-canvas in your example).

Here is a test. Notice that * alone will change the font size for everything, while > * will only change the color of the children of .seq-canvas:

#sequence .seq-canvas > *  {color: blue;}

* { font-size: 10px; }
<p>I'm outside</p>
<div id="sequence">
<ul class="seq-canvas">
  <li>This must be blue</li>
  <li>So is this</li>
  <li>
    <ul>
      <li>But is this blue?</li>
    </ul>
 <li>This must also be blue...</li>
 <li>How about <span>SPANS</span> - will they be blue as well?</li>
 <div>Or let's say that I put a div in here (even 
   though I know it's not right), does this then 
   mean that this is blue?
 </div>
</ul>
</div>
<p>I'm also outside</p>

Important note: The color of the <span> in your example is the default black, not blue, because the > does not apply the blue color to it. The reason it appears in blue is because it inherits the color of the parent. Some CSS styles are inherited and some aren't. If your CSS is applying a style that isn't inherited, then the <span> will look different from its parent. Understanding that helps understand the meaning of > *. In your example, you only apply the color blue which is inherited, so simply specifying #sequence .seq-canvas without the > * will have the same effect visually. However, it only applies it to .seq-canvas and the children will inherit it, but visually it's the same. However, if you use a style that's not inherited, then you will see the difference between #sequence .seq-canvas and adding > *.

One style that is not inherited is the border. In the example below, I applied both color and border to #sequence .seq-canvas and #sequence2 .seq-canvas2 > *, so you can see that all children are blue in both cases (first one is inherited and second one is directly applied), but when it comes to the border, the first group of children don't have border because it's not applied to them and they don't inherit it, while the second group have borders because it was directly applied to them:

#sequence .seq-canvas  {color: blue; border: 1px solid green;}
#sequence2 .seq-canvas2 > * {color: blue; border: 1px solid green;}

* { font-size: 10px; }
<p>I'm outside</p>
<div id="sequence">
<ul class="seq-canvas">
  <li>This must be blue</li>
  <li>So is this</li>
  <li>
    <ul>
      <li>But is this blue?</li>
    </ul>
 <li>This must also be blue...</li>
 <li>How about <span>SPANS</span> - will they be blue as well?</li>
 <div>Or let's say that I put a div in here (even 
   though I know it's not right), does this then 
   mean that this is blue?
 </div>
</ul>
</div>
<div id="sequence2">
<ul class="seq-canvas2">
  <li>This must be blue</li>
  <li>So is this</li>
  <li>
    <ul>
      <li>But is this blue?</li>
    </ul>
 <li>This must also be blue...</li>
 <li>How about <span>SPANS</span> - will they be blue as well?</li>
 <div>Or let's say that I put a div in here (even 
   though I know it's not right), does this then 
   mean that this is blue?
 </div>
</ul>
</div>
<p>I'm also outside</p>

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

What is causing the bootstrap nav-bar to not open on smaller screens?

This nav-bar functions properly on screens larger than 640px, but on smaller screens, the menu button does not display the menu items when clicked. You can view the site here. <nav class="navbar navbar-inverse"> <div class="container-fluid" ...

The margin property in jQuery does not seem to be functioning properly when trying to send

Within the view page, there is jQuery code that sets a margin on a div. Below is the code: <script type='text/javascript'> $('#someID').css('margin-left', '10px'); </script> This code functions proper ...

Can you explain the concept of "cascading" within CSS?

Can someone kindly explain the specific definition of "Cascading" in Cascading Style Sheets (CSS)? I have heard conflicting perspectives on this topic, so I am seeking clarification here. Any examples to illustrate would be greatly appreciated. ...

Tips for customizing a link element that routes to a React component

App.js: import './App.css'; import logo from './images/logo.png'; import Home from './components/Home'; import About from './components/About'; import Calculators from './components/Calculators'; import Cla ...

A step-by-step guide to creating adorable rounded corners in a DIV element

I'd like to create a stylish rounded corner div on the top-right and top-left edges. I attempted it with the following code: border-top-left-radius: 5em; border-top-right-radius: 5em; Desired look of the div: https://i.stack.imgur.com/EoSvSm.jpg A ...

A guide on utilizing Selenium to choose an option within a dropdown menu featuring an AJAX onchange attribute

After browsing several pages on stackoverflow, I have not been able to find a solution to my current problem. My goal is to automate a work process using selenium (python). This process requires logging into a web portal, selecting specific search criteria ...

Troublesome Issue with ngAnimate and ngHide: Missing 'ng-hide-animate' Hook Class

I am working on a case where I need to add animation to a DOM object using the ngHide directive: Check out this example here Within this scenario, I have an array of JSON objects: $scope.items = [ {"key": 1, "values": []}, {"key": 2, "values": [ ...

Tips for personalizing the FileField in wtforms to function as an image button

I'm attempting to display an image from my project's directory as an icon instead of the standard "choose file" button. Unfortunately, my attempts thus far have been unsuccessful. Not only is the image not loading, but the original button is only ...

Utilizing Compass SCSS with Blueprint for Optimal Overflow Settings

I've been working with blueprint through Compass, but I'm facing an issue where longer pages don't have scroll bars. It seems like the default setting for overflow is 'hidden'. Since this appears to be the standard, I assume there ...

The CSS grid-template-areas feature is not performing as anticipated

.content { width: 600px; height: 600px; border: 4px solid lime; display: grid; grid-template-areas: 'a d' 'b d' 'c d'; } textarea, iframe { margin: 0; box-sizing: border-box; } .content > .a {gri ...

Having trouble getting the CSS 3 Spin feature to work?

Using webkit for previewing in chrome. The spinning circles I created are not working properly (definitely not an HTML issue.) #loader-wrapper { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000; } #loader { display: inline-bl ...

change the css style with the !important rule to muiStyle

Currently implementing the latest Material-UI library in my project. I am in the process of migrating old CSS files to new MuiStyles. I am converting it within my MuiStyle object using JavaScript as shown below: const muiStyle = { fabStyle: { displ ...

The significance of Z-index in Embedded Email Subscription Code

I am encountering an issue with a pop-up window I have created for visitors to sign up for our mailing list. The problem is that the CSS menu appears on top of the pop-up, despite setting the menu's z-index to 9999. How can I adjust the z-index in the ...

Tips on how to remove the preset text from a textbox with Python Selenium

Has anyone encountered difficulty clearing default data from a textbox using Python Selenium? I keep getting an 'element not interactable' error. Here is the HTML code: <div class="emailAttachmentInputMobile"> <input type=&quo ...

Arranging Radio Buttons in a Row and Aligning a Radio Input Group Side by Side using Bootstrap 5

"I'm having a little issue with aligning radio buttons and a radio input group inline on the same line. The input group keeps moving to a new line for some reason. Can anyone help?" Below is the code snippet: <div class="d-flex flex ...

Difficulty finding elements due to their changing ids

Hey there, I'm pretty new to selenium and I've hit a roadblock with a problem. I have an input nested inside this html block and my job is to find it and send some keys. The tricky part is that not only is the id dynamic, but so are the css selec ...

How to ensure the footer stays at the bottom of the page even when the Treeview control expands

Greetings Everyone! I'm facing an issue with keeping the footer pinned at the bottom of the page. The treeview control I'm using overlaps the footer when expanded. Can anyone assist in ensuring the footer remains at the bottom of the page? < ...

FlexBox responsive items that are expandable getting cut off

I am currently working on creating a row of expandable items. While I have almost achieved the desired behavior, there are a few issues that I need help with: On Desktop, the items are cut off and not fully visible. On Mobile, half of the items are missin ...

Creating a platform that allows users to build custom themes on a website using ASP.NET/C# programming language

I'm looking for a sophisticated approach to designing an ASP.NET website where users can easily create personalized themes for their sites using a user-friendly interface. Can ASP.NET themes assist with this? Should the interface enable users to gener ...

The act of resizing a window causes the text to be forcibly expelled from its containing div

When you hover over an image in a grid, text and a button appear. However, when the window is resized, the content ends up overflowing out of the div. This issue is part of my first project that I am working on during a bootcamp. I have decided to keep th ...