I am trying to use unordered lists as columns something setup like the following:
<ul>
<li>word 1</li>
<li>word 1</li>
<li>word 1</li>
<li>word 1</li>
<li>word 1</li>
</ul>
<ul>
<li>word 2</li>
<li>word 2</li>
<li>word 2</li>
<li>word 2</li>
<li>word 2</li>
</ul>
What would I need to do as far as css these to lineup side by side as vertical lists with no bullets. I'm sure I'm missing something simple but I can't seem to figure it out. I specifically need this to work in IE7.
Thanks in advance,
Ben
Here's the really short answer:
ul {
float: left;
list-style-type: none;
}
Here's the slightly longer explanation:
The float part tells your lists to move together "on the same line". You might want to add a width property to the ul elements as well, in order to get equally distributed columns.
The list-style-type property simply turns off your bullets. Most likely, you will now have empty space where the bullets used to be. This can be removed by overriding maring and padding - eg. set them both to zero.
You might also want to add a clear: left property on whatever element is following the lists.
<div class="wrapper">
<ul>
<li>word 1</li>
<li>word 1</li>
<li>word 1</li>
<li>word 1</li>
<li>word 1</li>
</ul>
<ul>
<li>word 2</li>
<li>word 2</li>
<li>word 2</li>
<li>word 2</li>
<li>word 2</li>
</ul>
<div class="clear"></div>
</div>
<style type="text/css">
ul {width: 40%; float: left;list-style-type: none;}
ul li {list-style-type: none;}
.clear {clear:both;font-size:0px;line-height:0px;height:0px;}
</style>
Something along those lines... keep in mind that this will look quite a bit more "standard" between browsers if you have a decent CSS reset block. I recommend Blueprint.
Here's an example:
<div id="menucontainer">
<ul>
<li>w1</li>
<li>w2</li>
</ul>
</div>
Css:
#menucontainer ul {
list-style-type: none;
}
#menucontainer ul li {
display: inline;
padding: 0.1em;
}
Related
This is a mock up of a menu i have
HTML
Menu 1 (overflow:hidden)
<div class='menu'>
<ul>
<li>
Item 1
<ul>
<li>submenu 1</li>
<li>submenu 2</li>
<li>submenu 3</li>
<li>submenu 4</li>
<li>submenu 5</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
<br/><br/>
Menu 2 (overflow:hidden; overflow-y visible)
<div class='menu menu2'>
<ul>
<li>
Item 1
<ul>
<li>submenu 1</li>
<li>submenu 2</li>
<li>submenu 3</li>
<li>submenu 4</li>
<li>submenu 5</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
<br/><br/>
Menu 3 (overflow-x:hidden;)
<div class='menu3'>
<ul>
<li>
Item 1
<ul>
<li>submenu 1</li>
<li>submenu 2</li>
<li>submenu 3</li>
<li>submenu 4</li>
<li>submenu 5</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
<br/><br/>
Menu 4 (overflow:visible;)
<div class='menu menu4'>
<ul>
<li>
Item 1
<ul>
<li>submenu 1</li>
<li>submenu 2</li>
<li>submenu 3</li>
<li>submenu 4</li>
<li>submenu 5</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
CSS
.menu {border:1px solid #000000; overflow:hidden;}
.menu ul {list-style:none; margin:5px 5px; padding:0; position:relative}
.menu li {display:inline-block}
.menu li::after {content: " | ";}
.menu ul ul {position:absolute}
.menu ul ul li {display:block;}
.menu2 {overflow-y:visible}
.menu4 {overflow:visible}
.menu3 {border:1px solid #FF0000;overflow-x:hidden}
.menu3 ul {list-style:none; margin:5px 5px; padding:0; position:relative}
.menu3 li {display:inline-block}
.menu3 li::after {content: " | ";}
.menu3 ul ul {position:absolute}
.menu3 ul ul li {display:block;}
Fiddle
Now the idea is that menu item 1 has a sub menu which is triggered to appear via javascript and the submenu is supposed to go outside the box. because this menu is supposed to be responsive i assume the overflow was set in the template for a reason and i want to avoid altering the template as much as i can.
Now as you can see with the code the submenu in Menu 1 is hidden in the box, when i go to override the overflow-y property in Menu 2 to be it's default value (which is the same as overflow's) it's still hidden and there's a scroll box.
now just in case if there was something weird in overflow is still set for the y axis i went and copied the menu class for Menu 3 but instead of doing overflow:hidden i just did overflow-x:hidden; but that still have be a scrollbar. Menu 4 shows how if overflow is set to visible (the default value) i have no scroll bar and my submenu goes out of the box as it should.
My question is why doesn't overflow-y:visible look the same as overflow:visible? to my understanding, overflow:visible is just overflow-x:visible; overflow-y:visible much like how border:1px solid #000000 is the same as setting all the border sides's width, style and color one by one
overflow-x and overflow-y are part of CSS3 (while plain overflow is CSS2), and are still somewhat experimental. The rules for what happens when one value is a "scrolling value" (which includes hidden) and the other is visible are complex, and frankly confusing.
From the CSS3 Overflow Spec:
... if one cascaded values [sic] is one of the scrolling values and the other is ‘visible’, then computed values are the cascaded values with ‘visible’ changed to ‘hidden’.
This seems to justify the behavior you're seeing, but I don't understand why it was designed that way.
overflow: visible;
does not clip content and can be shown out side of content box but for
overflow-y; visible;
content clipped against content box with overflow auto default
I made a revised fiddle but the main issue I found is that the style for .menu was applied to all four menus and that part of its definition was overflow: hiddden, so you were basically getting a conflict with Menu 2. Deleting overflow: hidden from .menu in the first line of your CSS makes both Menu 2 and Menu 4 have the same behavior as you were expecting.
i have got a nested list, which is positioned under the parent list:
<ul>
<li> Item 1 </li>
<ul>
<li> Subitem 1 </li>
<li> Subitem 2 </li>
<li> Subitem 3 </li>
</ul>
</ul>
Is there any way to style them with css so that the nested list is right and centered to the parent list? The result should look like this:
- Subitem 1
Item 1 - Subitem 2
- Subitem 3
Best regards
You can try a tabular approach:
.list {
display: table;
}
.list > li, .list > ul {
display: table-cell;
vertical-align: middle;
}
<ul class="list">
<li>Item 1</li>
<ul>
<li>Subitem 1</li>
<li>Subitem 2</li>
<li>Subitem 3</li>
</ul>
</ul>
However, note that the HTML above is invalid, because the inner ul should be a child of li.
With a correct layout, I would use an inline-block approach:
.list > li > ul {
display: inline-block;
vertical-align: middle;
}
<ul class="list">
<li>Item 1
<ul>
<li>Subitem 1</li>
<li>Subitem 2</li>
<li>Subitem 3</li>
</ul>
</li>
</ul>
I am having trouble arranging the text inside a div tag in dreamweaver. I have tag for the main body of my page and I want to place the text freely; wherever I want, but dreamweaver is not allowing me to do so. When I click tab inside the div it does not work. No matter what I do I give a single space between my words. For example I want to arrange my text in the following way:
Please click on items for detail:
Item_one Item_two Item_three Item_four Item_five
Item_six Item_seven Item_eight Item_nine Itme_ten
Thanks
What you are looking for, might look similar to this:
<div>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<br />
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
</ul>
</div>
This is the CSS:
ul li {
list-style: none;
display: inline-block;
}
It is not recommended to use a div for every element that you are creating. It is easier to use unordered lists and style them according to what your project requires.
Hope it helps!
The easiest way to achieve this would be to use display: inline-block for every item.
Like this:
<div style="width: 100%">
<div style="display: inline-block">Item_one</div>
<div style="display: inline-block">Item_two</div>
</div>
<div style="width: 100%">
<div style="display: inline-block">Item_four</div>
<div style="display: inline-block">Item_six</div>
</div>
etc. Please do note that it'll only work if there's enough space for the div to display itself in a line; otherwise, you won't see any effect.
Hope this helps.
how to float third child menu to left?
i want to float 3rd child menu to left like the main menu "item1"
html
<nav id="nav">
<ul>
<li>Item1
<ul>
<li>Menu 1</li>
<li>Menu 1</li>
<li>Menu 1</li>
<li>Menu 1
<ul class"right-menu">
<li>Menu 2</li>
<li>Menu 2</li>
<li>Menu 2</li>
<li>Menu 2</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
You can target the 3rd child in CSS using the :nth-child syntax.
CSS
#nav ul li ul li:nth-child(3)
However if you want something that will be supported in all browsers I tend to use the adjacent sibling selector or "+".
In your example the css would be:
#nav ul li ul li + li + li {
float:left;
}
Although i would recommend using some classes so that you can reduce the huge number of selectors requires to do this.
Concider the following fiddle: http://jsfiddle.net/dts2T/
This has been bugging me for quite some time now. The Javascript in this fiddle should be redundant. But I've ripped my hair out googling this: How can I do the same using ONLY CSS?
The problem lies in the fact that any of the three columns could potentially contain more than one child. First I need to stretch each .column container to the height of the #bottom div. Then I need to stretch the height of the last element in each .column, so that it fills the remaining space of it's container. But HOW?
And before any of you suggests Faux columns or any other crappy solution to fake column stretching, thank you, but such solutions won't apply to this problem at all. The design I'm implementing suggests gradients on columns and rounded corners, which will make faux columns not applicable. It is the easiest thing in the world to stretch things horizontally, why can' it be equally easy to stretch them vertically?! Aargh!!
I would really appreciate any help from you brilliant guys out there. Any suggestion would be fine. I would even appreciate a good discussion on faking vertical stretching, if it is constructive.
Thank you.
This is a headbanging issue a lot of people run into at one time or another.
You can set the section to display: table; and columns to display: table-cell;. Even border radius and whatever fancy stuff works on it.
Here is a working demo: http://jsfiddle.net/MadLittleMods/QykYu/
Also here is the HTML and CSS:
CSS:
.container
{
display: table;
width: 100%;
border: 2px solid #000000;
}
.column
{
display: table-cell;
border: 1px solid #ff0000;
border-radius: 10px;
}
HTML:
<section class="container">
<div class="column">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
<div class="column">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
</ul>
</div>
<div class="column">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
<li>Item 11</li>
<li>Item 12</li>
<li>Item 13</li>
<li>Item 14</li>
</ul>
</div>
</section>