I am working on a sidebar, where I have 'a' elements inside 'li's, applying CSS code on them, and giving them border. However when I apply border-bottom on the 'a' elements, space between the elements is also effected. How can I remove this space between them? Thanks.
Sidebar image link: http://imgur.com/gntSanx
Code [html] :
<div id="container">
<div class="sidebar">
<ul id="nav">
<li><a href="#" class="selected">Dashboard</li>
<li><a href="#">Booter Hub</li>
<li><a href="#">Stresser</li>
<li><a href="#">Friends</li>
<li><a href="#">Search</li>
<li><a href="#">Purchase</li>
</ul>
</div>
<div class="content">
Code [CSS] :
ul#nav li a {
color: #ccc;
display: block;
padding: 10px;
font-size: 0.8em;
border-bottom: 1px solid #0A0A0A;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s
}
You need to be a bit careful here. First, zero out the margin and padding for the parent ul element (which will also zero out the same for the li child elements).
You can then add the styling to the a elements as you need for your design.
#nav {
margin: 0;
padding: 0;
list-style: none;
}
#nav li {
border: 1px dotted blue;
}
#nav li a {
display: block;
padding: 10px;
border-bottom: 1px solid red;
background-color: beige;
)
<ul id="nav">
<li>Dashboard</li>
<li>Booter Hub</li>
<li>Stresser</li>
<li>Friends</li>
<li>Search</li>
<li>Purchase</li>
</ul>
You request is unclear but it sounds as though you are suggesting that adding the border increases the height of the elements.
To have the borders/padding be included in the overall element dimensions you can use the box-sizing:border-box css property.
The box-sizing property is used to alter the default CSS box model used to calculate widths and heights of elements. It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification.
Examples
box-sizing: content-box;
box-sizing: padding-box;
box-sizing: border-box;
box-sizing: inherit;
border-box
The width and height properties include the padding and border, but not the margin. This is the box model used by Internet Explorer when the document is in Quirks mode. Note: Padding & border will be inside of the box e.g. IF .box {width: 350px}; THEN you apply {border: 10px solid black;} RESULT {rendered in the browser} .box {width: 350px;}
Box-sizing # MDN
First thing.. Close that a tag...
<li>Dashboard</li>
Once you have done that you will get the following result (I have removed the ul list-style, margin and padding, I am assuming you have done the same in other code not shared in the question)...
ul {
list-style: none;
padding: 0;
margin: 0;
}
#nav li a {
border: 1px solid pink;
}
#nav li a {
text-decoration: none;
color: #ccc;
display: block;
padding: 10px;
font-size: 0.8em;
border-bottom: 1px solid #0A0A0A;
}
<div id="container">
<div class="sidebar">
<ul id="nav">
<li>Dashboard</li>
<li>Booter Hub</li>
<li>Stresser</li>
<li>Friends</li>
<li>Search</li>
<li>Purchase</li>
</ul>
</div>
<div class="content">
*remember to add text-decoration: none; to remove the default a tag underline.
Related
I want to have a border-bottom effect on hover.
I am using transition property on hover, however after the transition-duration is over the border size changes/reduces by a pixel or so, which seems weird. Please help fix this and also would love to know the reason for this effect.
HTML -
<nav class="navbar">
<ul>
<li>
Home
</li>
<li>
About us
</li>
<li>
Contact us
</li>
</ul>
</nav>
CSS -
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.navbar {
width: 90vw;
margin: 0 auto;
font-size: 1.2rem;
background-color: #f1f1f1;
}
.navbar ul {
display: flex;
list-style: none;
justify-content: center;
}
.navbar ul li {
padding: 10px 20px;
margin: 5px;
color: #333;
cursor: pointer;
border-bottom: 4px solid transparent;
}
.navbar ul li:hover {
color: orangered;
border-bottom: 4px solid orangered;
transition: all 1s;
}
Here is the code - https://codepen.io/rawn01/pen/bGBmBdK
The reason for this happening is how the browser optimizes rendering. For animating / transitioning effects it often separates the affected element into a separate "composition layer" for performance reasons.
You can try several ways to attempt to fix the graphical issue:
add will-change attribute in order to tell the browser to keep the element on a separate layer
modify your transition: all 1s to a more specific one (e.g. transition: color 1s, border-bottom-color 1s). Also make sure to only modify the border-bottom-color attribute, not the whole border-bottom attribute with size and type (even though it stays the same)
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 6 years ago.
I can't figure out how to remove this space from my navbar and the picture..
The CSS code I have for the navbar and the image is:
a {
text-decoration: none;
color: white;
padding-right: 5px;
padding-left: 5px;
padding-top: 0;
}
a:hover {
color: black;
}
header {
background-color: #C0C0C0;
margin: 3px 60px 0;
}
li {
display: inline;
border-right: 1px solid black;
border-left: 1px solid black;
border-bottom: 1px solid black;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
nav {
position: relative;
text-align: center;
}
ul {
list-style-type: none;
}
#bikebanner {
position: relative;
left: 65px;
}
#bikebanner is the image id.
And the html goes like so:
<header>
<img src="images/bicyclebanner.jpg" id="bikebanner" alt="People riding bikes." title="Biking">
<h1 id="pagetitle">Cycling Tours</h1>
<nav>
<ul>
<li>About Us</li>
<li>Ask Us</li>
<li>Destinations</li>
<li>FAQ</li>
<li>Reviews</li>
<li>Seminars</li>
<li>Trip Prep</li>
</ul>
</nav>
</header>
Looking for a universal fit as I have other things with white space between them as well.
Thanks.
Try adding this to your css:
img{
display:block;
}
img is of type inline-block which adds a little space which is hard to find.
setting it to block should fix it.
what space you are talking about ?
Keep in mind h1 by default has white space around it
every h1-h6 tag has a margin top and bottom by default. i think if you overwrite this in your css you have what you want.
h1 {
margin: 0;
padding: 0;
}
look at this jsfiddle https://jsfiddle.net/zn7wtdLp/
This drives a lot of people crazy initially and the solution is not obvious, but images, lists and list items end up with a small space like this due to the font size inherited by or set on the img or ul. If you do nothing, the img and ul inherit the body font size (often 14px - 16px) with results in this 0.25rem (or 3.5px - 4px) space issue.
Nav Items
There are two popular solutions:
Float your list items left and make sure that you add a clearfix to your ul or its container, or
My preferred solution: Set the font-size on the ul to 0 and then the font-size on the li to 1rem (or whatever).
So my CSS would look something like this:
ul {
font-size: 0;
list-style: none;
margin: 0;
padding: 0;
}
li {
display: inline-block;
font-size: 1rem;
}
Images
If you set the image to display: block, this would kill the space below the image. This comes with its own caveats as well. For example, if you want it centered after you switch it to display: block;, you'll need to set the side margins to auto. Something like this:
header img {
display: block;
margin: 0 auto;
}
The problem is display:inline. This treats the elements like text, so if you have
<li>...</li>
<li>...</li>
you have the problem you mentioned, because the linebreaks cause a space.
Try to put your list elements like this:
<li>...</li><li>...</li>
For other solutions see here
I am trying to customize a funnel chart on the basis of data that I have rendered through database on page.
All works well except css rendering for chart.
<ul id="funnel-cht">
<li style="height:70px;width:50%;background-color:yellow">pendora</li>
<li style="height:70px;width:40%;background-color:#98bf26">pending</li>
<li style="height:70px;width:30%;background-color:orange">pen</li>
<li style="height:70px;width:20%;background-color:#c10000">Test</li>
</ul>
Here is what it looks like right now-
http://jsfiddle.net/m74ets8v/1/
I want to style it according to actual looking funnel chart, for an example-
How would i be styling this chart to make sense for me.
.funnel_outer{width:420px;float: left;position: relative;padding:0 10%;}
.funnel_outer *{box-sizing:border-box}
.funnel_outer ul{margin:0;padding:0;}
.funnel_outer ul li{float: left;position: relative;margin:2px 0;height: 50px;clear: both;text-align: center;width:100%;list-style:none}
.funnel_outer li span{ border-top-width: 50px;border-top-style: solid; border-left: 25px solid transparent; border-right:25px solid transparent; height: 0;display: inline-block;vertical-align: middle; }
.funnel_step_1 span{width:100%;border-top-color: #8080b6;}
.funnel_step_2 span{width:calc(100% - 50px);border-top-color: #669966}
.funnel_step_3 span{width:calc(100% - 100px);border-top-color: #a27417}
.funnel_step_4 span{width:calc(100% - 150px);border-top-color: #ff66cc}
.funnel_step_5 span{width:calc(100% - 200px);border-top-color: #0099ff}
.funnel_step_6 span{width:calc(100% - 250px);border-top-color: #027002}
.funnel_step_7 span{width:calc(100% - 300px);border-top-color: #ff0000;}
.funnel_outer ul li:last-child span{border-left: 0;border-right: 0;border-top-width: 40px;}
.funnel_outer ul li.not_last span{border-left: 5px solid transparent;border-right:5px solid transparent;border-top-width:50px;}
.funnel_outer ul li span p{margin-top: -30px;color:#fff;font-weight: bold;text-align: center;}
<div class="funnel_outer">
<ul>
<li class="funnel_step_1"><span><p>1</p></span></li>
<li class="funnel_step_2"><span><p>2</p></span> </li>
<li class="funnel_step_3"><span><p>3</p></span></li>
<li class="funnel_step_4"><span><p>4</p></span></li>
<li class="funnel_step_5"><span><p>5</p></span></li>
<li class="funnel_step_6"><span><p>6</p></span></li>
<li class="funnel_step_7"><span><p>7</p></span></li>
</ul>
</div>
The secret is to use margin: 0 auto for the lis. Setting the automatic margin calculation for the left/right dimension will center a block element horizontally. (Unfortunately, this technique doesn't work for vertical centering, but that's a different story.)
Here's your code, slightly modified, in a working example:
ul, li { margin: 0; padding: 0; list-style: none; }
ul { width: 400px; }
li { height: 70px; margin: 0 auto; }
/* NOTE: nth-child would be the better way to assign CSS to a set of
uniform elements than one class per li, but let's keep it simple for now */
li.li1 { width: 50%; background-color: yellow; }
li.li2 { width: 40%; background-color: #98bf26; }
li.li3 { width: 30%; background-color: orange; }
li.li4 { width: 20%; background-color: #c10000; }
<ul>
<li class='li1'>pendora</li>
<li class='li2'>pending</li>
<li class='li3'>pen</li>
<li class='li4'>Test</li>
</ul>
By the way, as already noted in the comments: In order to have actual trapezoids, you would (as far as I know) need to use SVG, and of course appropriate fallbacks for browser that don't support it.
If, as i read from comments, you just need to center the <li> elements you can set the an auto margin.
#funnel-cht>li
{
display:block;
margin:0 auto;
}
I'm a CSS-beginner. Basically I have the following html:
<ul>
<li>О нас</li>
<li>Галерея</li>
</ul>
I want to have a thick underline when hovering my a tags, but I use a custom font with big descenders, so if I use the common trick for this:
a:hover {
text-decoration: none;
border-bottom: 2px solid;
padding: 0;
margin: 0;
}
The underline is far below the base line: But I want it to look like this:
I tried to do it like this:
<ul>
<li class="over">О нас</li>
<li class="over">Галерея</li>
</ul>
.over{
font-size: 30px;
height:30px; // makes the text overlap this element
overflow:visible;
}
.over:hover {
border-bottom: 2px solid #ec6713;
}
But the width of the underline is the same for all the strings now:
Then I added display: inline-block; for .over. But I got this:
Then I changed inline-block to table, but the underline is again far below:
I ended up adding an extra span, so now I have:
<ul>
<li><span class="over">О нас</span></li>
<li><span class="over">Галерея</span></li>
</ul>
.over{
font-size: 30px;
height:30px; // makes the text overlap this element
overflow:visible;
display:inline-block;
}
.over:hover {
border-bottom: 2px solid #ec6713;
}
And this gives me finally the desired behaviour (the underline width is adjusted to the string width, and it's positioned close to the baseline). But is it a good practice to add an extra span for this purpose? Doesn't it look hacky?
A span is a meaningless tag, so it won't give extra 'weight' to your code. Therefor, imho, it is okay to use it (but better to avoid).
Alternatively you could do the following:
<ul>
<li>О нас</li>
<li>Галерея</li>
</ul>
a {
font-size: 30px;
text-decoration: none;
position: relative;
}
a:hover:after {
content: "";
border-bottom: 2px solid #ec6713;
position: absolute;
left: 0;
right: 0;
bottom: 3px;
}
And a DEMO.
Please note that the :after is overlapping the a. I've tried adding a z-index, but that didn't fix it.
OPTION 2
Add a background-image to your a.
I have implemented my webpage menu by inline li-s of ul. li has a colored border and contains a. Now onmousehover I need to change color of the text inside a and move it 2px up by not moving the li border. How can I do that?
The trick is to remove the top padding a bit and increase the bottom padding a bit to maintain the markup integrity.
I have set up a simple example of what you want. Check it on the fiddle here
The HTML:
<ul>
<li>Home</li>
</ul>
The CSS:
ul { width: 200px; margin: 20px; }
li { border-top: 2px #000 solid; padding: 5px; }
li a { padding: 5px; display: inline-block; }
li:hover a { padding: 3px 5px 7px 5px ; }
Add this to your CSS:
a:hover.jump {
color: [Insert whatever];
position: relative;
bottom: 2px;
}
And then add a class to your link
<ul>
<li>My Link Text</li>
</ul>
You can add background colors or whatever else you need on the hovering text. The cliche-named but pretty useful website CSS Ninja has a bunch of examples