So I'm trying to underline the <a>
elements of my header. The problem, I believe, is that for some reason jQuery isn't getting the proper width of the <a>
text, as it's in an embedded font.
UPDATE: Oddly, this is only occurring within Chrome and Safari, so Webkit browsers are having this issue.
Here's the relevant CSS:
*
{
padding: 0;
border: 0;
margin: 0;
}
a
{
text-decoration: none;
color: inherit;
cursor: pointer;
}
body
{
height: 100%;
margin: 0;
padding: 0;
}
body > #container
{
min-height: 100%;
position: relative;
height: 100%;
}
body > #container > header
{
width: 100%;
background-color: black;
color: white;
}
body > #container > header > #title
{
font-family: 'Shadows Into Light', cursive;
padding: 12px 0px 12px 30px;
font-size: 42px;
}
body > #container > header > #title > .navigation
{
font-family: 'Montserrat', sans-serif;
float: right;
display: inline;
}
body > #container > header > #title > .navigation > span
{
display: block;
float: left;
text-decoration: none;
font-size: 20px;
padding-left: 20px;
padding-right: 20px;
padding-top: 20px;
}
body > #container > header > #title > .navigation > #magic-line
{
position: absolute;
padding-top: 5px;
top: 60px;
left: 0;
background: white;
padding-left: 0px;
padding-right:0px;
}
body > #container footer
{
color: #3e606f;
text-align: center;
position: absolute;
bottom: 0;
width: 100%;
height: 40px;
}
Here's my header.html
<!DOCTYPE html>
<html>
<head>
<link href="css/header.css" media="screen" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="js/header.js"></script>
<link href='http://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>
<meta property="og:image" content="res/BigduckSe.png" />
</head>
<body>
<div id="container">
<header>
<div id="title">R.A.G.E.
<span class = "navigation">
<span class="current_page_item" id="home">
<a href="index.html">HOME</a>
</span>
<span id="about">
<a href="videos.html">ABOUT</a>
</span>
<span id="points">
<a href="#">POINTS</a>
</span>
<span id="schedule">
<a href="#">SCHEDULE</a>
</span>
<span id="swag">
<a href="#">SWAG</a>
</span>
</span>
</div>
</header>
</div>
</body>
And here's the all-important header.js
var ready1 = function() {
var $el, leftPos, newWidth,
$mainNav = $(".navigation");
if($("#magic-line").length){
}
else{
$mainNav.append("<span id='magic-line'></span>");
}
var $magicLine = $("#magic-line");
$magicLine
.width($(".navigation .current_page_item a").width())
.css("left", $(".current_page_item a").position().left)
.data("origLeft", $magicLine.position().left)
.data("origWidth", $magicLine.width());
$(".navigation span").hover(function() {
$el = $(this);
leftPos = $el.children("a").position().left;
newWidth = $el.children("a").width();
$magicLine.stop().animate({
left: leftPos,
width: newWidth
},200);
}, function() {
$magicLine.stop().animate({
left: $magicLine.data("origLeft"),
width: $magicLine.data("origWidth")
},200);
});
};
var resizeWindow = function() {
//adjusting the body size dynamically
var $headerfooter=$("header").height()+$("footer").height();
var $bodyheight=$(window).height()-$headerfooter;
$(".body").css("height",$bodyheight);
//adjusting position of wrapper dynamically
$("#wrapper").css("top",(.1*$bodyheight));
var $wrapperheight = .8*$bodyheight;
$("#wrapper").css("height",$wrapperheight);
};
$(window).load(ready1);
$(window).resize(ready1);
$(window).resize(resizeWindow);
I would put all of this on jsfiddle, but for some reason when I do, it formats properly. This only seems to happen when testing on an actual browser. In addition, you can see I'm using the window.load instead of document.ready, as I've read that could be the cause of the incorrect width, but it's not helping at all.
Also note, the second I resize the window, the underline properly works.
If anyone could help, it would be greatly appreciated.