So essentially I have a horizontal menu using ul and li elements styled with CSS which has a fixed height attribute for the ul but since the number of li elements are too many they are spilling over into multiple lines ...since the height of the ul is fixed, the li elements appear on the next line just fine but they are outside of the 'block' of the ul...so any further html content that appears starts showing inline with the li elments on the 2nd line?
I hope I have been able to describe the problem. I wish this was a publicly accessible site, for the CSS gurus to help with using firebug or web inspector.
use min-height on your UL, not height
use float:left on your LIs
use display:block on your A tags and put all other styling on the A tags. (DO NO STYLE THE LI TAGS OTHER THAN FLOAT:LEFT)
you can expand the width of the
container tag holding the ul, you do not have enough width for all the list elements
if you can not enlarge the container try to cut down the width of the li's, using less padding and margin in between them.
you can all so use a min-width property to bee sure that they will have enough space
Related
Just a forewarning, I am aware for the most part of how float works, and I understand that a div will not wrap floating objects. However, a came across a section of code on w3 schools and I'm a bit confused. Essentially, they use a ul and they float the li items, but the ul wraps to fit the height of the list items. If i were to do the same thing with a div, the div and the list items would not line up, I'm just curious as to why it works with the ul but not with div?
the code can be found here
https://www.w3schools.com/css/tryit.asp?filename=trycss_navbar_horizontal_black_right
The CSS for the ul in that example contains overflow: hidden;. This makes an element wrap floating child elements. There's no difference in that respect whether it's a ul or div.
I've enlarged the menu space, but still when I add a new item to the menu, it becomes like on the screenshot (vertical). I'm very new in html css. How should I fix that, to make them next to another horizontal?
To make list elements appear horizontally, you must add li{ display:inline-block; } to your css for the navigation. li elements are at default, block level elements which are displayed on a line for themselves, so to get them to behave and display beside each other, you must display the li elements as inline-block or inline. Inline-block would be better suited for your purposes for further styling of the li elements.
I'm having some real trouble with CSS here... it's very odd.
I have a UL element wrapped within a Nav tag. I'm trying to apply some padding to the individual links and for some reason the padding isn't moving the element down and expanding the container as a result.
Here's a screenshot of what's happening:
As you can see, the padding is being noticed by the browser, but it's just overlapping with the element above (which is being floated). I can't find a way to push it down, or at the very least make the container expand to hold it properly.
For reference, I'm using the Skeleton responsive boilerplate as a base.
Here's a link to it live: http://richardsonweb.co.uk/
Try display:inline-block; on your li elements
the behaviour problem explained in the title is understandable but I need a workaround.
I made an example in JSfiddle: http://jsfiddle.net/TBXr4/2/
See in the first LI I have a couple of words. They are not getting lined up like I need them to but they are getting listed. How do i resolved this?
Let me make this a little more specific, I don't want to set the width of the child UL manually, in fact I don't want one to be set. I need a way sothat the parent UL will have a width set whilst the child UL will be the smallest possible width to inherit the text.
You could just set the white-space property of the li element:
li {
/* other stuff */
white-space: nowrap;
}
JS Fiddle demo.
The problem with this is that while the text will be visible outside of the parent ul's assigned width, the style of the li (it's background-color / background-image) won't carry over.
References:
CSS white-space property.
Demo is here
i think you want this only.
The reason why the text is not displaying the sentence on one line is because you have set the width of the li, remove style="width:35px".
Why are you specifying a width to the exact element (UL) where you do not wish to adhere to it?
Apply the width setting to the main list and assign a new width to the sub-list as shown in this jsfiddle example
In the fiddle below i would like to the anchor elements to occupy all of the aviailable space of their parent li elements:
http://jsfiddle.net/nmxmT/
Can't see what i have done wrong :(
Put the padding on the a instead of the li and take the width off of the a.
http://jsfiddle.net/Gb38x/