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.

[CSS] how do I style div inside li?

Featured Replies

I am trying to style an existing template.

 

I have the following code:

 

<li class="even">
 <div class="clr">
</li>

 

I would like to style the 'clr' class but only when it occurs inside the list class "even".

 

Could someone explain how I do this?

 

Thank you in advance.

li.even .clr {
 color: red;
}

This will make all text red for any element with a .clr class that's within a listitem ( LI ) with an .even class.

this applies to everything. For example, if you wanted to syle all the spans with and id of "blue", but only if theyre inside an anchor tag with class of "red", and only then if the body tag is id'd "home", it would look like this:

 

body#home a.red span#blue{

/*--Styling--*/

}

 

That's why they call 'em "cascading" style sheets.

li.even .clr {   color: red; }

 

Every day i learn something very usefull. Thanks!

Hello,

 

If we talk in semantic a div inside a li isn't correct. For that you use span.

 

Best Regards

Hello,

 

If we talk in semantic a div inside a li isn't correct. For that you use span.

 

Best Regards

 

divs and spans have no semantic meaning. The only difference is that one is a block and one is in-line.

li elements allow flow content - which means inline and block. http://www.w3.org/TR/html4/struct/lists.html#h-10.2

 

Nothing wrong with div inside a li.

Hello,

 

Dear Thomas Thomassen tks for correcting me, I thought it was only inline elements.

Sorry for the mistake.

 

Best Regards.

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.