i'm begginer in html and css and i'm building my first site based on my psd project, i just started making it and i can't get through one problem.
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.grid {
margin: 0 auto;
width: 960px;
}
.primary-header {
position: relative;
background-color: #fff;
height: 85px;
}
.logo {
position: absolute;
top: 29px;
}
.primary-nav {
font-size: 12px;
font-weight: 700;
letter-spacing: .5px;
text-transform: uppercase;
}
.nav {
text-align: right;
}
.nav li {
display: inline-block;
vertical-align: top;
margin: 0 30px;
padding: 11px 30px;
}
.nav li:hover {
border: 1px solid #333;
border-radius: 5px;
background-color: #333;
color: #fff;
}
.nav li:last-child {
margin-right: 0;
}
border:1px solid #333;
border-radius:5px;
background-color:#333;
padding-bottom:10px;
color:#fff;
}
.nav li:last-child {
margin-right: 0;
}
<header class="primary-header">
<div class="grid group">
<a href="index.html">
<img src="http://i58.tinypic.com/2q2prah.png" class="logo" alt="logo">
</a>
<nav class="nav primary-nav">
<ul>
<li>O firmie</li>
<!--
-->
<li>Oferta</li>
<!--
-->
<li>Realizacje</li>
<!--
-->
<li>Kontakt</li>
</ul>
</nav>
</div>
</header>
and here's the effect i'm gonna reach:
So the problems are:
After pointing with cursor on menu element, padding-top and padding-bottom is too big, it should be 11px and right now it's propably 19px
According to margin-top in ".nav li" my nav should be vertically aligned, but it's a little bit too much into bottom, if i set margin-top: 0px;, there is still some white space above my nav, why?
After i point any menu element with cursor, all the menu elements move 1px to bottom, why?
Thanks for your answers, i was searching for answers for about 2 hours and i still didn't find it... please, help me..
Here's my best reply to your questions:
1) The padding is in addition to your text. For example, with Firebug I can see that OFERTA is measured as 15px tall. Add 11px to top and bottom and you get 37px. To get it to 11px, you're going to have to reduce the font-size and add minimal padding. If you don't care as long as the menu item isn't too big, then just lower the vertical padding in
padding: 11px 30px;
2) By default, the ul element has some margins. Set the margin to 0 for nav to remove it.
3) Previously, before hovering, the CSS rules state that the menu item has no border. On nav li:hover, the CSS adds a border, which increases the overall area and to compensate and stay in the center, the text moves slightly downward. A fix would be to add a border to the nav li.
Also,
border:1px solid #333;
border-radius:5px;
background-color:#333;
padding-bottom:10px;
color:#fff;
}
seems to be out of place. It's missing a opening brace and an identifier.
For #1, Try reducing the padding on .nav li from padding: 11px 30px to padding: 5px 30px
For #2, Add a float: left on your .logo and remove the position: absolute
For #3, Remove the border: 1px solid #333 on .nav li:hover
Number 1 renders fine on IE11 at my machine. Show 11px padding-top and -bottom. So this is working as it should. Maybe it is not desired?
Number 2 is caused by the margin on the UL, it's 12px.
.nav ul {
margin-top: 0px;
}
Number 3 is caused by the added border on hover. You need to use extra padding or set a transparent border to nav.li
.nav li {
display: inline-block;
vertical-align: top;
margin: 0 30px;
padding: 11px 30px;
border: 1px solid transparent;
}
Related
I would like add a border-bottom that displays when I hover over it with the mouse. I want it to override the border underneath so it looks like it changes colour. An example of this can be found here http://www.formaplex.com/services (in the nav bar)
Here is a jsfiddle https://jsfiddle.net/ey006ftg/
Also, a small question: does anyone know why there is a small gap in-between the the links (can be seen when hovering from link to link) and how to get rid of it.
Thanks
Just add this to your css:
nav a {
border-bottom: solid transparent 3px;
}
Here's a jsfiddle with the above code: https://jsfiddle.net/AndrewL32/ey006ftg/1/
You can use a negative margin to overlay the border below, as shown:
nav {
border-top: 1px solid grey;
border-bottom: 3px solid black;
width: 100%;
font-size:0;
}
nav ul {
width: 1056px;
margin: 0 auto;
text-align: center;
width: 1056px;
}
nav ul li {
display: inline-block;
width: 17%;
}
nav ul li a {
display: block;
padding: 21px 0;
font-size: 18px;
text-align: center;
letter-spacing: 1px;
text-transform: uppercase;
}
nav a:hover {
color: orange;
transition: 0.2s;
border-bottom: solid orange 3px;
margin-bottom: -10px;
}
a {
color: black;
text-decoration: none;
outline: 0;
}
<nav>
<ul>
<li>Home</li>
<li>Products</li>
<li>About</li>
<li>Careers</li>
<li>Contact</li>
</ul>
</nav>
As for fighting the inline gap, seeing as you defined a font-size later for the a tag, I would just add a font-size:0, which I added to nav in the above Snippet.
fiddle demo
Simply set your default border to transparent - change color on hover
nav ul li a {
display: block;
padding: 21px 0;
font-size: 18px;
text-align: center;
letter-spacing: 1px;
text-transform: uppercase;
border-bottom: solid transparent 3px; /* add this! */
transition:0.3s; /* or even this :) */
}
Try this fiddle
To set border-bottom the way you want, you have to add border to anchor tag like this:
nav ul li a {
display: block;
padding: 21px 0;
font-size: 18px;
text-align: center;
letter-spacing: 1px;
text-transform: uppercase;
border-bottom: 3px solid black;
}
and to make sure the space between menu items is gone use a little fix adding negative margin to your li tags inside menu like this:
nav ul li {
display: inline-block;
width: 17%;
margin-right: -4px;
}
Whatever I do I can't get the navigation to center.
I have a wrapper and the navigation bar has an underline across this div. The top of the buttons are rounded of so it just looks like they are coming out of the bottom border.
I've tried searching for a good way to center them. A lot of people use margin auto or margin 0 auto. Other people also use this in combination with display inline-block but then the border gets cut off from the nav buttons.
This is my HTML:
<div id="nav">
<ul>
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>CV</li>
<li>Contact</li>
</ul>
</div>
The CSS:
#nav {
margin: auto;
color: #FFFFFF;
width: 100%;
border-bottom: 1px solid #000000;
}
#nav ul {
margin: auto;
padding-top: 6px;
padding-bottom: 8px;
padding-left: 5px;
list-style:none;
}
#nav li {
display: inline;
width: 120px;
margin:0;
padding: 10px 5px;
border-radius: 10px 10px 0px 0px / 10px 10px 0px 0px;
background : -webkit-gradient(linear, left top, left bottom, from(rgb(100,100,100)), to(rgb(132,132,132)));
background : -moz-linear-gradient(top, rgb(200,200,200), rgb(232,232,232));
}
#nav li:last-child {
border-right: none;
}
#nav a {
text-decoration: none;
color: #383838;
font-weight: bold;
font-size: 20px;
padding-right: 10px;
padding-left: 5px;
}
For the ease for you i've also put it in a js fiddle http://jsfiddle.net/ge702rna/
Really hope someone can help me out because i've got my hands tied up in my hair right now.
Probally i'm just doing something simple wrong.
Simply add text-align:center;
#nav {
color: #FFFFFF;
width: 100%;
border-bottom: 1px solid #000000;
text-align:center; /* <-- ADD THIS LINE */
}
I just change the width in
#nav {
margin: auto;
color: #FFFFFF;
width: 77%; //changed
border-bottom: 1px solid #000000;
}
Are you looking for this..DEMO
I'm creating header of one aplication nad I found strange problem, which never happentd to me before. The problem is, that i have two list inside header, one floated to left, one to right and between all li elements there are two types of border. That's ok, but there's creating space between them out of nowhere? Or at least, I can't find what is creating the space
Can someone tell me where's space created?
Here is jsFiddle: jsFiddle link
Or direct-input:
HTML:
<header id="header">
<ul class="left">
<li class="title">jedna</li>
<li class="new-task">dva</li>
<li class="new-comment">NC</li>
</ul>
<ul class="right">
<li class="logged">jedna </li>
<li class="logout">dva</li>
</ul>
CSS:
header
{
position: relative;
top: 0px;
min-height: 35px;
padding: 0px;
margin: 0px;
background-color: #efefef;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#bbbbbb), to(#efefef));
background: -webkit-linear-gradient(top, #efefef, #bbbbbb);
background: -moz-linear-gradient(top, #efefef, #bbbbbb);
background: -ms-linear-gradient(top, #efefef, #bbbbbb);
background: -o-linear-gradient(top, #efefef, #bbbbbb);
}
header ul
{
margin: 0px;
padding: 0px;
line-height: 35px;
list-style-type: none;
}
header ul li
{
margin: 0px;
display: inline;
padding: 5px 10px;
border-left: 1px solid #efefef;
border-right: 1px solid #bbbbbb;
}
header ul li:first-of-type
{
border-left: none;
padding-left: 20px;
}
header ul li:last-of-type
{
border-right: none;
padding-right: 20px;
}
header ul.left
{
float: left;
}
header ul.right
{
float:right;
}
EDIT:
This space:
Your li's are set to display: inline, so your browser is putting a space between each li just like it would between words. You can counter this default behavior in a few ways. You can float instead of using display: inline, you can put all your li's on one line without spaces, or you can add a negative margin to pull the li's together. This article explains your options better than I could:
http://css-tricks.com/fighting-the-space-between-inline-block-elements/
Set ul li to float:left; and set the line-height to 25 instead of 35 in header ul
Adding the following CSS code fixed it for me:
header ul.left li {
display:block;
margin: 0;
float: left;
line-height: 25px;
}
This is being caused by the display: inline;.
What is happening is the white space between the lis is being considered as a character.
To prevent this add font-size: 0; to the parent ul and then add the font-size: 16px; to the lis.
header ul {
margin: 0px;
padding: 0px;
line-height: 35px;
list-style-type: none;
font-size: 0;
}
header ul li {
margin: 0px;
display: inline;
padding: 5px 10px;
border-left: 1px solid #efefef;
border-right: 1px solid #bbbbbb;
font-size: 16px;
}
JSFIDDLE
Here is a good article on what options you can use.
Just add float: left; and reduce padding, here's a FIDDLE
header ul li {
display: inline;
float: left;
padding: 0 10px;
border-left: 1px solid #efefef;
border-right: 1px solid #bbbbbb;
}
*Note: Horizontal space with width of about 4px is always added on inline & inline-block elements and to fix that you must float them or write HTML code in line for that elements.
I'm having troubles coming up with a solution to styling my navigation. This is what I want:
And this is a link to what I have so far.
This is supposed to be two separate classes of links on one navigation bar. One set on the left for the logo and other default links, and on the right is for social. I'm just going to need help with the left side for now but I thought I'd explain even further.
On the left side, each link should be centered in their own little block with a border on the left and right being 1px white. On their hover state, the background of their "box" should be white. The logo should be first on the left.
I'm sorry that I'm not able to explain better, but I've done my best. The picture and the link to what I have so far should explain the most.
I think it would be better if the logo was in the CSS instead of the HTML??
CSS:
/* Navigation bar */
#navi {
font-family: Helvetica Neue: Condensed Bold;
font-size: 14px;
color: white;
text-transform: uppercase;
background-color: #1e416f;
height: 30px;
margin: 0 0 20px 0;
padding: 20px 0 0 0;
}
#navi a {
color: white;
margin: 0 0 0 20px;
height: 30px;
}
#navi a:hover {
background: white;
color: #1e416f;
}
HTML:
<!-- NAVIGATION -->
<div id="navi">
<img src="/imgs/navi/caul_white_nav.png">
Directories
Committees
Resources
About
</div>
You can try something like:
#navi img, #navi a {
float: left; /* float next to each other on the left hand side */
}
#navi a { /* use some padding to have some empty space */
padding: 5px;
border-right: 1px solid #ffffff;
}
#navi a:hover { /* on hover, background white on A tags */
background: #ffffff;
}
And than play untill it fits, with the right side you could do the same, inside the nav you can float it to the right. If you want to have a seperate DIV you should also float this #navi to the left and the #social to the right.
If you only use padding on an element (which is blocked) the text will always be centered because the padding left / right are the same.
TIP: If you use floats like this and you want an item to be on a new line. Normally it would be set next to the float. If you use a DIV after the item and do a clear: both; it will be on a new line.
I've written this using your design: http://jsfiddle.net/ninty9notout/v3658/
Just information on what is what here:
On the homepage, use: <h1 class="logo">...</h1> and on all other pages: <div class="logo">...</div>
.logo and #primary-nav are floated left to make them stick to the left side.
All the li and a tags are also floated to the left. Block elements are easier to style than inline elements.
#tools-nav is floated to the right so it sticks to the right side.
I've used text-indent: -9999px; to hide the text for the logo and the would-be icons in the #tools-nav - feel free to add the icons via background property. Set the widths for the icon anchors to whatever width your icons are + 20 (+10px on either side).
And that is that.
The HTML:
<div id="navi">
<h1 class="logo">Name of Site</h1>
<ul id="primary-nav">
<li>Directories</li>
<li>Committees</li>
<li>Resources</li>
<li>About</li>
</ul>
<ul id="tools-nav">
<li class="login">Log In</li>
<li class="email icon">Email</li>
<li class="twitter icon">Twitter</li>
<li class="search icon">Search</li>
</ul>
</div>
The CSS:
#navi {
height: 30px;
background: #1e416f;
font-size: 14px;
color: white;
text-transform: uppercase;
}
.logo {
margin: 0;
padding: 0;
float: left;
}
.logo a {
float: left;
margin: 2px 10px;
width: 36px;
height: 26px;
background: url(http://redsky.incredifull.com/imgs/navi/caul_white_nav.png) left top no-repeat;
text-indent: -9999px;
}
#primary-nav, #tools-nav {
list-style: none;
margin: 0;
padding: 0;
}
#primary-nav li, #primary-nav a,
#tools-nav li, #tools-nav a { float: left; }
#primary-nav a,
#tools-nav a {
color: white;
text-decoration: none;
padding: 0 10px;
border-right: 1px solid white;
line-height: 30px;
}
#primary-nav li:first-child a,
#tools-nav li:first-child a{ border-left: 1px solid white; }
#tools-nav { float: right; }
#tools-nav .icon a {
text-indent: -9999px;
}
#tools-nav .email a { /* image */ }
#tools-nav .twitter a { /* image */ }
#tools-nav .search a { /* image */ }
I think it's what you wanted. Enjoy :)
Use
<img src="/imgs/navi/caul_white_nav.png" style="float: left;">
I have a navigation bar/list that is using only HTML and CSS. The background image for the nav bar is 45px tall.
The list elements have been set with a CSS border-left property. I basically want to have a single vertical separator before each item in the list.
When I change the font in the list to around 30px the height of the border-left fills the 45px height of the div which is good. But when I set the size of the font smaller the border-left no longer fills the height of the div.
How can I set the font in the list small and yet still have the height of the border-left to 45px?
I have placed the code below. Thanks in advance
CSS:
#navbar{
background-image: url('../images/navbar.png');
color: white;
font: 25px arial,sans-serif;
height: 45px;
}
#navbar a{
color: white;
text-decoration: none;
}
#navbar ul{
list-style: none;
margin: 5;
padding: 5;
}
#navbar li{
border-left: solid 1px white;
display: inline;
padding: 1px 10px 1px 1px;
margin: 10px;
}
HTML:
<div class="clear" id="navbar">
<ul>
<li>Home</li>
<li>Start</li>
<li>In Jouw Regio</li>
</ul>
</div>
Here's a solution:
http://jsfiddle.net/bQe6W/1/
I changed the following
#navbar li {
display: inline-block;
line-height: 45px;
margin: 0 10px;
}
Also set the background of the div to gray so you can see the example!
For #navbar li change the display to inline-block and set the height to 100% and set the line-height to 45px.