Reputation: 39
I really like how http://designmodo.com/ has simulated 3D borders on their navigation, so I'm trying to recreate that in my site. However, on my site, border-right and border-left in the nav
are not touching each other, but instead separated by a small space. How can I fix this?
Thank you for your time.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/1140.css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="head">
<!-- Logo goes here -->
<div class="container12">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Departments</a></li>
<li><a href="#">Library</a></li>
<li><a href="#">More</a></li>
</ul>
</nav>
</div>
</div>
<div class="headFix"></div>
<div class="info">
</div>
<footer>
<div class="container12">
</div>
</footer>
</body>
</html>
.head { /* preffered color is blackish:#2E3234 or blue:#245789*/
display: block;
clear: none;
background-color: #446CB3;
height: 75px;
width: 100%;
position: fixed;
z-index: 2;
margin: 0;
padding: 0;
}
nav {
float: right;
font-size: 16px;
display: block;
padding: 0;
margin: 0;
}
nav a:link, nav a:visited {
border-left: 1px solid #587BBA;
border-right: 1px solid #3D61A1;
text-decoration: none;
color: #E4EBF0;
display: inline-block;
height: 23px;
padding: 26px 15px;
text-align: center;
letter-spacing: 1px;
-o-transition: .2s ease-in-out;
-moz-transition:.2s ease-in-out;
-webkit-transition:.2s ease-in-out;
transition: .2s ease-in-out;
}
nav a:hover, nav a:active {
background-color: #fff;
color: #446CB3;
}
nav li {
display: inline;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
}
Upvotes: 2
Views: 109
Reputation: 6687
When you use display:inline-block
, you tell an element to behave like a block
element in terms of it's design, and like an inline
element in terms of placement. The spacing between the elements falls under the placement, or the inline
part of this.
There is an odd quirk with CSS and inline-block
elements, where upon if you have linebreaks between elements in the HTML code file, you will see a space between them in the results. You have a couple ways to address this.
Leave your CSS as it is, and change the HTML file. Makes for ugly HTML though.
<li><a href="#">Home</a></li>
<li><a href="#">Departments</a></li>
<li><a href="#">Library</a></li>
<li><a href="#">More</a></li>
<li><a href="#">Home</a></li><li><a href="#">Departments</a></li><li><a href="#">Library</a></li><li><a href="#">More</a></li>
Float
Instead of Inline-Block
You can keep your HTML structure as it is, and use float:left
to make things line up horizontally.
nav li {
display:inline-block;
}
nav li {
float:left;
}
If you've noticed, both methods don't have a double border on the outside. We can add this by giving the containing ul
borders that are opposite colors as the li
s have. However, if we use Method 2, we'll have to set that ul
to display:inline-block
to bring the borders down.
Use this WITH (IN ADDITION TO) Method 2 or 1.
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
border-left: 1px solid #3D61A1;
border-right: 1px solid #587BBA;
display:inline-block;
}
Upvotes: 2