mysterious margin for nav dots - html

I have created a very simple dot navigation on my site banner HERE. The HTML code i have used is as follows:
<ul class="carousel-dots">
<li>
</li>
<li>
</li>
<li class="active">
</li>
</ul>
Now for the <li> element i have the following code:
.banner ul.carousel-dots li {
height: 13px;
width: 13px;
display: inline-block;
background: url(../img/res/carousel-dots.png) 0 0 no-repeat;
margin: 0;
cursor: pointer;
}
Now even though i have margin: 0; in my style, i get a margin between the left and right, i don't know where are these spaces coming from , i would want the dots to be touching each other , side to side. So whats causing this mysterious margin ?

white space between inline-block elements?
The space is actually created by the "enter" between your elements.
How to remove the space between inline-block elements?
In the question above there are a lot of different answers how to remove it.
I set the parent element font-size to 0.
ul {
font-size: 0;
}
ul.carousel-dots li {
height: 13px;
width: 13px;
display: inline-block;
/*background: url(../img/res/carousel-dots.png) 0 0 no-repeat;*/
background-color: black;
border-radius: 50%;
margin: 0;
cursor: pointer;
}
<ul class="carousel-dots">
<li>
</li>
<li>
</li>
<li class="active">
</li>
</ul>

Ok, the answer is a bit tricky, if you want it fixed, you have to remove the space between the </li> and the next <li>
So, this:
<ul class="carousel-dots">
<li>
</li>
<li>
</li>
<li class="active">
</li>
Should become this:
<ul class="carousel-dots">
<li>
</li><li>
</li><li class="active">
</li>
The reason of this issue is the fact that when using inline-block, spaces are also considered inline characters, leaving space in between.
PS: There are also other ways to remove the space, by using word-spacing or other such things, but I find the simplest solution to be always the best, plus on html you should always try to minimize your code before shipping, so a few lines of code less is always better than a few more

Related

CSS dropdown menu subitem positioning

I'm having an issue where my dropdown is always on the left. I need to have it so it's directly under each menu item.
I tried playing around with the positioning because the absolute of the subitems is why it's going on the left all the time. But putting position: relative on subitem breaks the menu completely on hover.
Demo of issue: https://jsfiddle.net/dsngpsxb/2/
Code below:
HTML:
<nav class="main-navigation">
<ul>
<li class="item">item
<ul class="subitem">
<li>subitem</li>
<li>subitem</li>
<li>subitem</li>
</ul>
</li>
<li class="item">item
<ul class="subitem">
<li>subitem</li>
<li>subitem</li>
<li>subitem</li>
</ul>
</li>
<li class="item">item</li>
<li class="item">item</li>
<li class="item">item</li>
<li class="item">item</li>
<li class="item">item</li>
</ul>
</nav>
SCSS/SASS:
.main-navigation {
width: 100%;
position: relative;
ul {
margin: 0 auto;
padding: 18px;
.item {
display: inline;
padding-right: 43px;
font-size: 13px;
text-transform: uppercase;
&:hover ul {
display: block;
}
}
}
}
.subitem {
display: none;
position: absolute;
top: 50px;
li {
line-height: 30px;
font-size: 14px;
}
}
Please note that I did indeed do research here and found several questions on SO that explain my problem and I tried all accepted answers but none work.
I have included each example with a corresponding JSfiddle example below:
Dropdown menu appearing not below parent
adding position: relative to my subitem completely breaks menu: https://jsfiddle.net/mtp2cg7c/2/
CSS: make dropdown submenu appear below parent <ul> <li>
block display, relative positioning and a left float on my <li> with absolute positioning, 100% top and left: 0 on my <ul> "smashes" all the items togther: https://jsfiddle.net/9s9Lmr1h/4/
CSS dropdown menu element moving to left?
In the fiddle attached I noted that the global container as a property of clear: both; - I tried that in conjunction with floats and positioning. All sub items still float to the left: https://jsfiddle.net/3x3krdsd/1/
Is my <nav> tag to blame? I can't find anything that suggests this tag alters behavior of these rules: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav
Add a position: relative; to your .item and left: 0; to your .subitem.
This will make the sub-item position itself relative to the parent item, which should give you the result you want: https://jsfiddle.net/58sb3rL4/

CSS Layout not taking with id but does with <li> tag

Here is the HTML code :
<div id="tp-nb">
<ul>
<div id="tp-ls">
<li>
account-icon
</li>
<li>
notification-icon
</li>
<li>
icon
</li>
<li>
Images
</li>
<li>
Gmail
</li>
</div>
</ul>
And here is the CSS part:
ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 300pxx;
}
li{
float: right;
display: block;
padding: 10px;
}
When I change the css (li) to the id "#tp-ls" it loses it's layout and bunches all up completely. I've tried changing it from id to class, but as I figured out, made no difference.
Is there any possible way of handling a groupe of without affecting ALL ? I'm sure there is, however I fail to understand how it's possible. I also lack the knowledge thereof to know what I"m looking for, and therefore don't know how to search it on google ( for those of you whom would reply with "google it". )
Thank you, and until I get a response I'll continue searching what i'm searching for.
Here you make some mistakes
You must not use div inside ul
You can see that tp-ls this id is not assigned to any li so you have to give this id in ul
Example
ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 300pxx;
}
#tp-ls li{
float: right;
display: block;
padding: 10px;
}
<div id="tp-nb">
<ul id="tp-ls">
<li>
account-icon
</li>
<li>
notification-icon
</li>
<li>
icon
</li>
<li>
Images
</li>
<li>
Gmail
</li>
</ul>
</div>
Hope this will helps you :)

