Vertical align navigation link text - html

My aim is to have the text links to be central inline with the search text, however i want the border around each of the links to stay how they are. basically how to i centre the text without moving the border.
I have tried adding this to the links .home .reviews .store .contact, however this just moves the border.
padding-top:20px;
margin-top:20px;
Here is my HTML:
<div id="navigation">
<nav class="navbar">
<div class="navbarcontainer">
<ul class="nav navbar-nav">
<li class="home">Home</li>
<li class="reviews">Reviews</li>
<li class="store">Store</li>
<li class="contact">Contact</li>
</ul>
</div>
</nav>
Here is my CSS:
/* NAVIGATION */
li {
display:inline-block;
float:left;
border:1px black solid;
padding-left:12px;
padding-right:12px;
height:60px;
}
a:link, a:visited {
text-decoration: none;
color:#fff;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
}
This is what it currently looks like : http://imgur.com/0GVums0
Thankyou for any help

You can use line-height property on links to vertically center:
a:link, a:visited {
text-decoration: none;
color:#fff;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
line-height: 60px;
}
Or, you can also use vertical-align: middle, but keep in mind that this approach is not fully compatible with all browsers (IE8+).
li {
display:table;
float:left;
border:1px black solid;
padding-left:12px;
padding-right:12px;
height:60px;
}
a:link, a:visited {
text-decoration: none;
color:#fff;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
display: table-cell;
vertical-align: middle;
}

One way to do it:
li {
display: block;
float: left;
border: 1px black solid;
}
a {
padding: 19px 12px;
display: block;
}
a:link, a:visited {
text-decoration: none;
color: #000;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
}
Codepen example

Related

List hide after move anchor from :hover element

I want to show list when hover over <a> element. The list is shown but when I want to choose an item from it, it hides again.
I need code to stay showing until i click on item in it.
I want something in CSS please, I am learning JS now
.acc {
/* Account id */
font-family: 'Courier', arial;
color: black;
font-size: 3em;
text-decoration: none;
text-align: center;
}
.acc:hover {
color: #C0C0C0;
}
.hide {
display: none;
}
.acc:hover+.hide {
display: block;
font-family: 'Courier', arial;
color: black;
font-size: 3em;
text-decoration: none;
list-style-type: none;
padding: 0px;
margin: 0px;
overflow: hidden;
}
<div>
<a class="acc" href="acc">Accounts </a>
<ul class="hide">
<li>Facebook</li>
</ul>
</div>
You just need to add .hide:hover.
.acc:hover + .hide,
.hide:hover{
display:block;
font-family:'Courier', arial;
color:black;
font-size:3em;
text-decoration:none;
list-style-type:none;
padding:0px;
margin:0px;
overflow:hidden;
}

CSS positioning - relative positioning issue

