Indents in nested lists in HTML / CSS - html

I've started using Twitter Bootstrap, which is useful for me (as a programmer) to get a decent looking site without having to write much CSS.
However something is driving me crazy. I have a nested list like
<ul>
<li>Hello</li>
<li>World
<ul>
<li>Wide</li>
<li>Web</li>
</ul>
</li>
</ul>
But the first and second level of this list are NOT getting indented differently (ie. they align with each other on the left)
In normal html nested lists, deeper sublists indent more. But something in the style sheet must be turning this off. How do I find what controls this? I can't see a CSS "list indent" attribute for li elements in any documentation.

Just use Firebug in FF or Chrome dev-tools: right-click on your target and select inspect element. You can visually and textually inspect the CSS properties to see what's causing the collapse.
You probably want a rule like
ul > li {
margin-left: 10px;
}

Just to add to the answers above: padding-left will indent the words, but not the bullet point, while margin-left will indent the bullet point as well.
Example: http://jsfiddle.net/GMLxv/

I had the same problem as you.
There's a rule in type.less that cancels the indentation for lists:
ul, ol {
padding: 0;
margin: 0 0 #baseLineHeight / 2 25px;
}
I ended up overriding this rule:
ul, ol {
padding: 0px 25px;
}
Indentation in nested lists is now back.

You're looking to set padding-left:
li { padding-left: 1em; }
will indent every li 1em. Since the inner lis are already offset from the outer lis, it should do what you want.

Is it perhaps that you have set your bullets points to be inside the list items instead of before it, which would change your look quite significantly.
The CSS to apply it: ul { list-style-position: inside; }
Read more about list-style-position.
Example : https://jsfiddle.net/g0k0obwh/

You wouldn't want to apply the padding onto the li elements since that would create a padding between the bullet and the list if you are using a bulleted list. See:
ul > li {
padding-left:25px;
}
result:
- Hello
- World
- Wide
- Web
Neither would you want to apply it to the parent ul elements with ul { padding-left:25px;} which would give:
- Hello
- World
- Wide
- Web
The answer to your question is:
li > ul {
padding-left:25px;
}
result:
- Hello
- World
- Wide
- Web

Using Bootstrap you could do that by coding as follows. Just paste it your JSP or HTML and test it. You could go through this link for more information.
http://www.bootply.com/DglnYJTSKA
<div id="MainMenu">
<div class="list-group panel">
Item 3
<div class="collapse" id="demo3">
Subitem 1 <i class="fa fa-caret-down"></i>
<div class="collapse list-group-submenu" id="SubMenu1">
Subitem 1 a
Subitem 2 b
Subitem 3 c <i class="fa fa-caret-down"></i>
<div class="collapse list-group-submenu list-group-submenu-1" id="SubSubMenu1">
Sub sub item 1
Sub sub item 2
</div>
Subitem 4 d
</div>
Subitem 2
Subitem 3
</div>
Item 4
<div class="collapse" id="demo4">
Subitem 1
Subitem 2
Subitem 3
</div>
Item 5
<div class="collapse" id="demo5">
Subitem 1
Subitem 2
Subitem 3
</div>
</div>
</div>
CSS:
.list-group.panel > .list-group-item {
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px
}
.list-group-submenu {
margin-left:20px;
}

Related

How to reference sibling list items

