How to get child UL to come outside parent UL - html

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

Related

Padding being ignored by UL element

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

css stretch li based on content

I have this code here and I am trying to make the ul.submenu li to stretch according to its contents. As you can see, the 3rd li of the ul.submenu has a long text which hides instead of stretching the li.
I have tried changing the display property of all elements on the DOM with various combinations but I cannot get it right.
What am I doing wrong and why this happens? What am I missing?
Any help will be very much appreciated! :)
Currently the text has little bearing on the layout, because of block display and absolute positioning.
You can change this by giving the lis display: inline-block and white-space: nowrap. I've forked an example where the sub-menu is as long as the longest item requires.
Explanation
inline-block gives the element properties of inline and block display: inline in that the element should flow like text, and take its initial layout and dimensions from the text it contains. But the block part means you can also specify top and bottom padding and margin, clears, etc. Even with this set, the containing element is still absolutely positioned (most text content just flows as long as it needs because normally the containing block element fills 100% width - not the case for absolute, relative and fixed elements), so its instinct is to collapse to the minimum width, that of the first word. But if we use white-space: nowrap, we can force the text to extend as much as it needs, so the full sentence is used as the measure.
You could just change the min-width to:
min-width: 240px;
View Example

Prevent space increasing between elements on hover

I have a sidebar in which there are certain li elements as an index, and on hover of each of the li elements, I have a specific image appearing 'over' the li elements (eg: position:relative;top:-25px;)
Let's say I hover over the first li element and the rollover images appears fine. However, the space between 1st and 2nd element increases while this hover is occuring. I am not able to understand why this is happening and I want to stop this from happening i.e. the image should appear over the li item without no spacing problem but only a simple rollover.
Here is a fiddle of the problem I am talking about: http://jsfiddle.net/PF35v/3/
I would use absolute positioning in this case, I usually do when dealing with images and top/side nav bars that are "glued" to one side of a screen. Alternatively, in situations in which I am set on using relative vs. absolute I use a little cheat....Here is what I changed in the above fiddle
ul#nav a:hover+img {
display: block;
position:relative;
top:-35px;
margin-bottom:-48px;
}
UPDATED FIDDLE
http://jsfiddle.net/PF35v/9/
However, if your images are all different sizes, you would need to individually set up the top and margin-bottom positioning.
adding "position:absolute;" to ul#nav a:hover#first_id+img is stopping the LIs being pushed down (tried this on Chrome). Did you try this?

Anchor in list elements not filling available space with display:block and height/width set to 100%

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/

ul based html menu with css spilling into multiple lines

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