I am trying to complete a navigation list that is contained within a div.
I have it set to have a border on the right of each item to space out each item. I am looking to have this border only on the middle items and not on the last item.
HTML:
<div id="container-navigation">
<ul id="navigation">
<li>home</li>
<li>about</li>
<li>solutions</li>
<li>training</li>
<li>payments</li>
<li>contact</li>
</ul>
</div>
CSS:
#navigation li a {
color: #ffffff;
line-height: 22px;
font-size: 11px;
text-decoration: none;
padding: 5px 15px 6px 15px;
border-right: 1px solid #ffffff;
}
What would be the best way to accomplish this? Give the last item a unique class and create another CSS entry?
As suggested by thgaskell, here is one way of doing it:
#navigation li a {
color: green;
line-height: 22px;
font-size: 11px;
text-decoration: none;
padding: 5px 15px 6px 15px;
border-right: 1px solid red;
}
#navigation li:last-child a {
border-right: none;
}
Demo at: http://jsfiddle.net/audetwebdesign/G3mD9/
Note: the last-child pseudo-class is supported for IE9+, so a bit more limited than first-child which is good for IE7+.
If it was me, I would move the border to the left instead of the right:
#navigation li a {
border-left: 1px solid #ffffff;
}
And then I would use first-child as it is has good cross browser compatibility.
#navigation li:first-child a {
border-left: 0 none;
}
If you need to support older browsers (IE7+, etc...) you should flip the border from the right side to the left side, so that you can use the css selector first-child.
Change your current css from this:
#navigation li a {
color: #ffffff;
line-height: 22px;
font-size: 11px;
text-decoration: none;
padding: 5px 15px 6px 15px;
border-right: 1px solid #ffffff;
}
To:
#navigation li a {
color: #ffffff;
line-height: 22px;
font-size: 11px;
text-decoration: none;
padding: 5px 15px 6px 15px;
border-left: 1px solid #ffffff;
}
#navigation li:first-child a {
border-left: none;
}
EXAMPLE FIDDLE
Try the :last-child Selector, the easy way.
#navigation li a:last-child {
border-right: none;
}
Create new id or class name to last list item, then
give the style like that,
#id_name a { border-right:none !important; }
As an alternative to :first-child, you can also use the adjacent sibling selector to get IE7+ support. It needs changing to border-left from border-right like other solutions too though.
#navigation li a {
color: #ffffff;
line-height: 22px;
font-size: 11px;
text-decoration: none;
padding: 5px 15px 6px 15px;
}
#navigation li + li a {
border-left: 1px solid #ffffff;
}
Related
When hovering over a list item, see Fiddle (https://jsfiddle.net/22upj1yc/), I want the black highlight to cover not the entire area of the list item, not leaving any white space on top or bottom. Right now it only covers the center area of the list item.
I have tried removing the padding from ul and adding a height to li like this, but it does not work. How do I do this?
ul {
display: inline-block;
list-style: none;
margin: 0 auto;
background: #fff;
border-bottom: 2px solid #d8d8d8;
}
ul li {
display: inline-block;
border-right: 1px solid #d8d8d8;
height: 50px;
}
Add the hover to the <li> instead of the <a> tag, see fiddle https://jsfiddle.net/22upj1yc/1/
ul li:hover {
background-color: black;
}
I basically have updated your item, look in this jsfiddle.
Instead of just ul { }, I have made it ul li { }.
CODE
body {
font: 15px/1.625em "Helvetica Neue", Helvetica, sans-serif;
background: #f5f5f5;
}
ul li {
display: inline-block;
list-style: none;
padding: 10px;
margin: auto;
background: #fff;
border-bottom: 2px solid #d8d8d8;
}
ul li {
display: inline-block;
border-right: 1px solid #d8d8d8;
}
ul li a {
color: #777;
text-decoration: none;
padding: 0 12px;
}
ul li:hover {
background-color: black;
}
ul li.next {
border-right: 0;
}
ul li.next:after {
content: "\f054";
font-family: FontAwesome;
font-size: 12px;
padding: 0 10px;
}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li class="next">
Next
</li>
</ul>
Remove padding top and bottom from ul
ul {
display: inline-block;
list-style: none;
padding: 0 10px;
margin: 0 auto;
background: #fff;
border-bottom: 2px solid #d8d8d8;
}
And add padding to li
ul li {
display: inline-block;
border-right: 1px solid #d8d8d8;
padding:10px 0px;
}
here is link for jsfiddle https://jsfiddle.net/22upj1yc/6/
!--Sorry for bad English--!
The inline-block elements are adding around 4px space after each element (changes by browser). You can negate this with font-size: 0 on that element and switch your font size to apply directly to the li or a tags.
css
body {
background: #f5f5f5;
// removed font sizing, replaced in ul li below
}
ul {
display: inline-block;
font-size: 0; // get rid of ghost space after inline-blocks
list-style-type: none;
background: #fff;
border-bottom: 2px solid #d8d8d8;
margin: 0; padding: 0;
}
ul li {
display: inline-block;
border-right: 1px solid #d8d8d8;
text-align: center;
margin: 0;
padding: 0px 6px; // added some left/right padding
font: 15px/1.625em "Helvetica Neue", Helvetica, sans-serif; // moved your font sizing here
}
...there were some other padding issues I believe, basically I set all else to 0.
fiddle
https://jsfiddle.net/Hastig/3ezn15a0/1/
I have a simple navigation bar with an hover element.
.navip {
float: left;
text-decoration: none;
font-weight: lighter;
}
.navip > a {
display: block;
color: black;
text-decoration: none;
font-size: 20px;
font-weight: lighter;
line-height: 40px;
}
.navip > a:hover {
border-top: 3px solid blue;
}
When i hover on a, the border displays. But its taking down the text a little bit.
How i can fix this?
JsFiddle: http://jsfiddle.net/w0btkceg/
Edit: Solved it! I had to increase the height to 45 and add "border-top: 3px solid transparent" to the "navip a" class.
try to use
.navip > a:hover {
border-top: 3px solid blue;
margin-top: -3px;
}
I use this for menu:
.menu-item {
margin: 5px;
font-size: 1em;
font-weight: bold;
float: left;
border-top-style: solid;
border-top-width: 4px;
border-top-color: transparent;
}
.menu-item a {
padding: 5px 0;
text-decoration: none;
}
.menu-item-selected {
border-top-color: green;
}
.menu-item:hover {
border-top-color: green;
}
<div class="menu-item">
Test 1
</div>
<div class="menu-item menu-item-selected">
Test 2
</div>
<div class="menu-item">
Test 3
</div>
<div class="menu-item">
Test 4
</div>
Just do something like:
.navip > a {
display: block;
color: black;
text-decoration: none;
font-size: 20px;
font-weight: lighter;
line-height: 40px;
border-top: 3px solid transparent;} /* add a transparent border to the a */
.navip > a:hover {
border-top: 3px solid blue; /* Now just change the color value of the border from transparent to a color on over */
}
See working example here
Solution: Add a transparent border to the a , then add a color to it on hover. That way, the text won't move because the border existed before hover.
You could try box-sizing:border-box; this will include the border in the size of the box and is probably the most elegant solution.
Or my previous fix for this was just to have 10 padding for the normal link then padding:8px; for the hover version which had a border. Which would counter the border size.
Ok, you can declare a border-top property for the .navip > a{}, with 0 opacity on it, and then on hover, use your border color, like this one(check here)
.navip > a {
display: block;
color: black;
text-decoration: none;
font-size: 20px;
font-weight: lighter;
line-height: 37px; /*readjust for the border stuff*/
border-top: 3px solid rgba(255,255,255,.0);/*or transparent*/
}
.navip > a:hover {
border-top: 3px solid blue;
}
OR you can use a negative margin-top property on hover, or top property if you can make the .navip > a to position relative, check it here:
.navip > a {
position: relative;
display: block;
color: black;
text-decoration: none;
font-size: 20px;
font-weight: lighter;
line-height: 40px;
}
.navip > a:hover {
margin-top: -3px;/*or top: -3px*/
border-top: 3px solid blue;
}
You could use a box-shadow instead of a border-top, like this:
.navip > a:hover {
box-shadow: inset 0 3px 0 0 blue;
}
More info here: MDN Box Shadow
I have made a nav with a list that gives a list item the class .selected when on the current page. I am trying to add a background colour to this class which works, but I can't get it to fill the whole li item. It's not adding any background colour to the left of the navs selected li item. Not sure if this makes sense?
Here's my html:
<nav>
<ul>
<li class="selected">Home</li>
<li>About</li>
<li>Themes</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
And here's the css:
nav li {
border-right: solid 1px #fbfbfb;
display: inline;
font-family: 'Lato', sans-serif;
font-size: 15px;
list-style: none;
margin-left: 15px;
padding: 22px 15px 22px 0;
text-transform: uppercase;
text-align: center;
}
nav ul {
border-top: solid 1px #fbfbfb;
border-left: solid 1px #fbfbfb;
margin-bottom: 0;
padding: 20px 0;
}
nav a {
color: #6e6e6e;
text-decoration: none;
}
nav a:hover {
border-bottom: 1px solid #2ecc71;
}
.selected {
background-color: #2ecc71;
}
Just give some padding on the left to the li -
padding: 22px 15px 22px 15px;
Here's the jsFiddle
change your padding-left value:
nav li {
padding: 22px 15px 22px 10px;
}
margins and borders dont get background color.
try to cahnge it margin of li to either padding or a border of same size.
nav li {
border-right: solid 1px #fbfbfb;
display: inline;
font-family: 'Lato', sans-serif;
font-size: 15px;
list-style: none;
padding: 22px 15px 22px 15px;
text-transform: uppercase;
text-align: center;
}
The list item with class selected is being completely filled according to the instructions you've given to the browser to display the li element with a margin-left: 15px; and padding: 22px 15px 22px 0;. The padding you have specified says there should be no padding to the left of the content in the list item (the last value of 0).
Try removing margin-left: 15px; and change your padding to padding: 22px 15px 22px 15px; for your nav li element, like so:
nav li {
border-right: solid 1px #fbfbfb;
display: inline;
font-family: 'Lato', sans-serif;
font-size: 15px;
list-style: none;
padding: 22px 15px 22px 15px;
text-transform: uppercase;
text-align: center;
}
Small question on how to achieve some styling on a HTML / CSS UL menu.
I have a standard UL menu, but having some issues getting my head around how to achieve a certain look to the styling. The UL menu as it currently stands is shown here:
http://jsfiddle.net/WMQqt/
(HTML)
<ul id="nav">
<li>CONTACT US
</li>
<li>HOME
</li>
</ul>
(CSS)
#nav {
list-style: none;
margin-bottom: 10px;
*/ margin-top: -6px;
position: relative;
right: 286px;
z-index: 9;
height: 26px;
padding: 4px 4px 4px 4px;
font-weight: bold;
}
#nav li {
float: right;
margin-right: 10px;
}
#nav a {
display: block;
padding: 5px;
color: #444444;
background: #fff;
text-decoration: none;
border: 1px solid grey;
}
#nav a:hover {
color: #fff;
background: #04B431;
}
I'd like the menu buttons to have a small 1px border, but then some white space padding of around 3px before the background color starts.
Similar to how this looks:
http://jsfiddle.net/6PY7z/
Can this be done using the UL menu method?
Thanks for any advice, I'm no expert with HTML / CSS.
Add margin to a tag and move border to li
#nav li
{
float: right;
margin-right: 10px;
border: 1px solid grey;
}
#nav a
{
display: block;
padding: 5px;
color: #444444;
background: #ccc;
text-decoration: none;
margin:3px;
}
DEMO
you can use the following styles to achieve what you want:
#nav li
{
float: right;
margin-right: 10px;
border: 1px solid grey; /*put original border here*/
}
#nav a
{
display: block;
padding: 5px;
color: #444444;
background: #d8d8d8; /*new background-color*/
text-decoration: none;
border: 3px solid white; /*add white padding here*/
}
http://jsfiddle.net/WMQqt/4/
ok
in html go
<dl><div><dt>F</dt><dd>T</dd></div>
<div><dt>F</dt><dd>T</dd></div>
<div><dt>F</dt><dd>T</dd></div>
<div><dt>F</dt><dd>T</dd></div>
</dl>
in css
dl { display: flex;
flex-direction: column;}
some hints...
dt float left AND
dd float right
Here is a live example:
http://jsfiddle.net/Pzvdv/
<ul id="navigation">
<li>HOME</li>
<li>OUR APPROACH</li>
<li>MENU</li>
<li>GET IN TOUCH</li>
</ul>
#navigation {
float: left;
list-style-type: none;
}
#navigation li {
background-color: #934B00;
border-radius: 6px 6px 0 0;
color: White;
cursor: pointer;
float: left;
font-size: 12px;
margin-right: 6px;
padding: 5px;
}
#navigation li a:link {
color: White;
text-decoration: none;
}
Notice how I can click the link if I'm careful, but when I click the "tab pill" itself, the link isn't clicked.
Any workaround or better ways to accomplish this visual effect?
I want to follow the link href whether the user clicks the actual letters or the container pill.
The padding and other styles have to move from <li> to <a>.
On top of that, you have to add display:block or display:inline-block to the anchor.
Currently, your code does not work as expected, because the padding on the <li> adds a gap between the <li>s border and the anchor.
http://jsfiddle.net/Pzvdv/9/
#navigation li {
color: White;
cursor: pointer;
float: left;
font-size: 12px;
margin-right: 6px;
}
#navigation li a:link {
display: block; /* Or inline-block */
color: White;
text-decoration: none;
background-color: #934B00;
border-radius: 6px 6px 0 0;
padding: 5px;
}
If you add some padding to the link element like so:
#navigation li a {
padding:5px
}
It should work.
Set a to display as a block, i.e.:
a { display:block; }
And add height/width to 100%, and move all padding to there too. That will make it fill the entire list item.
The css for the link needs to be applied to the anchor instead.
#navigation li {
float: left;
}
#navigation li a {
color: White;
text-decoration: none;
background-color: #934B00;
border-radius: 6px 6px 0 0;
color: White;=
font-size: 12px;
margin-right: 6px;
padding: 5px;
cursor: pointer;
}
Like this? http://jsfiddle.net/Pzvdv/17/
You're adding all the presentation styles to the li elements instead of the actual links, just switch them and your pill menu works fine:
#navigation li {
float:left;
}
#navigation li a {
background-color: #934B00;
border-radius: 6px 6px 0 0;
color: White;
cursor: pointer;
font-size: 12px;
margin-right: 6px;
padding: 5px;
}
You should style the <a> element itself.
#navigation {
float: left;
list-style-type: none;
}
#navigation li a:link {
color: White;
text-decoration: none;
background-color: #934B00;
border-radius: 6px 6px 0 0;
color: White;
cursor: pointer;
float: left;
font-size: 12px;
margin-right: 6px;
padding: 5px;
}