Ive created a website but I noticed the navigation bar was slightly off using IE browser. I have read that position:relative may be the key but when I apply it the navigation bar doesn't respond to position commands (top, left, etc.)at all in IE, and would appear in different locations with FF browser when reloaded a few times.
Please could I get advice on which method is standard for getting correctly positioned elements with different browsers, and also tell me where I'm going wrong with changing my navigation bar divs from absolute to relative>
Much appreciated
code hints: Page comprises of company logo (id=banner) floated left, a small list of towns and phonenumber (id=info) all floated right. Navigation bar is in list form and I used block:inline command to so the list reads from left to right.
/* ----All page selectors---- */
body{
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
font-size:16px;
}
.page {
position: relative;
margin-left:auto;
margin-right:auto;
background-color: rgba(255,255,255,0.4);
font-family: gabriola, Verdana, Geneva, sans-serif;
color: #383838;
font-weight: bolder;
}
.banner a{
color: black;
text-decoration: none;
letter-spacing:10px;
}
#bannerText{
text-align:center;
}
.banner{
font-family: sans-serif, Verdana, Geneva;
}
#phonenum{
font-family: sans-serif, Verdana, Geneva;
}
#info{
font-weight:bold;
color: #505050;
line-height:110%;
}
ul a{
color: #383838;
}
/* ----Desktop only---- */
#media screen and (min-width:481px) {
body{
background-image: url("images/water.jpg");
}
#info{
font-size: 200%;
float: right;
right:0px;
width: 230px;
margin: 15px 25px 0px 0px;
padding:15px 5px 5px 5px;
}
#info ul{
margin:0px;
padding-left:63px;
}
#phonelogo{
float:left;
width:30px;
}
#phonenum{
float:right;
width: 190px;
margin:0%;
font-size: 80%;
font-family: sans-serif, Verdana, Geneva;
}
.banner{
float:left;
padding-top:1px;
margin-left: 18px;
opacity: 0.7;
}
#banner{
margin-top: 20px;
}
.banner p{
margin:0px;
}
#bannerText{
letter-spacing: 5px;
margin-bottom:5px;
padding-left:5px;
}
.btn{display:none;}
#toolbar {
position: absolute;
margin:220px 0px 0px 16px;
opacity: 0.7;
}
.menu li a{
font-family: gabriola, Verdana, Geneva, sans-serif;
font-size: 140%;
font-weight: bold;
text-decoration: none;
color: black;
margin-right:30px;
}
.nav{
position: absolute;
list-style-type: none;
top:10px;
left:-33px;
}
.nav ul li{
display: inline;
}
.nav ul li a{
font-family: gabriola, Verdana, Geneva, sans-serif;
font-size: 140%;
font-weight: bold;
text-decoration: none;
color: black;
}
.nav ul li a:hover{
color: yellow;
}
<div id="homePage" class="page">
<div class="banner">
<p id="banner">
<a href="index.htm"><img src="images/Logo.png" alt="
Logo for site" /></a>
</p>
<p id="bannerText"><a href="Slogan link.htm">
Slogan under the Logo</a></p>
</div>
<div id="info">
<table>
<tr>
<td id="phonelogo"><img src="images/phoneimage.png" alt="
Mobile phone image" /></td>
<td id="phonenum">(08080) 080 080</td>
</tr>
</table>
<ul>
<li>Town A</li>
<li>Town B</li>
<li>Town C</li>
</ul>
</div>
<div id="toolbar">
<div>
<p id="toolBackground">
<img src="images/toolBackground.png" alt="
Coloured background for toolbar" />
</p>
</div>
<div class="dropdown">
<ul class="nav">
<li><img class="btn" src="images/menuIcon.png" alt="
Menu button for mobile site version" />
<ul class="menu">
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
</ul>
</li>
</ul>
</div>
</div>
Always use a css reset so the styling is the same between browsers.
Very minimal css reset I always use:
html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,time,mark,audio,video {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
display: block;
}
Then everything should look (mostly) the same between browsers.
Also keep in mind display: inline-block; adds spaces between elements based on the font-size.

a:visited not working in Microsoft Edge

