Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce Gap between HTML <UL> and <LI> elements

Tags:

html

css

xhtml

I have below HTML in my web page:

Forum
<ul>
<li> Stack</li>
<li> OverFlow</li>
</ul>

And as you could see below, I get the items listed perfectly, but there is a fixed gap between <UL> and <LI> elements.

HTML Output

Is there a way, I can reduce this gap? i.e. gap between "Forum" and "Stack" text in attached screen?

like image 263
Vicky Avatar asked Mar 16 '11 07:03

Vicky


3 Answers

The gap does not exist between UL and LI elements, but between the Forum text and the UL element. Most browsers define a default margin around certain elements, like the UL.

You get rid of it with CSS:

ul { margin: 0; }

or if you just want to reduce it, for example this one will set 0 margin for horizontal, 5px for vertical:

ul { margin: 5px 0; }
like image 110
kapa Avatar answered Oct 05 '22 04:10

kapa


Try this (don't know if it's the problem with you):

<ul><li>
your first li element </li><li>
your second li element</li>
</ul>

There are spaces that you can't avoid on HTML code if you don't "avoid" it, let's say. Take a look here.

like image 40
Sonhja Avatar answered Oct 05 '22 03:10

Sonhja


In addition to kapa's comment, if you enter a negative value for the margin it will reduce the gap.

In css:

ul { margin:-20px;}
like image 38
Andrew Avatar answered Oct 05 '22 05:10

Andrew