I have a list i want to add to a <div>
. Each listitem contains a <div>
which in turn contain an image and a text string. The list must be vertical. I ve tried putting display:block
for the <ul>
with width:100%
but the list is flowing left to right horizontally. How do I make the list vertical?
Asked
Active
Viewed 2.6e+01k times
45

simeg
- 1,889
- 2
- 26
- 34

kavita deshpande
- 453
- 1
- 4
- 6
-
2Can you show us some code please? – Paul Jul 15 '11 at 05:58
4 Answers
60
Try putting display: block
in the <li>
tags instead of the <ul>
-
Thanks a lot! it is now a vertical list but the alignment is to the left. I want it to be at the centre – kavita deshpande Jul 15 '11 at 06:37
-
3(This is an old question, I know) There are two scenarios here: 1) if you want the _text alignment_ to be center, then use `text-align: center` on the `ul`; but if you want the list itself to be centered on the screen with the text still left aligned, then define a `width` or `max-width` property and add `margin-left: auto; margin-right: auto;` to it. – rpearce Apr 18 '16 at 08:26
22
I would add this to the LI's CSS
.list-item
{
float: left;
clear: left;
}

Joe
- 80,724
- 18
- 127
- 145
-
I have to remove the clear:left; and it works calm,any idea why ? – Prageeth godage Aug 28 '18 at 02:20
10
Hope this is your structure:
<ul>
<li>
<div ><img.. /><p>text</p></div>
</li>
<li>
<div ><img.. /><p>text</p></div>
</li>
<li>
<div ><img.. /><p>text</p></div>
</li>
</ul>
By default, it will be add one after another row:
-----
-----
-----
if you want to make it vertical, just add float left to li, give width and height, make sure that content will not break the width:
| | |
| | |
li
{
display:block;
float:left;
width:300px; /* adjust */
height:150px; /* adjust */
padding: 5px; /*adjust*/
}