Spacing between two <li> elements - html

I've written the folloning code:
<ul>
<li>Text</li>
<li>text</li>
</ul>
and styles:
list-style-type: none;
padding: 5px;
display: inline;
background-color: #A9A9A9;
But i have spacing between two li elements like the following:
How can I remove this spacing?

By put them inline
<ul>
<li>Text</li><li>text</li>
</ul>
Js Fiddle Demo

If you float your li items, it should remove the margin between li output.
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
ul {
list-style-type: none;
}
ul li {
float:left;
padding: 5px;
display: block;
background-color: #A9A9A9;
}

Here are two common ways to avoid the space:
<ul>
<li>
one</li><li> <!-- use this to avoid the linebreak -->
two</li><li>
three</li>
</ul>
Or you can use Comments:
<ul>
<li>one</li><!--
--><li>two</li><!-- Comments so there is no white-space
--><li>three</li>
</ul>
You can check it in this Demo
You get the space because there is some space between the elements.
(Tabs, Newline count as space ). With this Minimized HTML it should work :)
You can read more about it here Examples at CSS-Tricks

try floats and use list-style-type for ul:
ul {
list-style-type: none;
}
li {
padding: 5px;
float:left;
background-color: #A9A9A9;
}

Just Add float:left in your Css
ul li {
background-color: #A9A9A9;
display: inline;
float: left;
padding: 5px;
}
Demo

There are many ways as mentioned above few of them..however you can achieve with another method. using font-size:0
ul
{font-size:0; /*This will remove the space totally*/
list-style-type: none;
}
li{
padding: 5px;
display: inline;
background-color: #A9A9A9;
font-size:16px; /*This is important line so the font come again in same shape*/
}
Here is the Demo.

Related

text in <span> is not inheriting styles from class

I wonder if someone can help me or point me in the right direction so I can resolve my problem.
I have a list which has got class assigned
<ul class="link-list nav">
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
The link-list nav looks as below:
.link-list {
display: inline-block;
list-style: none;
margin: 0;
padding: 0;
font-size: 12px;
}
.link-list > li {
display: inline-block;
}
.link-list > li > a {
display: block;
padding: .9em 1.6em;
/*margin: top right bottom left;
border: 1px solid white;*/
text-decoration: none;
color: white;
}
.link-list > li > a:hover { /* :hover, :focus, :blur */
color: pink;
}
.link-list.nav > li > a {
font-weight: bold;
}
So now the list is being formatted as it should be
Correct colors:
but when I am trying to make the first item of the list bigger by embedding span tags and changing above code to:
<ul class="link-list nav">
<li><span style="font-size: large">Menu 1</span></li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
The font become bigger but also all other formatting disappear
Incorrect colors:
I have been experimenting with defining another class which would inherit from link-list nav but unsuccessfully. Any suggestions please?
Thanks in advance,
Regards Tom.
you can put the span as child of a given your CSS (you are using the direct child selector >).
or
you can just use CSS selector first-child in li
or
or simply removing the >, making it a child (not direct one).
.link-list {
display: inline-block;
list-style: none;
margin: 0;
padding: 0;
font-size: 12px;
}
.link-list > li {
display: inline-block;
}
.link-list > li > a {
display: block;
padding: .9em 1.6em;
/*margin: top right bottom left;
border: 1px solid white;*/
text-decoration: none;
color: red;
}
.link-list > li > a:hover {
/* :hover, :focus, :blur */
color: pink;
}
.link-list.nav > li > a {
font-weight: 700;
}
/* use this */
.link-list.nav > li > a span {
font-size: 20px
}
/* or use this */
.link-list.nav > li:first-child > a {
color: blue
}
<ul class="link-list nav">
<li><span>Menu 1</span>
</li>
<li>Menu 2
</li>
<li>Menu 3
</li>
<li>Menu 4
</li>
</ul>
The selectors no longer match because the <a> is no longer a child of the <li>.
Use a descendant combinator (a space) instead of a child combinator (a >).
Alternatively, put the span inside the innermost element so that it doesn't disrupt the child combinators.
Alternatively, and probably the best option, don't add an extra element at all. You want to style all the text there, so apply your CSS to the whole element.
Thank you Quentin and dippas for your swift responses.
Out of both solutions, I have gone for creating:
.link-list.nav > li > a span {
font-size: 20px
}
and changing
<li><span>Menu 1</span>
to
<li><span>Menu 1</span>
This resolved my problem completely.
Clearly I need to reach out to articles about inheriting.
Thanks again and take care guys!

How to remove the space between a unordered list and a div

I was wondering how to remove the vertical space between a unordered list and div. I know it's possible with using - margins, but I have a feeling that isn't really a clean method.
This is my code:
.menu {
list-style-type: none;
background-color: #660066;
}
.menu li {
display: inline;
padding-left: 40px;
padding-right: 40px;
}
.div {
width: 100%;
height: 500px;
background-color: #660066;
}
<nav>
<ul class="menu">
<li>Check 1</li>
<li>Check 2</li>
<li>Check 3</li>
<li>Check 4</li>
</ul>
</nav>
<article class="div">
In this case your ul simply has standard margin on top and bottom. margin: 0; solves this.
jsfiddle
ul{
margin: 0;
}
Always do a reset like shown below for both UL and LI. That way spaces will only be present when you apply them by yourself.
ol, ul {
margin: 0;
padding: 0;
}
Click here to see why it is important to set a reset.
You have to set up your position since you are going to move in close proximity to the original location your position will be relative from there you move can move it up or down , it should look like this
.div
position:relative;
bottom:30px;