I building a common css user file for two different web pages. I have unordered lists on two different pages. In the actual html there are lots of unordered lists deeply nested in divs and what have your. The actual number of list items is greater than shown here. I need to format the first set of list items differently than the second set. There is nothing different in the ul coding. There is too much css to wade through for other differences.
<-- list in first page -->
<ul class="our-list">
<li class="group item" data-filter-id="draft">a little bit of <span>text</span></li>
<li class="group item" data-filter-id="contentstatus[published]">other <span>text</span></li>
<li class="group item" data-filter-id="participated">last of the <span>text</span></li>
</ul>
<-- list in second page -->
<ul class="our-list">
<li class="group item" data-filter-id="One">a little <span>text</span></li>
<li class="group item" data-filter-id="Two">the <span>text</span></li>
<li class="group item" data-filter-id="Three">last <span>text</span></li>
</ul>
The only discernible difference that I have noticed is different data-filter-id fields. I need to reference the span tags in the first list and not the second.
I've written this css to address the first li in the first list:
li[data-filter-id="draft"] span {
background-color: yellow !important;
}
Is there some way to refer to the sibling li tags in this css?
I could code:
li[data-filter-id="draft"] span,
li[data-filter-id="contentstatus\[published\]"] span,
li[data-filter-id="participated"] span, {
background-color: yellow !important;
}
But is there some shortcut I could code to have to list all the adjacent list items?
This this the correct way to escape the imbedded [] in css?
li[data-filter-id="contentstatus\[published\]"] span,
Is this the correct way to include the class on the css for the li tag?
li.group.item[data-filter-id="draft"] span,
Use ul:first-of-type > li as a selector for all li items inside the first ul
If that isn't sufficient (you write about different pages), use a class on the according ul and address the child lis of that class like ul.my-class > li

Indent for Nested List Items Next to Float Image

