Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove horizontal spacing in <ul> with list-style-type:none

Tags:

html

css

On http://www.w3schools.com/cssref/playit.asp?filename=playcss_ol_list-style-type&preval=none, a nice overview is provided for the different list-style-type values.

However, for the value none, it still reserves some horizontal space for the empty list symbol. Is there a way to remove this horizontal spacing, so that the text actually moves to the left as if it was no list? I would like to use text-align:center on the list items, and this horizontal spacing makes them not really centered. And I need to use <ul> because the CMS brings it in that way.

Basically, by default list-style-type:none does a visibility:hidden on the bullets, while I would like to achieve display:none on the bullets instead. What would be the proper way to do this?

like image 488
user1111929 Avatar asked Feb 28 '13 03:02

user1111929


People also ask

How do I remove spaces in UL?

The padding-left:0 is used to remove indentation (space) from left. The list-style: none property is used to remove list-style property from the list of items.

How do I reduce horizontal space between Li in HTML?

The spacing between list items in an orderedlist or itemizedlist element can be minimized by the document author by adding a spacing="compact" attribute to the list element. In HTML output, the list will get a compact="compact" attribute on the list start tag to reduce spacing in the browser.

How do I remove a style from a UL tag?

Adding the "list-style: none" CSS class to the unordered list (<ul>) or ordered list (<ol>) tag removes any bullet or number.


2 Answers

It's the browsers default styling that's adding that space, just use a CSS reset to reset all of the browsers default styles. Most block elements have some default margin/padding .. even the <body> element has 8px of margin applied to it by default.

Here is a link to Eric Meyer's reset: http://meyerweb.com/eric/tools/css/reset/

Just to see for yourself, add:

ol {
margin: 0;
padding: 0;
}
/* This would be declared in the above reset */
like image 158
Adrift Avatar answered Nov 05 '22 07:11

Adrift


Make sure to add browser reset styles before you start working with CSS.

You have to add this:

ol, li {
  margin: 0px;
  padding: 0px;
}

for this question.

like image 23
madhushankarox Avatar answered Nov 05 '22 06:11

madhushankarox