2

I want one <li> inside of a <ul> that I don't want to be affected by the CSS that affects the rest of the <li> elements in the list.

I am trying to add an id or a class to the line item element, but I can't figure out the correct syntax to do this:

<li id="submit">
  <button id="seSubmitButton" class="btn btn-success" data-placeholder="SUBMIT">
    SUBMIT
  </button>
</li>

The css that affects this is here:

.dropdown-menu>li:hover {
  background-color: #f2c2c2;
}

I tried multiple things here:

.dropdown-menu>li>submit :hover {
  background-color: #a2a2a2;
}

like .dropdown-menu>li submit or just .li submit

but it's not picking it up. What am I doing wrong with the specific syntax to make this specific <li> picked up by my CSS?

3 Answers 3

1

You would use the selector li#submit since the li element has an id of submit:

Example Here

.dropdown-menu>li#submit:hover {
  background-color: #a2a2a2;
}

You could also use the :not() pseudo class to negate the li#submit element when setting the initial styling that you are trying to overwrite:

Example Here

.dropdown-menu>li:not(#submit):hover {
  background-color: #f2c2c2;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Great. Thank you for this! Where can I read on the differences between all the different characters I could possibly put - . vs # vs > etc....
@JohnWu MDN is the best place.. Scroll down to "CSS Selectors" developer.mozilla.org/en-US/docs/Web/CSS/Reference
Why not? When you have no experience with basics w3schools is fine.
1

When you added id, you can use it in your stylesheet to address the element:

#id {
    background-color: #f2c2c2;
}
#id:hover {
     /* some style */
}

Comments

0

You should use # while using id and dot(.) while using class.

for id

 #idName {
    /* css propery here */
    }

for class

.className {
    /* css propery here */
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.