3

I have an unordered list element contains list of elements like this.

<div class="menu">
<ul>
<li class="menu-x">x1</li><li class="menu-x">x2</li><li class="menu-x">x3</li>
<li class="menu-y">y1</li><li class="menu-y">y2</li><li class="menu-y">y3</li>
<li class="menu-z">z1</li><li class="menu-z">z2</li><li class="menu-z">z3</li>
</ul>
</div>

And in the css when using display: inline;.it is not showing or hiding the particular element.So this is my css.

div.menu li{
  display: inline;
  border-radius:2px;
  font-size:12px;
  margin:5px;
  box-shadow:0 0px 5px #FFFFFF;
  padding:7px 7px 0px 7px;
}
li.menu-y{
  display:none;
}
li.menu-z{
  display:none;
}

fiddle is here

1
  • you can use float:left instead of display:inline Commented Apr 13, 2016 at 6:07

3 Answers 3

5

The display: none has no effect because the earlier selector div.menu li is more specific and so it takes precedence. Change the selector to something like div.menu li.menu-y.

The selector div.menu li has a specificity of 012 because it has 1 class selector and 2 element type selectors as part of it whereas the li.menu-y and li.menu-z selectors have a specificity of only 011 because it has only 1 class selector and 1 element type selector as part of it.

Changing the selector to div.menu li.menu-y would mean that the specificity becomes 022. Thus, it it will take precedence over div.menu li and so the display: none will take effect.

Or even .menu li-menu-y would be sufficient because its specificity is 021 (2 classes and 1 element type) but I prescribed the other because I felt it was more consistent with your earlier selector.

div.menu li {
  display: inline;
  border-radius: 2px;
  font-size: 12px;
  margin: 5px;
  box-shadow: 0 0px 5px #FFFFFF;
  padding: 7px 7px 0px 7px;
}
div.menu li.menu-y {
  display: none;
}
div.menu li.menu-z {
  display: none;
}
<div class="menu">
  <ul>
    <li class="menu-x">x1</li>
    <li class="menu-x">x2</li>
    <li class="menu-x">x3</li>
    <li class="menu-y">y1</li>
    <li class="menu-y">y2</li>
    <li class="menu-y">y3</li>
    <li class="menu-z">z1</li>
    <li class="menu-z">z2</li>
    <li class="menu-z">z3</li>
  </ul>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

try this one:

div.menu li{
  display: inline;
  border-radius:2px;
  font-size:12px;
  margin:5px;
  box-shadow:0 0px 5px #FFFFFF;
  padding:7px 7px 0px 7px;
}
.menu .menu-y{
  display:none;
}
.menu .menu-z{
  display:none;
}

DEMO HERE

1 Comment

It is great that you have a solution but you should have a valid reason for that!
0

Try like this:

ul li .menu-y {
  display:none;  
}

ul li .menu-z {
  display:none;  
}

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.