1

I am currently working on a navigation menu where any menu item doesn't fit onto available space get appended onto a hidden unordered list(ul) which can be accessed through a toggle button. What I would like to achieve is to display Group-1, Group-2...as inline-block without affecting css of child elements.I am trying to use below css;

.hidden-link{ display:inline-block; } 

However when I use this line it changes all children element's property to show in a row rather that in a table format. I have tried jquery as well but no win.

$(document).ready(function(){ $("ul.hidden-links").children().css("display","inline-block"); }); 

e.g

<div class="container"> <ul class='hidden-links hidden'> <li>Group1 <ul class ="flash"> <li>item-1</li> <li>item-1</li> <li>item-1</li> </ul> </li> <li>Group2 <ul class ="flash"> <li>item-1</li> <li>item-1</li> <li>item-1</li> </ul> </li> <li>Group3 <ul class ="flash"> <li>item-1</li> <li>item-1</li> <li>item-1</li> </ul> </li> </ul> </div> 
4
  • Your html is invalid. You can use only li in root of ul. Commented Jul 10, 2016 at 12:41
  • UL cannot be direct child of other UL Commented Jul 10, 2016 at 12:43
  • Sorry there were some errors now amended Commented Jul 10, 2016 at 12:46
  • Is there a way to achieve this using jquery so that only css can be applied on the parent element. Commented Jul 10, 2016 at 12:49

3 Answers 3

1

If I understand you correctly, you only need to select the direct children of the menu.

Then this is all you need.

$(document).ready(function(){ $("ul.hidden-links > li").css("display","inline-block"); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Paulie it did work when used you specified selector in css :-) ul.hidden-links > li{ display: inline-block; }
0

If you want each element do be shown on a separate row, then you should be using display: block instead of `inline-block'.

More info on inline-block here http://www.w3schools.com/css/css_inline-block.asp

Comments

0

You can use simple css tricks to tackle this problem. Styled both ul in different css.

.hidden-links li{ display: inline-block; } li .flash li{ display: block; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.