My site works and looks fine using Chrome, Safari, and Firefox but in the Microsoft Edge browser, my navbar breaks. Whenever I visit a page, the background color of the nav link becomes white when its supposed to stay dark blue (#293241). Here is my code:
.nav a:link, .nav a:visited {
display: block;
width: 100px;
background-color: #293241;
color: #FFF;
padding: 7px;
text-decoration: none;
font-family: Francois One, sans-serif;
text-align: center;
text-transform: uppercase;
}
<div class="nav">
test
</div>
Any work around?
Edited a:link and a:visited into two css sections fixed the issue. Like so:
.nav a:link {
display:block;
width:100px;
background-color:#293241;
color: #FFF;
padding: 7px;
text-decoration:none;
font-family: Francois One, sans-serif;
text-align: center;
text-transform: uppercase;
}
.nav a:visited {
display:block;
width:100px;
background-color:#293241;
color: #FFF;
padding: 7px;
text-decoration:none;
font-family: Francois One, sans-serif;
text-align: center;
text-transform: uppercase;
}
<div class="nav">
test
</div>

Evenly space out horz links and bullets between links across nav bar

I have a horz nav bar at the top of my website that has 7 text links & 6 bullets between the text links. Is there a way to evenly space out the text links & bullets horz across the nav bar. I tired it with the following code, all works well except the bullet spacing is weird and off. Much appreciated for some help on this. Here is the code I have.
Here is a link to my code on fiddle: http://jsfiddle.net/mountart/bdzcv/
<style type="text/css">
div#container{
width:1020px;
}
div#container ul {
display:table;
width: 100%;
margin:0px 0px;
padding-left:0px;
-webkit-padding-start:0px; /* reset chrome default */
}
div#container ul li {
display:table-cell;
height:20px;
line-height:20px;
width:14.285%;
font-family: "Arial Narrow", Arial, sans-serif;
font-weight:bold;
font-size:12px;
padding:0px 0px;
text-align: center;
border-right:none;
}
div#container ul li:last-child {
border-right:none;
}
div#container A:link { COLOR: black; TEXT-DECORATION: none; font-weight: normal }
div#containerA:visited {
COLOR: #666;
TEXT-DECORATION: none;
font-weight: normal
}
div#container A:active {
COLOR: #666;
TEXT-DECORATION: none
}
div#container A:hover {
COLOR: #C00;
TEXT-DECORATION: none;
font-weight: none
}
div#container li.headerbullet
{
float:left;
display:inline-block;
width:auto;
margin-left:5px;
margin-right:0px;
height:20px;
line-height:20px;
}
div#container li.headerbullet img
{
margin-top:10px;
}
</style>
<div class="clear"></div>
<div id="container">
<ul>
<li>ARTS & ENTERTAINMENT</li>
<li class="headerbullet"><img src="http://www.hispanicbusiness.com/_client_common/images/main/2012/footer_bullet.png"/></li>
<li>TECHNOLOGY</b></li>
<li class="headerbullet"><img src="http://www.hispanicbusiness.com/_client_common/images/main/2012/footer_bullet.png"/></li>
<li>AUTO</li>
<li class="headerbullet"><img src="http://www.hispanicbusiness.com/_client_common/images/main/2012/footer_bullet.png"/></li>
<li>SPORTS</li>
<li class="headerbullet"><img src="http://www.hispanicbusiness.com/_client_common/images/main/2012/footer_bullet.png"/></li>
<li>NEWS BRIEFS</li>
<li class="headerbullet"><img src="http://www.hispanicbusiness.com/_client_common/images/main/2012/footer_bullet.png"/></li>
<li>GREEN ECONOMY</li>
<li class="headerbullet"><img src="http://www.hispanicbusiness.com/_client_common/images/main/2012/footer_bullet.png"/></li>
<li><a rel="nofollow" href="http://www.hirediversity.com" target="_blank">CAREER NEWS</a> </li>
</ul>
</div><hr style="margin-top:4px"/>
Let's clean up some of that HTML and CSS :)
We can create the bullets using just the li parents for each link. The padding on #container li will space out the bullets evenly, however large of a gap you want.
Updated
The menu is centred by the combination of margin: auto; and a fixed width (in this case - width: 776px;.
Have a fiddle!
HTML
<div id="container">
<ul>
<li>
ARTS & ENTERTAINMENT
</li>
<li>
TECHNOLOGY
</li>
<li>
AUTO
</li>
<li>
SPORTS
</li>
<li>
NEWS BRIEFS
</li>
<li>
GREEN ECONOMY
</li>
<li>
CAREER NEWS
</li>
</ul>
</div>
CSS
* {
margin: 0;
padding: 0;
}
#container {
overflow: hidden;
}
#container ul {
margin: 10px auto;
width: 776px;
border-bottom: dotted 1px #CCC;
overflow: auto;
padding: 0 0 10px;
}
#container li:first-child {
list-style: none;
margin: 0 0 0 18px;
}
#container li {
float: left;
font-family:"Arial Narrow", Arial, sans-serif;
font-size: 0.8em;
padding: 0 30px 0 2px;
}
#container a:link {
color: #000;
text-decoration: none;
}
#container a:hover {
color: #F00;
text-decoration: underline;
}
You can justify your list elements by making you ul have text-align: justify. Then, make an :after element that has a width: 100% to trick it into thinking there is another line.
See here: (Sorry, I removed some of your CSS to make it easier to read.)
http://jsfiddle.net/ECf2u/
div#container{
width:1020px;
}
div#container ul {
width: 100%;
text-align: justify;
-webkit-padding-start:0px; /* reset chrome default */
}
div#container ul:after {
content: "";
width: 100%;
display: inline-block;
}
div#container ul li {
font-family: "Arial Narrow", Arial, sans-serif;
font-weight:bold;
font-size:12px;
text-align: center;
display: inline-block;
position: relative;
}
div#container A:link { COLOR: black; TEXT-DECORATION: none; font-weight: normal }
div#containerA:visited {
COLOR: #666;
TEXT-DECORATION: none;
font-weight: normal
}
div#container A:active {
COLOR: #666;
TEXT-DECORATION: none
}
div#container A:hover {
COLOR: #C00;
TEXT-DECORATION: none;
font-weight: none
}
Here is a simpler solution, using CSS3 flex.
It fully-justifies the menu items, distributing the space evenly around the bullets.
I couldn't figure out how to do the bullets without the extra empty <li><\li> elements.
Link to CodePen
.menu { font: 14px "Arial Narrow", Arial, sans-serif; list-style-type: none; padding:3px }
.menu a { color: black; text-decoration: none }
.menu a:visited, .menu a:active { color: #666 }
.menu a:hover { color: #c00 }
.menu { display:flex; justify-content:space-between; border: 1px solid black; border-width: 1px 0 }
.menu li:empty:after { content:"\2022" }
<ul class="menu">
<li>ARTS & ENTERTAINMENT</li><li></li>
<li>TECHNOLOGY</li><li></li>
<li>AUTO</li><li></li>
<li>SPORTS</li><li></li>
<li>NEWS BRIEFS</li><li></li>
<li>GREEN ECONOMY</li><li></li>
<li>CAREER NEWS</li>
</ul>

Padding error with <li> line wrap- trying to resolve while correctly maintaining left-border

I have a vertical ul as a nav menu. When a:hover is triggered, a border-left shows up at the edge of the screen and padding is adjusted so the text isn't displaced. Pretty common menu effect. Works well, except when user resizes their screen to the point where the nav menu items break into two lines- then there is no padding on the second line, pulling it to the left. I need to find a way to apply the padding equally to the whole li even if the line is broken, while keeping my border-left effect!
I have looked at some answers to similar problems on stackoverflow but they all seem to involve removing the padding from the li and applying it to the ul or containing element instead. If I do this, then I lose the positioning on my left border highlight- the border shows up right next to the text, and I can't figure out how to manipulate the padding on the border separate from the li to bump it back out!
Here's the css:
#middle_left ul {
list-style: none;
padding-top:5%;
font-family: 'Gill Sans', Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
font-size:1.5em;
}
#middle_left ul a {
padding-left:15px;
text-decoration: none;
color: #2e2f2a;
}
#middle_left ul a:hover {
padding-left:12px;
color: #81827f;
border-left: solid 3px #81827f;
}
And the HTML:
<div id="middle_left">
<ul>
<li>The Novel</li>
<li>Bio</li>
<li>Translation</li>
<li>Other Works</li>
</ul>
</div>
Thanks for any suggestions for how to tackle this!
Wrap the a in divs:
<div id="middle_left">
<ul>
<li><div>The Novel</div></li>
<li><div>Bio</div></li>
<li><div>Translation</div></li>
<li><div>Other Works</div></li>
</ul>
</div>
#middle_left ul {
list-style: none;
padding-top:5%;
padding-left: 15px;
font-family: 'Gill Sans', Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
font-size:1.5em;
}
#middle_left ul div{
padding-left:15px;
text-indent: -15px;
}
#middle_left ul div:hover{
padding-left:15px;
text-indent: -15px;
border-left: solid 3px #81827f;
}
#middle_left ul a {
padding-left:15px;
text-decoration: none;
color: #2e2f2a;
}
#middle_left ul a:hover {
padding-left:12px;
color: #81827f;
}
See here for example:
http://jsfiddle.net/6nz9F/2/
How about this?
CSS
#middle_left ul {
list-style: none;
padding-top: 5%;
padding-left:12px;
font-family: 'Gill Sans', Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
font-size: 1.5em;
}
#middle_left ul a {
display: block;
text-decoration: none;
color: #2e2f2a;
border-left: 3px solid transparent;
}
#middle_left ul a:hover {
color: #81827f;
border-left-color: #81827f;
}