Multiple ID selectors aren't working

So i have two Divs like this:
<div id="first_content">
<ul>
<li>This</li>
<li>text</li>
<li>should</li>
<li>be</li>
<li>displayed</li>
<li>in</li>
<li>one</li>
<li>line</li>
</ul>
</div>
<div id="second_content">
<ul>
<li>This</li>
<li>text</li>
<li>should</li>
<li>be</li>
<li>displayed</li>
<li>in</li>
<li>one</li>
<li>line</li>
</ul>
</div>
And CSS:
#first_content, #second_content ul {
list-style: none;
}
#first_content, #second_content ul li {
display: inline;
}
It doesn't work (at least on firefox 34). Style applies only to one ID.
When i remove one of these ID selectors, another one works fine.
I guess it should work? what's wrong?
try:
#first_content ul, #second_content ul {
list-style: none;
}
#first_content ul li, #second_content ul li {
display: inline;
}
if you are trying to select the ul's and li's of both containers you need to specify this with both selectors.
Basic CSS
.foo, .bar { ... }
are two separate selector chains. You have:
#first-content, #second_content ul
^--- applies to <div id="first-content">
^^^^^^^^^^--- applies to any <ul> inside <div id="second-content">
<div> tags do not have a list-style, so your first rule doesn't do anything for the first <div> set. For your other rule set, display-inline will apply to the parent div for first-content, and to the <li> tags in the second-content area.
Here is some css:
#navcontainer ul
{
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
}
#navcontainer ul li { display: inline; }
#navcontainer ul li a
{
text-decoration: none;
padding: .2em 1em;
color: #fff;
background-color: #036;
}
#navcontainer ul li a:hover
{
color: #fff;
background-color: #369;
}
And some HTML:
<div id="navcontainer">
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Cheese</li>
<li>Vegetables</li>
<li>Fruit</li>
</ul>
</div>
These should produce the desired effect. Source: http://css.maxdesign.com.au/listutorial/horizontal_master.htm
Multiple id concatenation has never worked in Firefox. For example, I am using 67.0 (64-bit) and the following CSS works as intended:
#noDisplay {
display: none;
}
#togForm {
display: none;
}
...but if I concatenate that, as shown below, it does not work (one id working, the other not working), and this has always been the case.
#noDisplay,#togForm {
display: none;
}
I know that sometimes the reason is because of conflicting entries, but display: none on its own? - Argue with that if you can!

How to align breadcrumb

I have a a breadcrumb in my subheader however the active breadcrumb appears underneath the list. I would like it so that they are both in the same line.
HTML:
<div id="breadcrumb">
<ul>
<li>Home ></li>
<li class="active">Marketing Items</li> </ul> </div>
CSS:
#breadcrumb {
font-size:11px;
background-color:#F2F2F2;
}
#breadcrumb ul {
margin:0px;
margin-bottom:0px;
margin-left:4px;
list-style: none;
background-color:#F2F2F2;
}
#breadcrumb .active {
color:#B3B3B3;
}
Here is also the jsfiddle: http://jsfiddle.net/4nRPY/
Use float:left or display: inline-block. But, with float left you have to clear the element right after that.
#breadcrumb ul li{
float: left;
}
Use display: inline-block; on your <li> tags
#breadcrumb ul li {
display: inline-block;
}
DEMO: http://jsfiddle.net/4nRPY/2/
You can this way to chive to that
li{float:left;}
Demo http://jsfiddle.net/4nRPY/3/
I prefer a pseudo element:
JSFiddle
HTML
<div id="breadcrumb">
<ul>
<li>Home</li>
<li class="active">Marketing Items</li>
</ul>
</div>
CSS
#breadcrumb ul li:after {
content:">";
padding:0 0.5em;
}
#breadcrumb ul li:last-child:after {
content:"";
padding:0;
}
Slighty less browser support but no extraneous HTML mark-up and you can change it throughout your site by changing one CSS property.

List-style goes away with inline-block - but I want my list decorators to stay

How do I get them to stay?
I have the following list - the moment I add to my list li display: inline-block; the custom list decorators I designated disappear.
Is there a CSS way of keeping my list decorators when the list is horizontal, or are list decorators only ever supposed to appear with vertical lists? Of course I could just have an image next to every list entry, but for simplicity's sake I'd rather deal with this in the CSS.
.first-page-menu-list {
list-style-image: url('../graphics/list-style-image.png');
list-style-position: inside;
text-transform: uppercase;
}
An alternate method consists of floating the li elements.
<ul>
<li>the item</li>
<li>the item</li>
<li>the item</li>
</ul>
ul {
overflow: auto; /* similar to clearing the floats... */
border: 1px solid gray;
}
ul li {
float: left;
border: 1px solid blue;
padding: 10px;
margin: 0 20px;
}
Demo fiddle: http://jsfiddle.net/audetwebdesign/kBNVz/
It seems that you're right but there's an easy fix for this, just use the background as long as you're not using it otherwise try this:
CSS:
.first-page-menu-list li {
background: url('../graphics/list-style-image.png') no-repeat 0px 4px;
display: inline;
text-transform: uppercase;
padding-left: 15px;
margin-left: 10px;
}
HTML:
<ul class="first-page-menu-list">
<li>asd</li>
<li>asdf </li>
<li> asdf</li>
</ul>
Play with the px values and you'll easy see what does which magic
Flexbox works well for this without the need to clear your floats.
ul.inline-list-style {
list-style: upper-roman;
display: flex;
}
ul.inline-list-style li {
flex: 1;
}