Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6825615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:03:15+00:00 2026-05-26T22:03:15+00:00

Im doing a nav. Its a ul list. the ‘a’ tags and ‘span’s are

  • 0

Im doing a nav.

Its a ul list. the ‘a’ tags and ‘span’s are in the same space and the span contains an image that is hidden.
The image does fadeIn/fadeOut which is successful.
Im trying to set the width of the img/span to the width of the li(the parent)

i cant seem to friggin do it. please help.

<ul id="nav">
    <li><a href="#">Web<br />Design</a><span><img src="images/nav-over.png"  height="100px" /></span></li>
    <li><a href="#">Graphic<br />Design</a><span><img src="images/nav-over.png"  height="100px" /></span></li>
    <li><a href="#">Our<br />Work</a><span><img src="images/nav-over.png" height="100px" /></span></li>
    <li><a href="#">SEO</a><span><img src="images/nav-over.png" height="100px" /></span></li>
</ul>

this was kinda on the right path…

var h = $('#nav li img').parent().height();
var w = $('#nav li img').parent().width();
$('#nav li img').width(w).height(h);

but it set all of the #nav li span height and width the same and not from the parent…

then i’ve tried this :

$('#nav li span').each(function(){$(this).parent().width()});
$('#nav li span img').each(function(){$(this).parent().width()});

which i know is poorly structured but i was just testing. but no it didn’t work…

so for each #nav li span and #nav li img i want to set the width to the corresponding parent(li) width.

i think i explained this correctly. lol. thanks.

heres the css

 #nav {
    list-style:none; width:608px; height:100px; display:block; padding:0; margin:0; position:relative
}
#nav li {
    background:url(images/nav-div.jpg) right top no-repeat; float:left; text-align:center;height:100px;
}
#nav li a {
    color:#565555; font-size: 18px; letter-spacing:10px; line-height:25px; text-transform:uppercase; text-decoration:none;height:100px; display:block; padding:0 19px 0 19px; position:relative; top:0; left:0;z-index:900
}
#nav li a:hover {
    color:#eaeaea   
}

#nav li span {
    position:relative; top:-100px; left:0; z-index:800; opacity:0.0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:03:15+00:00Added an answer on May 26, 2026 at 10:03 pm

    Use .width() where you have .each(), and use .closest("li") instead of .parent(), and don’t forget the return statements:

    $('#nav li span img').width(function () { return $(this).closest("li").width(); });
    $('#nav li span img').height(function () { return $(this).closest("li").height(); }); 
    

    http://jsfiddle.net/KzhgQ/

    Edit: Here’s a more efficient version that prevents looping the images twice (thanks natedavisolds) :

    $('#nav li span img').each(function () {
        var img = $(this);
        var listItem = img.closest("li");
        img.width(listItem.width()).height(listItem.height());
    });
    

    http://jsfiddle.net/KzhgQ/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does UINavigationBar retain nav items pushed onto its stack? In other words, after doing
When doing TDD , how to tell that's enough tests for this class /
I'm trying to use Twitter Bootstrap's dropdown menu in its top nav bar. You
I have some code (written by another developer) that is doing AJAX page loading
What I'm doing: I'm creating a sample app that shows how to incorporate Kendo
I have built a sidebar navigation that collapses & expands when the nav titles
The context: I am working on an app that maintains a list of contacts
For a current project I'm doing I'm using PHP includes for my nav bar
Now what I am doing is having a text nav but then on hover
I just updated my app so that it's a universal app. In doing so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.