I have nested lists sitting next to a floated image. The floated image "consumes" all of the left-margin for the nested list. Is there any way to make it so that the nested-list indents outward from the image, as if there were no image there?
Here is a screenshot:
On the left we have how it's being rendered when there's a float. On the right we have how it's being rendered when there is no float.
Is there any way to get the nested list items to kick to the right the same way, whether or not there's an image floated to the left?
Thanks!
I had exactly the same problem (that's how I found this post), but I finally got it figured out. Look at the attached image to see what I explain below.
The following HTML produces an error like what the original poster has (edited for brevity):
<figure style="float:left; margin:1em 4em 1em 0; width:231px;">
<img style="box-shadow:0 1px 5px; border-radius:5px;" src=" ... .jpeg?w=231" width="231" height="300" />
<figcaption> ... </figcaption>
</figure>
<p><strong>The Rough Plan</strong>
The app needs to have (eventually) all of the following features:</p>
<ul>
<li>A full recipe book
<ul>
<li>The ability to add/remove/edit recipes.</li>
</ul>
</li>
...
<li>Generate shopping lists.</li>
</ul>
When you inspect the list elements using the browser's dev tools you can see that all of the spacing for the Unordered List tag is being measured from the size of the page content area, not from the remaining space next to the floating image.
By setting the overflow style to auto that got me a partial fix. The list, and all of it's sub items, began to indent properly next to the image but for some reason all of the top-level bullets disappeared. This other post led me to try adjusting the padding of the list which worked! All together all I had to do was changed the opening tag from <ul> to <ul style="overflow:auto; padding:0 0 0 1em;">.
Obviously, you'd want to do this in a style sheet, not in the HTML itself.
You can give margin-left to the submenu .. but ..
Why not use flexbox?
.container {
display: flex;
flex-wrap: wrap;
width: 500px;
border: 1px solid #999;
background: #F2F2F2;
}
ul {
margin: 0 30px;
padding: 0;
}
ul > li + ul {
margin-left: 20px;
}
<div class="container">
<img src="http://placehold.it/200x200" alt="Imagen">
<div class="flex-uls">
<ul>
<li>Top Item</li>
<li>Top Item</li>
<li>Top Item</li>
<ul>
<li>SubLevel Item</li>
<li>SubLevel Item</li>
<li>SubLevel Item</li>
</ul>
</ul>
</div>
</div>

How to add space before bullet points in HTML

I want to add space before bullet points . My requirement like
This is paragraph1
The text line one
The text line two
This is paragraph 2
The text line one
The text line two
Any help will be appreciated.
Try setting margin to li
li{
margin-left: 20px;
}
JSfiddle here
There is spacing before bullet points by default. If there isn’t, you are probably using a “Reset CSS” of some kind.
To set the spacing to a desired value, set padding-left and margin-left of both ul and li elements to zero and then set one of them to the desired value.
CSS:
li {
margin-left:1em;
}
You can set CSS to li as per your requirement.
HTML Code
<p>This is my paragraph1</p>
<ul><li> List One </li>
<li> List Two </li>
<li> List Three </li>
</ul>
<p>This is my paragraph 2</p>
<ul><li> List One </li>
<li> List Two </li>
<li> List Three </li>
</ul>
CSS
li {
margin-left:1em;
}
JSFiddel
apply margin-left to ul
Working Fiddle example is here:
Code:
[http://jsfiddle.net/Sharan_thethy/MNaUn/][1]
I hope this will help you

How to selected nested First ul from multiple div

Select just the First ul in class area by css
<div class='area'>
<div>
<ul>
<li>
<ul>
</li>
</div>
</div>
<div class='area'>
<div>
<ul>
<li>
<ul>
</li>
</div>
</div>
<div class='area'>
<div>
<ul>
<li>
<ul>
</li>
</div>
</div>
I tried this
'.area > ul' # This is not working as div is in between the .area and ul
Is there a different way to select the elements without referencing the in-between div in the selector?
So, Finally I should get just 3 ul without nested ul's
Update
In some other templates of my code the first ul comes after the second level
So to avoid confusion in selector, I am trying to avoid the inbetween divs.
Assuming you actually had valid HTML, you could use the * wildcard selector, which is as close as you're going to get to "[not] referencing the in-between div". That said, what's wrong with referring to the child <div>?:
.area > * > ul {
// Properties
}
Using > * matches any child tag, so it makes your CSS slightly more flexible, if that's your end goal.
For (potentially) two levels of elements, assuming they're <div>s, you can do the following:
.area > div > ul,
.area > div > div > ul, {
// Properties
}
'.area ul' would be the selector you are looking for if your html was correct.
edit:
Sorry, the html is kind of confusing... I thought those were </ul>s and that <ul>s were overlapping with <li>s.
This question my be relevant to your problem:
Similar to jQuery .closest() but traversing descendants?

How to position an inner - inner tag at different position?

I asked a more basic question before (How can I position an inner tag at different position?) and it was answered perfectly.
But I forgot about the deeper sub-levels..
The basic problem is that the top-level items are displayed in a different position on the page than the sub-level ones..
So the structure looks now like this:
<div id="menu">
<div class="body-menu">
<ul>
<li class="current"><div class="body-menu">
Item1
<ul>
<li class="current"><div class="body-menu">
Item 1.1
<ul>
<li class=""><div class="body-menu">
Item 1.1.1
</div></li>
<li class="current deepest-menu"><div class="body-menu">
Item 1.1.2
</div></li>
</ul>
</div></li>
<li class=""><div class="body-menu">
Item 1.2
</div></li>
</ul>
</div></li>
<li class=""><div class="body-menu">
Item 2
</div></li>
</ul>
</div>
<div class="menu-background"></div>
</div>
I used this code to fix the basic problem of showing the sub-level ones in the left-side-menu and the top-level at their original position (top menu)
.body-menu > ul > li {
position:relative;
padding-bottom: 1em;
}
.body-menu ul ul {
position:absolute;
left:10px;
top:30px;
}
but now the items at level 1.1.1 are displaying over the 1.1 ones...
is there an easy solution to this?
thanks in every case for your help!
--crisler
UPDATE
css stuff
http://jsfiddle.net/crisler/wZrVS/ (simple)
http://jsfiddle.net/crisler/pMTHX/1/ (more items..)
a little bit crowded because most of it is from the university css file..
hope i got everything
Use this CSS instead:
.body-menu ul ul.second-level {
position:absolute;
left:10px;
top:30px;
}
And add a second-level class to all the uls that are immediately nested after the first level items (ie. Item 1, Item 2, ...):
Item1
<ul class="second-class">
The problem is that you are applying that CSS rule to all the sublists in your code. With this change it will only affect to the second level of lists, and the rest will behave normally.
This is the result:
And this is the edited fiddle (the one with more items): http://jsfiddle.net/pMTHX/2/