I am trying to complete a simple function, what is wrong with this code?
Basically I'm trying to overlay a span, with the exact same width as its containing <a> link. So I want the black span box (in example) as wide as the containing grey box.
function vg() {
if ($("body").hasClass("work-page")) {
var a = $(".projTitle").width();
$(".subtitle").css({
width: a + "px",
})
}
li {
position:relative;
}
li a.projTitle {
display: inline-block;
margin: auto 15px auto 0px;
line-height: 100px;
height: 100px;
overflow: hidden;
outline: 0;
border: 0;
font-weight:300;
background:#ccc;
font-size:18px;
}
li .subtitle {
font-size:10px;
font-family: 'Titillium Web', sans-serif;
font-weight: 500;
opacity: .8;
display: block;
margin-left: 0px;
line-height: 17px;
margin-right: 0px;
height: 100px;
margin-bottom: 0px;
position: absolute;
top: 0px;
padding-top: 83px;
width:auto;
background:#000;
color:#fff;
}
<html>
<body class="work-page">
<ul>
<li>
<a class="css3Animate projTitle" href="work/project/index.html">The Project<span class="css3Animate subtitle">subtext span</span></a>
</li>
</body>
</html>