I set up a simple css based dropdown navigation.
The last category of the main navigation (named login) is supposed to look different from the rest, hence I simply applied a different style via last-of-type.
However the style now gets applied to the drop-down menus as well, meaning the last item of the dropdowns have said style applied also.
(Also, I cannot target them with nth-... selector since there will be new categories added / removed every once in a while.)
How would I stop this form happening?
<ul>
<li>item 1
<ul>
<li>subitem 1</li>
<li>subitem 2</li>
<li>subitem 3</li> <-- unfortunately different style also...
</ul>
</li>
<li>item 2</li>
<li>item 3</li>
<li>login</li> <-- different stlye
</ul>
If you use a wrap for your unordered lis you can use something like this
<div class="test">
<ul>
<li>item 1
<ul>
<li>subitem 1</li>
<li>subitem 2</li>
<li>subitem 3</li> <!-- unfortunately different style also...-->
</ul>
</li>
<li>item 2</li>
<li>item 3</li>
<li>login</li> <!-- different stlye -->
</ul>
</div>
So the CSS
.test > ul > li:last-of-type{color:red;}
set style only for the first ul after div.test and doesn't affect the other nested elements
Codepen
I tried the solution for SlickNav fixed header here:
How to make a fixed header with SlickNav
This works, but I then have a problem: my lengthy SlickNav menu list can no longer scroll, it stucks at bottom of the screen. Is there a solution?
Thank you.
Edit:
My changes from original slicknav package to reproduce the problem:
1) Add to dist/slicknav.css after the line 78 (.slicknav_menu) the following lines to get fixed header:
/* change to make sticky menu */
/* but this overrides top of each page, to fix */
/* also the whole menu could no longer be scrolled! */
/* https://stackoverflow.com/questions/19854185/how-to-make-a-fixed-header-with-slicknav*/
display: block;
position: fixed;
width: 100%;
top: 0;
2) Add a very long menu item list to demo/index.html after Parent 2, item 7 (line 39) :
<ul id="menu">
<li>Parent 1
<ul>
<li>item 3</li>
<li>Parent 3
<ul>
<li>item 8</li>
<li>item 9</li>
<li>item 10</li>
</ul>
</li>
<li>item 4</li>
</ul>
</li>
<li>item 1</li>
<li>non-link item</li>
<li>Parent 2
<ul>
<li>item 5</li>
<li>item 6</li>
<li>item 7</li>
</ul>
</li>
<li>Added item First</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item 1</li>
<li>Added item Last</li>
</ul>
Now when you use mobile mode, the last item line "Added item last" cannot be seen since the menu list is to long and is no longer scrollable as it was before setting the fixed header in 1).
Incidentally by searching I found that other user had similar problem :
How to make a fixed header with SlickNav
I have a list of say 20 items. But for my design I need to ensure there is never more than 5 items per ul. Is there a way I can loop through the list and after every 5, start a new ul? Not sure if this is possible, but if you've got any alternatives let me know.
Current list:
<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>
Desired Result:
<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>
<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>
<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>
<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>
Since it is MVC, it is pretty easy to do this in a nice and simple fashion without getting int String Builders and html within your code.
Lets say you have your page model which is an Enumerable of your data model.
You could do something like
#For i As Integer = 0 to Model.Count() - 1
#IIf(i Mod 5 = 0, Html.Raw("<ul>"), "")
#<li>#Model(i).Value</li>
#IIf((i + 1) Mod 5 = 0, Html.Raw("</ul>"), "")
Next
note This has not been tested and been a while since I did MVC with vb.net, so might not be 100% correct
Are you looking to manipulate existing and rendered HTML? Because then I wouldn't use VB.NET but rather jQuery or some kind of client-side technology to manipulate your HTML. If you're composing the HTML from code to be sent to the view you can try following code:
Dim sb As New StringBuilder()
sb.Append("<ul>")
For i As Integer = 1 To 20 Step 1
sb.Append("<li><a href=''>list item</a></li>")
If (i Mod 5) = 0
sb.Append("</ul><ul>")
End If
Next
Dim result As String = sb.ToString()
result = result.Remove(result.LastIndexOf("<ul>"))
Give this a try
Dim someItms() As String = New String() {"Lorem", "ipsum", "dolor", "sit", _
"amet", "consectetur", "adipisicing", _
"tempor", "incididunt", "ut", "labore", _
"sunt", "in", "culpa", "qui", "officia", "deserunt", _
"mollit", "anim", "id", "est", "laborum", "LASTITEM"}
Dim myelmnts As XElement = <div></div>
Const grpsz As Integer = 5 'numer of li's per ul
For x As Integer = 0 To someItms.Length - 1 Step grpsz
'get a group, note last group may or may not be full
Dim foo As IEnumerable(Of String) = someItms.Skip(x).Take(grpsz)
Dim ul As XElement = <ul></ul> 'define ul
Dim li As XElement 'define li
For Each s As String In foo 'create li's
li = <li><%= s %></li>
ul.Add(li) 'add to ul
Next
myelmnts.Add(ul) 'add completed ul to list
Next
I have a navigation bar with drop down menus created with UL elements. Currently, the drop down table shifts when the web page is zoomed in or out. How do I style the CSS so that the drop down menus will stay aligned?
<ul id="links">
<li>First link</li>
<li>Second link
<ul id="dropdown1">
<li>Drop down item 1</li>
<li>Drop down item 1</li>
<li>Drop down item 1</li>
</ul>
</li>
<li>Third link</li>
<li>Fourth link
<ul id="dropdown2">
<li>Drop down item 1</li>
<li>Drop down item 1</li>
<li>Drop down item 1</li>
</ul>
</li>
</ul>
jsFiddle here.
I am using a Bootbusiness theme in my Twitter Bootstrap website, and I am trying to create the stacked tab navigaton, as seen in the documentation of Bootstrap but whenever I try do it only appears as a List without style. And not styled as stacked button.
Here is my code in the HTML
<div >
<ul class="nav nav-tabs nav-stacked">
<li class="active">List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
</div>
You need to have an anchor inside li to get the styles
Fiddle
<div>
<ul class="nav nav-tabs nav-stacked">
<li class="active">List Item </li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
</div>