Unwanted extra li element in unordered list

So, I have an unordered list which contains buttons for a keypad. The problem is that for some reason, There's an extra <li> element in the end of the list and this just ends up screwing everything. How could I fix this?
<ul id="buttons">
<li><div><a><span>1</span></a></div><div><a><span>2</span></a></div><div><a><span>3</span></a></div></li>
<li><div><a><span>4</span></a></div><div><a><span>5</span></a></div><div><a><span>6</span></a></div></li>
<li><div><a><span>7</span></a></div><div><a><span>8</span></a></div><div><a><span>9</span></a></div></li>
<li style="max-width:80px;margin:auto;"><div><a><span>0</span></a></div><li>
</ul>
//as you can see only 4 li elements
//styles
li {
width: 100%;
border-spacing: 10px 5px;
display: table;
table-layout:fixed;
text-align: center;
}
ul {
position: relative;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
list-style-type: none;
}
But when I open the document in chrome, There are 5 <li> elements.
There is a typo error. Problem is at your last list item . It is not closed properly. It should be like this :
<li style="max-width:80px;margin:auto;"><div><a><span>0</span></a></div></li>
You have used <li> instead of </li> to close your last list item
so your could should be
<ul id="buttons">
<li>
<div><a><span>1</span></a></div>
<div><a><span>2</span></a></div>
<div><a><span>3</span></a></div>
</li>
<li>
<div><a><span>4</span></a></div>
<div><a><span>5</span></a></div>
<div><a><span>6</span></a></div>
</li>
<li>
<div><a><span>7</span></a></div>
<div><a><span>8</span></a></div>
<div><a><span>9</span></a></div>
</li>
<li style="max-width:80px;margin:auto;">
<div><a><span>0</span></a></div>
</li>

ul list gets hidden under a div

I've been having this issue in different places where I have a ul list and Im trying to add it on top of a div (image, or a background) but the list does not appear on top. I wonder if it gets sent in the back..i even added z-index
JSFiddle
CSS
.toolbar p{ text-align: right; padding: 10px 180px 0 0; color: #fff; font-size: 26px; z-index: 1; }
.toolbar { width: auto; height: 50px; background-color: #cc1e2c; z-index: 1;}
.social-icons { z-index: 2;}
HTML
<div class="col_full toolbar">
<p>CALL NOW: +1 555.555.1234</p>
<ul class="social-icons">
<li> </li>
<li> </li>
<li> </li>
</ul>
</div>
The reason you aren't seeing anything is because you posted links, without any content. If you added words, the list would appear:
<div class="col_full toolbar">
<p>CALL NOW: +1 555.555.1234</p>
<ul class="social-icons">
<li> Twitter </li>
<li> Instagram</li>
<li> Facebook</li>
</ul>
</div>
On this example I made the height bigger so you could see that the links are in fact on top.
If you want to see the images, you need to use the image tag like so:
<li> <img src="path/to/your/twitter_image.jpg"/> </li>
JSFiddle

CSS Hide Text But Show Image?

I need to change something without touching HTML codes.
So I have this code in my HTML
<span class="share">
<ul>
<li>Share </li>
<li class="twitter">twitter</li>
<li class="facebook">facebook</li>
<li class="delicious">delicious</li>
<li class="friendfeed">friendfeed</li>
<li class="addthis">share</li>
<div class="clear"></div>
</ul>
</span>
and this in CSS
.twitter {
background: url('../images/tt.png') no-repeat;
width: 10px;
height: 14px;
}
This works fine, but twitter text is visible under the twitter logo, I don't want those texts to appear in my list, I want to replace them with images in CSS.
Is it possible to do without touching HTML Codes?
Make the text transparent. Since it's a link, you'll want to use a few selectors to make sure all cases are addressed:
.twitter a, .twitter a:link, .twitter a:visited
{
color: transparent;
}
Edit: This other option, while more verbose, has the benefit of keeping the focus border (the little dots that appear when a link is selected) to the size and shape of the twitter icon. Also, the text will not be revealed if selected and copied and pasted. It becomes invisible and unselectable. Here is the technique:
.twitter a {
display: inline-block;
overflow: hidden;
width: 0;
height: 14px;
padding-left: 10px;
}
You could use text-indent:
text-indent: -9999px; /* get rid of any text */
Try making your font-size : 0px; in your css.
use text-indent with a little magic in it :)
HTML:
<span class="share">
<ul>
<li>Share </li>
<li class="twitter">twitter</li>
<li class="facebook">facebook</li>
<li class="delicious">delicious</li>
<li class="friendfeed">friendfeed</li>
<li class="addthis">share</li>
<div class="clear"></div>
</ul>
</span>
CSS:
a.twitter {
background-image:url('../images/tt.png');
display:block;
height:58px;
text-indent:-9999px;
width:200px;
}
So you see the text is indented but still the image is still clickable because i've put a class in the twitter link ;)