I want to remove all indentation from ul. I tried setting margin, padding, text-indent to 0, but no avail. Seems that setting text-indent to a negative number does the trick - but is that really the only way to remove the indentation?
Set the list style and left padding to nothing.
ul {
list-style: none;
padding-left: 0;
}
ul {
list-style: none;
padding-left: 0;
}
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
To maintain the bullets you can replace the list-style: none with list-style-position: inside or the shorthand list-style: inside:
ul {
list-style-position: inside;
padding-left: 0;
}
ul {
list-style-position: inside;
padding-left: 0;
}
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
My preferred solution to remove <ul> indentation is a simple CSS one-liner:
ul { padding-left: 1.2em; }
<p>A leading line of paragraph text</p>
<ul>
<li>Bullet points align with paragraph text above.</li>
<li>Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. </li>
<li>List item 3</li>
</ul>
<p>A trailing line of paragraph text</p>
This solution is not only lightweight, but has multiple advantages:
It nicely left-aligns <ul>'s bullet points to surrounding normal paragraph text (= indenting of <ul> removed).
The text blocks within the <li> elements remain correctly indented if they wrap around into multiple lines.
Legacy info:
For IE versions 8 and below you must use margin-left instead:
ul { margin-left: 1.2em; }
Add this to your CSS:
ul { list-style-position: inside; }
This will place the li elements in the same indent as other paragraphs and text.
Ref: http://www.w3schools.com/cssref/pr_list-style-position.asp
display:table-row; will also get rid of the indentation but will remove the bullets.
Remove the padding:
padding-left: 0;
Can you provide a link ?
thanks
I can take a look
Most likely your css selector isnt strong enough or can you try
padding:0!important;
Live demo: https://jsfiddle.net/h8uxmoj4/
ol, ul {
padding-left: 0;
}
li {
list-style: none;
padding-left: 1.25rem;
position: relative;
}
li::before {
left: 0;
position: absolute;
}
ol {
counter-reset: counter;
}
ol li::before {
content: counter(counter) ".";
counter-increment: counter;
}
ul li::before {
content: "●";
}
Since the original question is unclear about its requirements, I attempted to solve this problem within the guidelines set by other answers. In particular:
Align list bullets with outside paragraph text
Align multiple lines within the same list item
I also wanted a solution that didn't rely on browsers agreeing on how much padding to use. I've added an ordered list for completeness.
I have the same problem with a footer I'm trying to divide up. I found that this worked for me by trying few of above suggestions combined:
footer div ul {
list-style-position: inside;
padding-left: 0;
}
This seems to keep it to the left under my h1 and the bullet points inside the div rather than outside to the left.
Doing this inline, I set the margin to 0 (ul style="margin:0px"). The bullets align with paragraph with no overhang.
The following worked for me.
In Chrome, Edge and Firefox (which needs special treatment).
Bullets are kept and are on the same line with surrounding paragraphs.
ul {
padding-left: 0;
margin-left: 17px;
}
/* Different value for Firefox */
#-moz-document url-prefix() {
ul {
margin-left: 14px;
}
}
Related
Assume the following list:
<div class="menublock">
<ul class="menu">
<li>Home</li>
<li>Google</li>
<li>Porn Hub</li>
<li>Toronto Star</li>
<li>Stack Overflow</li>
<li>Example Site</li>
<li>York University</li>
</ul>
</div>
with the following CSS
.menublock .menu {
margin-top: 35px;}
.menublock .menu li {
display: inline;
list-style-type: none;
padding-right: 20px;
}
.menublock .menu li a {
font-size: 16pt;
}
How do I stop the list from wrapping in the middle of a list item?
That is, I want it to line break between "Toronto Star" and "Stack Overflow" (if necessary), but not between "Stack" and "Overflow"
Line Breaks should be responsive to actual screen width, not force using child-after selectors or other such fixed points.
Make the a tag display as inline-block
.menublock .menu li a {
font-size: 16pt;
display:inline-block;
}
Instead of having every list item display as "inline", have them display as "block" and have them float "left".
This will prevent breaking of text inside of each item.
I tend to make horizontal navbars this way because it eliminates issues like these as well as awkward spacing issues that result from inline elements when they are next to each other.
Edit: floating an element automatically makes it display as "block", so just eliminate "display: inline" and have your list items float left.
.menublock .menu li a {
font-size: 16pt;
white-space:nowrap;
}
I want to remove all indentation from ul. I tried setting margin, padding, text-indent to 0, but no avail. Seems that setting text-indent to a negative number does the trick - but is that really the only way to remove the indentation?
Set the list style and left padding to nothing.
ul {
list-style: none;
padding-left: 0;
}
ul {
list-style: none;
padding-left: 0;
}
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
To maintain the bullets you can replace the list-style: none with list-style-position: inside or the shorthand list-style: inside:
ul {
list-style-position: inside;
padding-left: 0;
}
ul {
list-style-position: inside;
padding-left: 0;
}
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
My preferred solution to remove <ul> indentation is a simple CSS one-liner:
ul { padding-left: 1.2em; }
<p>A leading line of paragraph text</p>
<ul>
<li>Bullet points align with paragraph text above.</li>
<li>Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. </li>
<li>List item 3</li>
</ul>
<p>A trailing line of paragraph text</p>
This solution is not only lightweight, but has multiple advantages:
It nicely left-aligns <ul>'s bullet points to surrounding normal paragraph text (= indenting of <ul> removed).
The text blocks within the <li> elements remain correctly indented if they wrap around into multiple lines.
Legacy info:
For IE versions 8 and below you must use margin-left instead:
ul { margin-left: 1.2em; }
Add this to your CSS:
ul { list-style-position: inside; }
This will place the li elements in the same indent as other paragraphs and text.
Ref: http://www.w3schools.com/cssref/pr_list-style-position.asp
display:table-row; will also get rid of the indentation but will remove the bullets.
Remove the padding:
padding-left: 0;
Can you provide a link ?
thanks
I can take a look
Most likely your css selector isnt strong enough or can you try
padding:0!important;
Live demo: https://jsfiddle.net/h8uxmoj4/
ol, ul {
padding-left: 0;
}
li {
list-style: none;
padding-left: 1.25rem;
position: relative;
}
li::before {
left: 0;
position: absolute;
}
ol {
counter-reset: counter;
}
ol li::before {
content: counter(counter) ".";
counter-increment: counter;
}
ul li::before {
content: "●";
}
Since the original question is unclear about its requirements, I attempted to solve this problem within the guidelines set by other answers. In particular:
Align list bullets with outside paragraph text
Align multiple lines within the same list item
I also wanted a solution that didn't rely on browsers agreeing on how much padding to use. I've added an ordered list for completeness.
I have the same problem with a footer I'm trying to divide up. I found that this worked for me by trying few of above suggestions combined:
footer div ul {
list-style-position: inside;
padding-left: 0;
}
This seems to keep it to the left under my h1 and the bullet points inside the div rather than outside to the left.
Doing this inline, I set the margin to 0 (ul style="margin:0px"). The bullets align with paragraph with no overhang.
The following worked for me.
In Chrome, Edge and Firefox (which needs special treatment).
Bullets are kept and are on the same line with surrounding paragraphs.
ul {
padding-left: 0;
margin-left: 17px;
}
/* Different value for Firefox */
#-moz-document url-prefix() {
ul {
margin-left: 14px;
}
}
I'm having some problems with my ul-list after using applying CSS-reset.
When the text in the li is long and it breaks to a second line, the text begins under the bullet. I'd like it to start with the same margin/padding as the text on the right side of the bullet.
Sort of hard to explain, but if you look at the example-image. The left-image is the list today. "motta varsel [...]" begins under the bullet, but I'd like it to look the picture on the right.
How can I do this with CSS? I assume there is something very simple I've overlooked, but I can't figure out what. Google searches did not return anything useful either.
The li tag has a property called list-style-position. This makes your bullets inside or outside the list. On default, it’s set to inside. That makes your text wrap around it. If you set it to outside, the text of your li tags will be aligned.
The downside of that is that your bullets won't be aligned with the text outside the ul. If you want to align it with the other text you can use a margin.
ul li {
/*
* We want the bullets outside of the list,
* so the text is aligned. Now the actual bullet
* is outside of the list’s container
*/
list-style-position: outside;
/*
* Because the bullet is outside of the list’s
* container, indent the list entirely
*/
margin-left: 1em;
}
Edit 15th of March, 2014
Seeing people are still coming in from Google, I felt like the original answer could use some improvement
Changed the code block to provide just the solution
Changed the indentation unit to em’s
Each property is applied to the ul element
Good comments :)
Here is a good example -
ul li{
list-style-type: disc;
list-style-position: inside;
padding: 10px 0 10px 20px;
text-indent: -1em;
}
Working Demo: http://jsfiddle.net/d9VNk/
I second Dipaks' answer, but often just the text-indent is enough as you may/maynot be positioning the ul for better layout control.
ul li{
text-indent: -1em;
}
I would set the fish in a :before style in css. Also you have a spelling mistake in your HTML. It should be <ul>. Font Awesome should give you the code to put into content.
li {
padding: 0% 0% 5% 3%;
width: 100%;
list-style-position: outside;
position: relative;
}
li:before {
content: '';
position: absolute;
width: 5px;
height: 5px;
background: black;
top: 10px;
left: -5px;
}
<div class="col">
<ul>
<p class="col align-self-center">
<li>5% marketing and strategic alliances</li>
<li>10% Metadata release (Rarity tools) Focus on community growth</li>
<li>25% Listing in Magic Eden</li>
<li>50% First Donation to partners</li>
<li>65% Increase in marketing investment</li>
<li>80% Bluepaper Publication of Phase 2</li>
<li>100% Second Donation to partners</li>
</p>
</ul>
</div>
</div>
This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 8 years ago.
Possible Duplicate:
Unwanted margin in inline-block list items
How to remove “Invisible space” from HTML
Why do the inline-block list items have a space in them? No matter how I make my list items into a menu, I always get spaces.
li {
border: 1px solid black;
display: inline-block;
height: 25px;
list-style-type: none;
text-align: center;
width: 50px;
}
ul {
padding: 0;
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
I have seen this and answered on it before:
After further research I have
discovered that inline-block is a
whitespace dependent method and
is dependent on the font setting. In this case 4px is rendered.
To avoid this you could run all your
lis together in one line, or block
the end tags and begin tags together
like this:
<ul>
<li>
<div>first</div>
</li><li>
<div>first</div>
</li><li>
<div>first</div>
</li><li>
<div>first</div>
</li>
</ul>
Example here.
As mentioned by other answers and comments, the best practice for solving this is to add font-size: 0; to the parent element:
ul {
font-size: 0;
}
ul li {
font-size: 14px;
display: inline-block;
}
This is better for HTML readability (avoiding running the tags together etc). The spacing effect is because of the font's spacing setting, so you must reset it for the inlined elements and set it again for the content within.
Solution:
ul {
font-size: 0;
}
ul li {
font-size: 14px;
display: inline-block;
}
You must set parent font size to 0
I would add the CSS property of float left as seen below. That gets rid of the extra space.
ul li {
float:left;
}
Actually, this is not specific to display:inline-block, but also applies to display:inline. Thus, in addition to David Horák's solution, this also works:
ul {
font-size: 0;
}
ul li {
font-size: 14px;
display: inline;
}
Another solution, similar to Gerbus' solution, but this also works with relative font sizing.
ul {
letter-spacing: -1em; /* Effectively collapses white-space */
}
ul li {
display: inline;
letter-spacing: normal; /* Reset letter-spacing to normal value */
}
I had the same problem, when I used a inline-block on my menu I had the space between each "li" I found a simple solution, I don't remember where I found it, anyway here is what I did.
<li>Home</li><!---->
<li>News</li><!---->
<li>About Us</li><!---->
<li>Contact Us</li>
You add a comment sign between each end of, and start of : "li"
Then the horizontal space disappear.
Hope that answer to the question
Thanks
Even if its not inline-block based, this solution might worth consideration (allows nearly same formatting control from upper levels).
ul {
display: table;
}
ul li {
display: table-cell;
}
IE8+ & major browsers compatible
Relative/fixed font-size independent
HTML code formatting independent (no need to glue </li><li>)
just remove the breaks between li's in your html code...
make the li's in one line only..
I need to use, for example, the star-symbol(★) as the bullet for a list-item.
I have read the CSS3 module: Lists, that describes, how to use custom text as bullets, but it's not working for me. I think, the browsers simply don't support the ::marker pseudo element.
How can I do it, without using images?
Using Text As Bullets
Use li:before with an escaped Hex HTML Entity (or any plain text).
Example
My example will produce lists with check marks as bullets.
ul {
list-style: none;
padding: 0px;
}
ul li:before
{
content: '\2713';
margin: 0 1em; /* any design */
}
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
Browser Compatibility
Haven't tested myself, but it should be supported as of IE8.
At least that's what quirksmode & css-tricks say.
You can use conditional comments to apply older/slower solutions like images, or scripts. Better yet, use both with <noscript> for the images.
HTML:
<!--[if lt IE 8]>
*SCRIPT SOLUTION*
<noscript>
*IMAGE SOLUTION*
</noscript>
<![endif]-->
About background images
Background images are indeed easy to handle, but...
Browser support for background-size is actually only as of IE9.
HTML text colors and special (crazy) fonts can do a lot, with less HTTP requests.
A script solution can just inject the HTML Entity, and let the same CSS do the work.
A good resetting CSS code might make list-style (the more logical choice) easier.
Enjoy.
EDIT
I probably wouldn't recommend using images anymore. I'd stick to the approach of using a Unicode character, like this:
li:before {
content: "\2605";
}
OLD ANSWER
I'd probably go for an image background, they're much more efficient versatile and cross-browser-friendly.
Here's an example:
<style type="text/css">
ul {list-style:none;} /* you should use a css reset too... ;) */
ul li {background:url(images/icon_star.gif) no-repeat 0 5px;}
</style>
<ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
This is the W3C solution. You can use it in 3012!
ul { list-style-type: "*"; }
/* Sets the marker to a "star" character */
https://drafts.csswg.org/css-lists/#text-markers
Update: according to the comments this works in all modern browsers in 2021.
You can construct it:
#modal-select-your-position li {
/* handle multiline */
overflow: visible;
padding-left: 17px;
position: relative;
}
#modal-select-your-position li:before {
/* your own marker in content */
content: "—";
left: 0;
position: absolute;
}
<ul id="modal-select-your-position">
<li>First item</li>
<li>Second item</li>
</ul>
Images are not recommended since they may appear pixelated on some devices (Apple devices with Retina display) or when zoomed in. With a character, your list looks awesome everytime.
Here is the best solution I've found so far. It works great and it's cross-browser (IE 8+).
ul {
list-style: none;
padding-left: 1.2em;
text-indent: -1.2em;
}
li:before {
content: "►";
display: block;
float: left;
width: 1.2em;
color: #ff0000;
}
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
The important thing is to have the character in a floating block with a fixed width so that the text remains aligned if it's too long to fit on a single line.
1.2em is the width you want for your character, change it for your needs.
Don't forget to reset padding and margin for ul and li elements.
EDIT: Be aware that the "1.2em" size may vary if you use a different font in ul and li:before. It's safer to use pixels.
To add a star use the Unicode character 22C6.
I added a space to make a little gap between the li and the star. The code for space is A0.
li:before {
content: '\22C6\A0';
}
Today, there is a ::marker option. so,
li::marker {
content: "\2605";
}
A more complete example of 222's answer:
ul {
list-style:none;
padding: 0 0 0 2em; /* padding includes space for character and its margin */
/* IE7 and lower use default */
*list-style: disc;
*padding: 0 0 0 1em;
}
ul li:before {
content: '\25BA';
font-family: "Courier New", courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace;
margin: 0 1em 0 -1em; /* right margin defines spacing between bullet and text. negative left margin pushes back to the edge of the parent <ul> */
/* IE7 and lower use default */
*content: none;
*margin: 0;
}
ul li {
text-indent: -1em; /* negative text indent brings first line back inline with the others */
/* IE7 and lower use default */
*text-indent: 0;
}
I have included star-hack properties to restore the default list styles in older IE versions. You could pull these out and include them in a conditional include if desired, or replace with a background-image based solution. My humble opinion is that special bullet styles implemented in this manner should degrade gracefully on the few browsers that don't support pseudoselectors.
Tested in Firefox, Chrome, Safari and IE8-10 and renders correctly in all.
ul {
list-style-type: none;
}
ul li:before {
content:'*'; /* Change this to unicode as needed*/
width: 1em !important;
margin-left: -1em;
display: inline-block;
}
I've been through this whole list and there are partially correct and partially incorrect elements right through, as of 2020.
I found that the indent and offset was the biggest problem when using UTF-8, so I'm posting this as a 2020 compatible CSS solution using the "upright triangle" bullet as my example.
ul {
list-style: none;
text-indent: -2em; // needs to be 1 + ( 2 x margin), and the result 'negative'
}
ul li:before {
content: "\25B2";
margin: 0 0.5em; // 0.5 x 2 = 1, + 1 offset to get the bullet back in the right spot
}
use em as the unit to avoid conflict with font sizing
As mentioned in these two comments, the modern approach is to use list-style-type or ::marker. You can also combine them depending on your use case.
One of the more notable setbacks with these methods is that you can't yet apply margin or padding to ::marker, and instead must rely on whitespace (as illustrated in the examples here) or use an offset method as outlined in the demo provided in 2.1 below.
1. Using list-style-type to set a custom marker
li { list-style-type: "🔧 "; }
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
2. Using ::marker to style list-style-type
/* intentional whitespace, may vary cross-browser */
li { list-style-type: "★ "; }
li::marker { color: red; }
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
2.1 Spacing
While it's not immediately apparent in the demo above, the marker is moving away from the list as opposed to pushing itself into it. This means that it may fall outside of your grid and/or may become obscured by another element.
I've created a demo on Codepen that highlights the whitespace issue alongside two potential solutions depending on if you need to match the default ul styling or create something that's inside the parent container.
3. Using ::marker exclusively for variants:
li.one::marker { content: "🥇 "; }
li.two::marker { content: "🥈 "; }
li.three::marker { content: "🥉 "; }
<ul>
<li class="one">1</li>
<li class="two">2</li>
<li class="three">3</li>
</ul>
Additional Resources:
"List Markers and String Styles" by Eric Meyer on CSS Tricks [2021]
Can I Use list-style-type <string> (vs. list-style-type)
Can I Use ::marker
Try this code...
li:before {
content: "→ "; /* caractère UTF-8 */
}
To expand on the top answer, and address the issues brought up regarding the overflowing lines not indenting properly, you could make the list items padding-left 20px (for example) and the position relative. Then in the li:before, set the position to absolute and left -20px;
Example:
ul {
list-style: none;
padding: 0 0 0 20px;
}
ul li {
position: relative;
}
ul li:before {
content: '\2713';
position: absolute;
top: 0;
left: -20px; // or whatever your padding-left is on the ul
font-size: inherit;
line-height: inherit;
}
I would have written this as a comment on the answer, but don't have enough points to post a comment, but hopefully this can help someone having this issue.
This topic may be old, but here's a quick fix
ul {list-style:outside none square;} or
ul {list-style:outside none disc;} , etc...
then add left padding to list element
ul li{line-height: 1.4;padding-bottom: 6px;}