I have the following unordered list item with nested ul. How do I select the first li aka the text "List A" ?
I tried ul > li:first-child but this selects the first list item's child as well.
<div class="container">
<ul>
<li>
List A
<ul>
<li>List A sub</li>
<li>List A sub</li>
<li>List A sub</li>
<li>List A sub</li>
</ul>
</li>
<li>
List B
<ul>
<li>List B sub</li>
<li>List B sub</li>
<li>List B sub</li>
<li>List B sub</li>
</ul>
</li>
</ul>
</div>
You should set it up with the default style of ul > li.
ul > li{
font-weight: normal;
color: gray;
}
.container > ul > li:first-child {
font-weight: bold;
color: red;
}
<div class="container">
<ul>
<li>
List A
<ul>
<li>List A sub</li>
<li>List A sub</li>
<li>List A sub</li>
<li>List A sub</li>
</ul>
</li>
<li>
List B
<ul>
<li>List B sub</li>
<li>List B sub</li>
<li>List B sub</li>
<li>List B sub</li>
</ul>
</li>
</ul>
</div>
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
I have a container inside a parent with fixed position, and want to apply the same height of the parent element to that container. But the height: 100% is not applying. What am I missing here?
.fixed-container {
position: fixed;
width: 400px;
top: 50px;
max-height: calc(100% - 100px);
}
.list-container {
height: 100%;
overflow-y: scroll;
}
https://codepen.io/NoahWetjen/pen/dyjVbRX
Ok. Just add display:flex; flex-direction:column to .fixed-container
.fixed-container {
position: fixed;
width: 400px;
top: 50px;
max-height: calc(100% - 100px);
background: lightgreen;
display:flex;
flex-direction:column;
}
.list-container {
height: 100%;
overflow-y: scroll;
background: rgba(0,0,0,.2);
}
<div class="fixed-container">
<div class="list-container">
<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>
<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>
</div>
</div>
change max-height to height so both elements have the same height
To be honest i dont really understand what you want. is this what you are looking for?
.fixed-container {
position: fixed;
width: 400px;
top: 50px;
max-height: calc(100% - 100px);
background: lightgreen;
overflow:hidden
}
.list-container {
height: inherit;
overflow-y: scroll;
background: rgba(0,0,0,.2);
}
<div class="fixed-container">
<div class="list-container">
<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>
<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>
</div>
</div>
I new to CSS and I want to ask a question: I have a <header> with two elements and I want to align them, the title on the right and the navigation on the left, but I couldn't really hack it alone.
<pre>
<header >
<h1>Title</h1>
<nav class="navigation">
<ul class="navlist">
<li>list element</li>
<li>list element</li>
<li>list element</li>
</ul>
</nav>
</header>
</pre>
You should learn about flexbox:
header {
display: flex;
}
header h1 {
order: 1;
}
<header>
<h1>Title</h1>
<nav class="navigation">
<ul class="navlist">
<li>list element</li>
<li>list element</li>
<li>list element</li>
</ul>
</nav>
</header>
I guess may you want to achieve in this ui look.
Here is some good article may can helps you flexbox
#parent {
width: 100%;
}
header {
display: flex;
justify-content: space-between;
}
<div id="parent">
<header>
<h1>Title</h1>
<nav class="navigation">
<ul class="navlist">
<li>list element</li>
<li>list element</li>
<li>list element</li>
</ul>
</nav>
</header>
</div>
I want the scrollable part of the page to scroll within it's height only. But it overlaps with the header whose position has been set to 'fixed'.
Here is the fiddle: https://jsfiddle.net/3xc9n6jb/
How do I make them not overlap so that the scrollable content scrolls without touching the header?
<div class="main-div">
<div class="myBox"></div> <!--This red rectangle is the header. The scrollable content should not overlap with this.-->
<div class="scrollable-content horizontal">
<ul>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
<li>Fourth Item</li>
<li>Fifth Item</li>
<li>Sixth Item</li>
<li>Seventh Item</li>
<li>Eight Item</li>
<li>Ninth Item</li>
<li>Tenth Item</li>
</ul>
</div>
</div>
.myBox {
width: 500px;
height: 50px;
background-color: red;
position: fixed;
}
ul {
position: absolute;
margin-top: 30px;
}
maybe you want something like this:
<div class="main-div">
<div class="myBox"></div> <!--This red rectangle is the header. The scrollable content should not overlap with this.-->
<div class="scrollable-content horizontal">
<ul>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
<li>Fourth Item</li>
<li>Fifth Item</li>
<li>Sixth Item</li>
<li>Seventh Item</li>
<li>Eight Item</li>
<li>Ninth Item</li>
<li>Tenth Item</li>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
<li>Fourth Item</li>
<li>Fifth Item</li>
<li>Sixth Item</li>
<li>Seventh Item</li>
<li>Eight Item</li>
<li>Ninth Item</li>
<li>Tenth Item</li>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
<li>Fourth Item</li>
<li>Fifth Item</li>
<li>Sixth Item</li>
<li>Seventh Item</li>
<li>Eight Item</li>
<li>Ninth Item</li>
<li>Tenth Item</li>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
<li>Fourth Item</li>
<li>Fifth Item</li>
<li>Sixth Item</li>
<li>Seventh Item</li>
<li>Eight Item</li>
<li>Ninth Item</li>
<li>Tenth Item</li>
</ul>
.myBox {
width: 500px;
height: 50px;
background-color: red;
position: fixed;
top:0;
}
ul {
margin-top: 50px;
}
the key is dont use position:absolute in ul selector and add the value of margin-top equals to height of mybox.
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 am trying to line up a footer menu and to select only the first list elements as single selection
<ul class="someclass">
<li><!--this is what I am trying to capture-->
<a>something arbitrary here</a>
<ul>
<li>list elemnts here</li>
<li>list elemnts here</li>
<li>list elemnts here</li>
<li>list elemnts here</li>
</ul>
</li>
<li>
<a>something arbitrary here</a>
<ul>
<li>list elemnts here</li>
<li>list elemnts here</li>
<li>list elemnts here</li>
<li>list elemnts here</li>
</ul>
</li>
<li>
<a>something arbitrary here</a>
<ul>
<li>list elemnts here</li>
<li>list elemnts here</li>
<li>list elemnts here</li>
<li>list elemnts here</li>
</ul>
</li>
</ul>
I want to be able to select all the top <li> elements, without directly selecting every other interior <li> elements. which css selectors should I use?
.someclass > li:first-child {
}
Example: http://jsfiddle.net/yUMwD/
Or to select all lis on that level:
.someclass > li {
}
> means 'child element', so it's would take the li that is directly under .comeclass