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>
Related
I am making a webpage for a college project.
I have a navigation bar made with an unordered list and css, and i cannot figure out how to create a bulleted list on that page without it also going into the nav bar.
I am new to programming and html in general.
HTML
<ul>
<li>
Home
</li>
<li>Hobbies</li> <li>Contact</li>
<li>Image Gallery</li>
</ul>
thank you
Change your menu html tags to <nav> <ul> so that it looks something like this...
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
Then apply your menus CSS to that style set only i.e.
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}
Now you can create your bullet point list normally on the same page without conflict. i.e.
<ul>
<li>List Item 1</li>
<li>List Item 1</li>
<li>List Item 1</li>
</ul>
If you've found it helpful please mark this as the accepted answer to your question. Thanks.
You can use a class or id from your CSS. E.g.
.nonbulletnav {
list-style-type: none;
}
Or
#nonbulletnav {
list-style-type: none;
}
Then in your html code just give that class or id to <ul> element as:
<ul class="nonbulletnav">
....
....
</ul>
list-style-type is an important attribute. With this you can style the bullets in different ways like use square instead of circular bullets. You can read about it on MDN. As it is obvious list-style-type: none takes off the bullets and indents the list element properly.
To create a bulleted list, use the unordered list tags <ul></ul> and list item <li></li> tags as shown in the example below.
<ul>
<li>Example</li>
<li>Example2</li>
<li>Example3</li>
</ul>
The above example would create a bulleted list as shown below.
Example
Example2
Example3
If you wanted to change this list to an ordered list (numbered list), change the <ul></ul> tags to <ol></ol>, as shown in the example below.
<ol>
<li>Example</li>
<li>Example2</li>
<li>Example3</li>
</ol>
The above example would create a numbered list as shown below.
1.Example
2.Example2
3.Example3
If you wanted to apply CSS style or use an image as your bullet list, create CSS code similar to the example below.
#content ul li
{
list-style-Type: none;
padding: 0 0 4px 23px;
background: url(http no-repeat left top;
}
In this example, using an external .css file, we're telling the web page to only change the bulleted items in the <div id="content"></div> section. If you want all bulleted items to change, you can remove the #content in the above example. In the second line, the list-style-Type: none; tells the browser to display no bullets. In the third line, the padding: 0 0 4px 23px; is the padding and indent around the bullets. Finally, the last background line tells the browser to use an image as the bullet and where to display it. With this CSS code, we get bullets as shown below.
For the navigation on a website I am making I am using a side bar that is set up using an unordered list. There are also multiple lists inside of lists. I used multiple div's too. I have now run into the issue that form inside of a div I need to set up some code that will contradict the div that it is in. In my case I have css of line-height: 35px; I need to edit this to become 15px.
Here is the code i need to edit it is the center( sub List )
<li>
<h2> Tech Ed. Classes</h2>
</div>
<div id="sidebarLinks"><!-- USE THIS DIV SECTION FOR A LIST WITH BULLET POINTS -->
<ul>
<li><strong><em>Main Page</em></strong></li>
<li>Construction</li>
<li>Drafting</li>
<li>Electronics</li>
<ul id="subList">
<li >INTRODUCTION TO ELECTRONICS</li>
<li>EXPLORING CAREERS IN ELECTRONICS</li>
</ul>
<li>Graphic arts </li>
<li>Manufacturing</li>
<li>Project Lead the Way</li>
<li>Transportation, Distribution, & Logitstics</li>
<li>Wood Working</li>
</ul>
</div>
</li>
You can do this simply by adding a css class to the elements you want to change to be different from the div they are in. For example:
li {
line-height: 35px;
}
.smaller {
line-height: 15px;
}
This CSS will make the line-height on all <li> elements equal to 35px, except for <li> elements with a class of smaller. Those will have a line-height of 15px. For example:
<ul>
<li>This will have a line height of 35 pixels.</li>
<li class="smaller">This will have a height of 15 pixels.</li>
</ul>
<ul class="smaller">
<li>This will have a line height of 15 pixels, the ul has a class of smaller.</li>
<li class="smaller">This will have a height of 15 pixels as well.</li>
</ul>
JSFiddle
I would suggest adding a more specific selector for the inner list. This method would not require any changes to your existing markup:
#sidebarLinks {
line-height: 25px;
}
#sidebarLinks #subList {
line-height: 15px;
}
Here is a fiddle demonstrating the above selectors: JSFiddle
What the Header Should Look Like
This is how the header should look like.
What it currently looks like
As you can see, my header isn't looking too good... I seem to be having some floating issues.
Current Header Code
Here is the HMTL I used to generate my header.
I'm trying to center the h1, float the logo to the left completely and have the h2 display beside the logo. The publish date and publisher are fine.
<header>
<ul style="list-style-type:none;float:right;">
<li style="float:left;">
<img src="C:\Logo.jpg" alt="Logo"/>
</li>
<li style="float:left;">
<h2>Statuts de Production</h2>
</li>
<li style="float:right;">
<h1 style="margin-bottom:0px">Machines en cours d'assemblage</h1>
</li>
<ul style="list-style-type:none;float:right;">
<li>
Dernière mise à jour: <xsl:value-of select="Table/Publish/DateEntry"/>
</li>
<li>
Par: <xsl:value-of select="Table/Publish/Username"/>
</li>
</ul>
</ul>
</header>
Am I not using the right approach? Should I use a table instead of an unordered list?
If you want to vertical align the list items and indent the middle one, just remove the styles from the HTML and use this external CSS (using external CSS is the first thing to improve your approach):
ul { display: block; list-style-type:none; height: 50px; }
li { display: inline-block; vertical-align: middle; }
ul ul { display: inline-block; }
ul ul li { display: block; }
and set the padding to each list item as you want, the third item might be floated right.
Second: you can not use image path on your HDD C:\Logo.jpg to enable the access from clients, use the http://... protocol.
Third: you can not use ul as direct child of ul. Only lis are allowed inside ul
<ul>
<li>item 1</li>
<li>item 2</li>
<li>
<ul>
<li>subitem 1</li>
<li>subitem 2</li>
</ul>
</li>
</ul>
Dose the following help you? it is designed such that the hight is constant.
<div style='position:relative; padding:0px 200px 0px 200px; background-color:gray;height:20px;box-sizing:border-box;'>
<div style='position:absolute;background-color:yellow; left:0px; top:0px; height:100%;width:200px;'>
left pannel
</div>
<div style='position:absolute;background-color:yellow; right:0px; top:0px; height:100%; width:200px;'>
right pannel.
</div>
<div style='box-sizing:border-box;width:100%;text-align:center;'>
Center
</div>
</div>
You can see it also here.
I want to make my menu and image appear on the same line but sadly that doesn't seem to be happening. Could anyone tell me why and how I would solve my problem? I've got the following image and menu...
HTML
<div id="header">
<img alt="" height="67" src="Aidanlogo.png" width="400" />
<div id="myslidemenu" class="jqueryslidemenu">
<ul>
<li>Home</li>
<li>Blog</li>
<li>About</li>
<li>Contact</li>
</ul>
<br style="clear: left" />
</div>
</div>
Menu CSS: http://pastebin.com/drMD7gwg
Header CSS
#header {
width: 700px;
margin-left: auto ;
margin-right: auto ;
}
try this
#menu ul li { display: inline; }
Divs are block elements, so by default it will always appear on a separate line.
You could make the image a block and float it left (display:block; float:left;)
You could make your div display:inline-block, or float:right; it, assuming there's room in the parent (700px).
DIV is a block element, so it won't display on the same line as anything else unless you change it's inline property:
#myslidemenu { display:inline; }
Also note that you'll have to modify the <ul> styles to display the <li> tags on a single line. See this link for more on that part.
edit I'm not sure what the jQuery slide menu does to the <div> or <ul> styles - you might have a look in Firebug after it's rendered.
Given the following markup:
<ul>
<li>apple</li>
<li class="highlight">orange</li>
<li>pear</li>
</ul>
Both the uls and the lis widths appear to be 100%. If I apply a background-color to the list item, the highlight stretches the full width of the page.
I only want the background highlight to stretch as wide as the widest item (with maybe some padding). How do I constrain the lis (or perhaps the uls) width to the width of the widest item?
Adding ul {float: left; } style will force your list into preferred width, which is what you want.
Problem is, you should make sure next element goes below the list, as it did before. Clearing should take care of that.
Can you do it like this?
<ul>
<li>apple</li>
<li><span class="highlight">orange</span></li>
<li>pear</li>
</ul>
Exactly as BoltBait said, wrap your text in an inline element, such as span and give that the class.
<ul>
<li>apple</li>
<li><span class="highlight">orange</span></li>
<li>pear</li>
</ul>
My extra 2 cents is that if you don't have access to change the HTML, you can do it using Javascript. In jQuery:
$('li.highlight').wrapInner("<span></span>");
and use the CSS:
li.highlight span { background-color: #f0f; }
edit: after re-reading your question, can you clarify: do you want the highlight to only go as wide as the element which is highlighted, or as wide as the widest element in the list? eg:
- short
- items ********************
- here
- and then a really long one
...where the asterisks represent the highlighting. If so, then buti-oxa's answer is the easiest way. just be careful with clearing your floats.
Adding style="float: left;" to ul will cause the ul to only stretch as wide as the widest item. However, the next element will be placed to the right of it. Adding style="clear: left;" to the next element will place the next element after the ul.
Try it out
See documentation on float and clear.
The best way of going about solving this without messing up the style of your existing layout, is by wrapping the ul and li in a div with display: inline-block
<div id='dropdown_tab' style='display: inline-block'>dropdown
<ul id='dropdown_menu' style='display: none'>
<li>optoin 1</li>
<li>optoin 2</li>
<li id='option_3'>optoin 3
<ul id='dropdown_menu2' style='display: none'>
<li>second 1</li>
<li>second 2</li>
<li>second 3</li>
</ul>
</li>
</ul>
</div>
None of the existing answers provide the correct solution, unfortunately. They range from abusing the float property to totally restructuring your HTML, something which often isn't feasible.
The <ul> element has display: block; as its default display property, causing the width to fill 100% of its container.
To change this aspect and still retain all the other default properties of how a <ul> is displayed (e.g. avoid issues with float from other answers), apply display: inline-block; to the list:
ul {
display: inline-block;
background-color: green;
}
.highlight {
background-color: orange; /* for demonstration */
padding: 15px; /* for demonstration */
}
<ul>
<li>apple</li>
<li class="highlight">orange</li>
<li>pear</li>
<li>banana</li>
</ul>