Get background-image of div to link to page

Hello,
I have a div which contains my all the content in my header; thus, it is given the id header. I have given it a background image. I want that background image to go to a page on click of a certain area of that background image.
So kind of like how one can click on part of an <img /> tag to link to a file using hot maps or image maps…

Can someone help me code using css, html, javascript, any web-language or combinations thereof
to have certain areas of the background image of a div-tag, placed by my stylesheet, link to specific pages.

I hope I explained this well enough. Thanks in advance and I hope someone can help do this soon.

Please reply with any questions, comments, or solutions

Regards,
Team 1504

:wave: Thank you guys for everything especially Paul.
I appreciate your help! Not only did you guys help me with my problem, but also introduced me to neew concepts which I hope to extend my understanding of.
Thanks:weee:

Off Topic:

Beginners method or some other? I use Fridrich (full OLL/PLL) (took me approximately 3 months to learn, I know approximately …84 (57 OLL+21PLL=78…and the rest are F2L algorithmic approaches to stuckpeices / other stuff ;))

Ok - so you still want the parts of the penguin that pops out from behind the nav to be a link. That should be ok as long as the nav has a higher z-index as mentioned before. (A minor issue is that it may confuse someone with a shaky hand as they may may click outside the menu by mistake and similarly when moving from the main nav to the sub.)

do you have any tips on how I can avoid using <br /> and   but still having spacing and breaks.
For breaks would I use separate <p> <p> paragraphs?
And for spacing would I use padding. Well for spacing I mean, how would I have more than one space between two words besides

<p>This has  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; six spaces </p>

If you ever find yourself entering more than one or two non breaking spaces then it’s 99% certain that there is a better way to do this. Once you put the spaces in your html they are there for ever and cannot be changed.

If you want space between the two words then firstly I would ask why? If it was for a list then you should be using a list. If its for visual effect only then you could just wrap a span around each word and apply some padding/margin to the span to make the space that you require. Or if the words were meant to have importance then use the strong element. This would also make it possible for you to change/remove the space very easily should you wish to do it later - just by changing the stylesheet.

It is unlikely that you would just want space between 2 random words so think about the context and use the most semantic element for the job in hand.

Vertical margin can be created by applying margins (or padding) to existing elements. You never need breaks to do this and breaks between paragraphs and divs is just wrong. Breaks are used rarely in most pages because existing elements will do the job just fine. For things like form controls, addresses and poems then breaks are fine but when you want a margin between elements or paragraphs then use a margin :slight_smile:

Regarding the not giving you a link to the code for my menu, I am sorry for wasting your time.

I didn’t mean it sound like that - it was just that you left out some important information :slight_smile:

So how could I remove this space? I tried padding-bottom, but that seems to do nothing and padding-top pushes it down more as it should.

Thanks in advance!! :slight_smile:

The space above the subnav is because you have set the menu to 38px high and added 38px padding but it only looks to be 36px high.

Just copy and paste this to test:


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<link rel="stylesheet" href="global\
av\\styles\
av.css" type="text/css" />
</head>
<body id="home">
<style type="text/css">
/* navigation container */
#globalheader {
    width: 982px;
    height: 36px;
    margin:0 auto;
    position: relative;
    top:120px;
    z-index: 9998;
}
#globalheader #globalnav {
    margin: 0;
    padding: 0;
    zoom: 1;
    width: 100%;
}
#globalheader #globalnav:after {
    content: " ";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}


#globalheader #globalnav li {
    display: inline;
}
#globalheader #globalnav li a {
    float: left;
    width: 103px;
    height: 0;
    padding-top: 36px;
    overflow: hidden;
    background-image: url(http://team1504.com/projects/navigation/global/nav/images/globalnavbg.png);
    _background-image: url(http://team1504.com/projects/navigation/global/nav/images/globalnavbg.gif);
    background-repeat: no-repeat;
}
#globalheader #globalsearch {
    background-image: url(http://team1504.com/projects/navigation/global/nav/images/globalnavbg.png);
    _background-image: url(http://team1504.com/projects/navigation/global/nav/images/globalnavbg.gif);
    background-repeat: no-repeat;
}
/* default styling */
#globalheader #globalnav li#gn-home a {
    background-position: 0 0;
}
#globalheader #globalnav li#gn-about a {
    background-position: -103px 0;
}
#globalheader #globalnav li#gn-groups a {
    background-position: -206px 0;
}
#globalheader #globalnav li#gn-media a {
    background-position: -309px 0;
}
#globalheader #globalnav li#gn-outreach a {
    background-position: -412px 0;
}
#globalheader #globalnav li#gn-resources a {
    background-position: -515px 0;
}
#globalheader #globalnav li#gn-sponsors a {
    background-position: -618px 0;
}
#globalheader #globalnav li#gn-support a {
    background-position: -721px 0;
}
/* on hover */
#globalheader #globalnav li#gn-home a:hover {
    background-position: 0 -38px;
}
#globalheader #globalnav li#gn-about a:hover {
    background-position: -103px -38px;
}
#globalheader #globalnav li#gn-groups a:hover {
    background-position: -206px -38px;
}
#globalheader #globalnav li#gn-media a:hover {
    background-position: -309px -38px;
}
#globalheader #globalnav li#gn-outreach a:hover {
    background-position: -412px -38px;
}
#globalheader #globalnav li#gn-resources a:hover {
    background-position: -515px -38px;
}
#globalheader #globalnav li#gn-sponsors a:hover {
    background-position: -618px -38px;
}
#globalheader #globalnav li#gn-support a:hover {
    background-position: -721px -38px;
}
/* On clicked or pressed by mouse */
#globalheader #globalnav li#gn-home a:active {
    background-position: 0 -76px;
}
#globalheader #globalnav li#gn-about a:active {
    background-position: -103px -76px;
}
#globalheader #globalnav li#gn-groups a:active {
    background-position: -206px -76px;
}
#globalheader #globalnav li#gn-media a:active {
    background-position: -309px -76px;
}
#globalheader #globalnav li#gn-outreach a:active {
    background-position: -412px -76px;
}
#globalheader #globalnav li#gn-resources a:active {
    background-position: -515px -76px;
}
#globalheader #globalnav li#gn-sponsors a:active {
    background-position: -618px -76px;
}
#globalheader #globalnav li#gn-support a:active {
    background-position: -721px -76px;
}
/* On selected */
#globalheader.home #globalnav li#gn-home a:hover {
    background-position: 0 0;
    cursor: default;
}
#globalheader.store #globalnav li#gn-about a {
    background-position: -103px -114px !important;
}
#globalheader.mac #globalnav li#gn-groups a {
    background-position: -206px -114px !important;
}
#globalheader.ipod #globalnav li#gn-media a {
    background-position: -309px -114px !important;
}
#globalheader.iphone #globalnav li#gn-outreach a {
    background-position: -412px -114px !important;
}
#globalheader.ipad #globalnav li#gn-resources a {
    background-position: -515px -114px !important;
}
#globalheader.itunes #globalnav li#gn-sponsors a {
    background-position: -618px -114px !important;
}
#globalheader.support #globalnav li#gn-support a {
    background-position: -721px -114px !important;
}
/* GLOBAL SEARCH */
#globalsearch {
    width: 158px;
    height: 38px;
    position: absolute;
    top: 0;
    right: 0;
    background-position: 100% 0;
    background-repeat: no-repeat;
}
#globalsearch.active {
    background-position: 100% -38px;
}
#globalsearch input.g-prettysearch, #globalsearch .search-wrapper input.g-prettysearch {
    background: url(http://team1504.com/projects/navigation/global/nav/images/searchfield_repeat.png) center top repeat-x;
}
#globalsearch input.g-prettysearch {
    width:140px;
    height: 16px;
    margin-top: 9px;
    margin-left: 8px;
}
#globalsearch .search-wrapper {
    position: relative;
    width: 140px;
    margin-top: 9px;
    margin-left: 8px;
}
#globalsearch .search-wrapper input.g-prettysearch {
    width: 110px;
    margin-left: 17px;
*margin-top:-1px;
*margin-right:-2px;
*margin-left:7px;
}
#globalsearch .search-wrapper .left, #globalsearch .search-wrapper .left {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 20px;
    height: 19px;
    background: url(http://team1504.com/projects/navigation/global/nav/images/searchfield_leftcap.png) left top no-repeat;
}
#globalsearch .search-wrapper .right {
    display: block;
    position: absolute;
    right: 0;
    top: 0;
    width: 10px;
    height: 19px;
    background: url(http://team1504.com/projects/navigation/global/nav/images/searchfield_rightcap.png) right top no-repeat;
}
#globalsearch .search-wrapper.empty.blurred input {
    color: #7E7E7E;
}
#globalsearch .search-wrapper .reset {
    position: absolute;
    width: 11px;
    height: 11px;
    overflow:hidden;
    z-index: 1;
    right: 4px;
    top: 4px;
    background: url(http://team1504.com/projects/navigation/global/nav/images/close.gif);
    display: block;
    cursor: pointer;
    _cursor:hand;
}
#globalsearch .search-wrapper.empty .reset {
    display: none;
}
#globalsearch .search-wrapper input.g-prettysearch {
    position: absolute;
    width: 110px;
    top: 0;
    right: 10px;
    border: 0px;
    margin: 0;
    padding: 3px 0 0 0;
    font: 11px "Lucida Grande", Arial, sans-serif;
}
#globalsearch label .prettyplaceholder {
    display: block;
    overflow: hidden;
    text-indent: -9999px;
    height: 0;
    width: 0;
}
#globalsearch input[type=search].not-round {
    background: #ABABAB;
    height: 19px;
    outline: none;
    -webkit-border-radius: 9px;
    -webkit-border-image: url(http://team1504.com/projects/navigation/global/nav/images/searchfield_border.png) 2 2 2 2 stretch stretch;
    width: 133px;
}
/* SHORTCUTS */
#sp-results {
    position: absolute;
    margin-right: -2px;
    margin-bottom: 0;
    margin-left: 0;
    top: 61px;
    left: 160px;
    height: 0;
}
#sp-results .inside {
    width: 328px;
    height: auto;
    position: absolute;
    top: 0;
    right: 0;
    line-height: 1px;
    font-size: 1px;
}
#sp-results .resultCat {
    position: relative;
    color: #f6f6f6;
    background: #919191;
    width: 308px;
    height: 8px;
    margin: 0;
    padding-bottom: 12px;
    width: 302px;
    font: 11px "Lucida Grande", "Lucida Sans Unicode", Arial, Verdana, sans-serif;
    font-weight: bold;
    border: 1px none #fb6bff;
}
ul.sp-results {
    background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_bg_mid_grey.png) repeat-y 0 0;
    _background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_bg_mid_grey.gif) repeat-y 0 0;
    color: #333;
    padding: 0 3px;
    margin: 0;
    _margin-right: 5px;
    width: 328px;
    text-align: left;
    font: 10px/14px "Lucida Grande", "Lucida Sans Unicode", Arial, Verdana, sans-serif;
}
ul.sp-results li {
    display: block;
    margin: 0 0 -3px 0;
    padding: 5px 10px;
    list-style-type: none;
    height: 4.6em;
    position: relative;
    border-left: 1px solid #919191;
    border-right: 1px solid #919191;
    width: 300px;
}
ul.sp-results li.viewall {
    width: 308px;
    height: 20px;
    text-align: right;
    color: #000;
    position: absolute;
    bottom: -30px;
*bottom: -27px;
    left: 0px;
    background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_bg_foot_grey.png) no-repeat left bottom;
    _background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_bg_foot_grey.gif) no-repeat left bottom;
    border-style: none;
}
ul.sp-results li.viewall a {
    color: #fff;
    padding-right: 23px;
    background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_arrow.gif) no-repeat 99% 50%;
    padding-top: 3px;
    padding-bottom: 3px;
    font: bold 11px "Lucida Grande", "Lucida Sans Unicode", Arial, Verdana, sans-serif;
}
ul.sp-results li.hoverli {
    background: #b7b7b7 none repeat-x;
    color: #fff;
    cursor: pointer;
}
ul.sp-results li.hoverli h4 a {
    color: #fff;
}
ul.sp-results li.hoverli p {
    color: #f1f1f1;
}
ul.sp-results li span.text {
    display: block;
    position: absolute;
    left: 68px;
    width: 240px;
}
ul.sp-results li h4 {
    margin: 0;
    font-size: 11px;
    font-weight: bold;
}
ul.sp-results li p {
    margin: 0;
    font-size: 10px;
    overflow: hidden;
    height: 2.7em;
    color: #555;
}
ul.sp-results li a {
    color: #606060;
    text-decoration: none;
    height: auto;
    width: auto;
    overflow: visible;
    background: none;
}
ul.sp-results li img, ul.sp-results li .replacementimg {
    position: absolute;
    left: 10px;
    width: 46px;
    height: 46px;
}
ul.sp-results li h4 a {
    color: #191919;
}
ul.sp-results li.viewall.hover {
    background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_bg_foot_grey.png) no-repeat bottom left;
}
#sp-search-spinner {
    position: absolute;
    top: 13px;
    right: 14px;
    z-index: 10;
    display: none;
}
#sp-search-cancel img {
    cursor: pointer;
}
#sp-results .firstCat {
    position: absolute;
    top: -25px;
    left: 0;
    width: 308px;
    height: 8px;
    background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_bg_head_grey.png) no-repeat left top;
    _background: url(http://team1504.com/projects/navigation/global/nav/images/shortcuts_bg_head_grey.gif) no-repeat left top;
}
#sp-result-none.viewall {
    bottom: -27px;
*bottom: -27px;
}
#sp-result-none.viewall a {
    font-size: 10px;
}
.subnavHolder {
    background:#000;
    color:#fff;
    padding:5px 19px 5px 19px;
    font-family:Arial, Helvetica, sans-serif;
    font-size:0.827em;
}
.subnavElement {
    display:inline;
}

#header {
    position:relative;
    background:url(http://www.pmob.co.uk/temp/images/team15.png) no-repeat 0 0;
    width:1000px;
    height:190px;
    margin:auto;
}
#header ul.hotlink {
    margin:0;
    padding:0;
    list-style:none;
    position:absolute;
    top:0;
    left:0;
    z-index:2;
}
#header ul.hotlink li {
    position:absolute;
    text-indent:-999em;
}
#header ul.hotlink li a {
    display:block;
    width:100%;
    height:100%;
    outline:0;
}
#header ul.hotlink li a:hover {
    z-index:99;
}
ul.hotlink li.sitepoint {
    top:62px;
    left:0;
    width:144px;
    height:126px;
}
ul.hotlink li.w3schools {
    top:0px;
    left:133px;
    width:498px;
    height:126px;
}
ul.hotlink li.google {
    top:82px;
    left:648px;
    height:37px;
    width:347px;
}
.subnavHolder li{float:left}
.subnavHolder{overflow:hidden;}

</style>
<script src="http://team1504.com/projects/navigation/global/nav/scripts/shortcuts.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript"> 
    var searchSection = 'global';
    var searchCountry = 'us';
</script>
<div id="header">
    <ul class="hotlink">
        <li class="sitepoint"><a title="Sitepoint" href="http://www.sitepoint.com">Sitepoint</a></li>
        <li class="w3schools"><a title="W3Schools" href="http://www.w3schools.com">W3Schools</a></li>
        <li class="google"><a title="google" href="http://www.google.com">Google</a></li>
    </ul>
    <div id="globalheader" class="apple">
        <ul id="globalnav">
            <li id="gn-home"><a href="http://apple.com/">Home</a></li>
            <li id="gn-about"><a href="http://store.apple.com">About</a></li>
            <li id="gn-groups"><a href="http://apple.com/mac/">Groups</a></li>
            <li id="gn-media"><a href="http://apple.com/ipod/">Media</a></li>
            <li id="gn-outreach"><a href="http://apple.com/iphone/">Outreach</a></li>
            <li id="gn-resources"><a href="http://apple.com/ipad/">Resources</a></li>
            <li id="gn-sponsors"><a href="http://apple.com/itunes/">Sponsors</a></li>
            <li id="gn-support"><a href="http://apple.com/support/">Blog</a></li>
        </ul>
        <div id="globalsearch">
            <form action="http://searchcgi.apple.com/cgi-bin/sp/nph-searchpre11.pl" method="post" class="search" id="g-search">
                <div>
                    <input type="hidden" value="utf-8" name="oe" id="search-oe">
                    <input type="hidden" value="p" name="access" id="search-access">
                    <input type="hidden" value="us_only" name="site" id="search-site">
                    <input type="hidden" value="lang_en" name="lr" id="search-lr">
                    <label for="sp-searchtext"><span class="prettyplaceholder">Search</span>
                    <input type="search" name="q" id="sp-searchtext" class="g-prettysearch applesearch" accesskey="s">
                    </label>
                </div>
            </form>
            <div id="sp-results">
                <div class="inside"></div>
            </div>
        </div>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="http://team1504.com/projects/navigation/hybridCode3.js"></script>
        <div id="subNavContent"></div>
        <div id="subNavContainer"></div>
    </div>
</div>
</body>
</html>


** Edit** P.S. Also,
The above has the highest priority, but how can I learn how to use the coordinates to make anchors shaped as boxes so I know what area it is covering. Is there a GUI or graphical way of me being able to see the achor area as I type in coordinates like hotspots in dreamweaver or is it guess and check?
For example, If you created an achor, as you did in the header image, to cover the red life-saver in this image what would the coordinates or the positioning numbers be so that I could have a li that has an <a>, whic links it to bbc.co.uk? As you did it for the header parts?
Thanks and Regards!
I just copied the image into Fireworks and drew boxes around the text and took the co-ordinates from Fireworks. You should be able to do the same in any paint package. It just takes a couple of seconds to do.

The top left of the image is 0,0 just like it will be in the page when you set position:relative on the immediate parent. Draw a box around the part that you are interested in and the paint package display the width,height and x,y co-ordinates for you.

Hope that helps :slight_smile:

PS your demo isn’t working in Firefox because the css file is missing due to the back slashes you used in the href instead of forward slashes.

OK - before we start there are two things you must never do:

Never add inline styles to the elements as that leads to utter confusion and impossible to maintain, fix or debug layouts.

Secondly never use breaks to make space or to move things around.

Regarding your problem all you need to do with the code I gave you was to isolate the css I gave you so that it did not affect any existing elements - which you neglected to mention.

Just add a class to the ul and then change the css accordingly.


#header {
    position:relative;
    background:url(images/team15.png) no-repeat 0 0;
    width:1000px;
    height:190px;
    margin:auto;
}
#header[B] ul.hotlink[/B] {
    margin:0;
    padding:0;
    list-style:none;
    position:absolute;
    top:0;
    left:0;
    z-index:2;
}
#header [B]ul.hotlink[/B] li {
    position:absolute;
    text-indent:-999em;
}
#header [B]ul.hotlink[/B] li a {
    display:block;
    width:100&#37;;
    height:100%;
    outline:0;
}
#header [B]ul.hotlink [/B]li a:hover {
    z-index:99;
}
[B]ul.hotlink[/B] li.sitepoint {
    top:62px;
    left:0;
    width:144px;
    height:126px;
}
[B]ul.hotlink[/B] li.w3schools {
    top:0px;
    left:133px;
    width:498px;
    height:126px;
}
[B]ul.hotlink[/B] li.google {
    top:82px;
    left:648px;
    height:37px;
    width:347px;
}




<div id="header">
    <ul [B]class="hotlink"[/B]>
        <li class="sitepoint"><a title="Sitepoint" href="http://www.sitepoint.com">Sitepoint</a></li>
        <li class="w3schools"><a title="W3Schools" href="http://www.w3schools.com">W3Schools</a></li>
        <li class="google"><a title="google" href="http://www.google.com">Google</a></li>
    </ul>
</div>


The code is now completely independent of any other list items in that section and any other issues will be of your own making.

I’d need to see the full code (css/html) for the menu to see where you want it positioned (preferably a link to the page). It’s no good omitting the most important details and then telling us afterwards as that wastes everybodies time :slight_smile:

I see that your navbar looks as though it is now positioned on top of the penguin that you wanted to be a link? That is really odd because there is only a little bit of the penguin visible now and makes no sense to be a link.

To move the subNavContainer downwards you should use a margin-top on it assuming there is no floated content above or use a margin-bottom on the element above.

To keep the subnavContainer on top you need to apply a higher z-index to #subNavContainer than the other elements in that section. If it is not a positioned element then add position:relative so that z-index takes effect.


[COLOR=#009900][COLOR=#cc0000]#subNavContainer{z-index:99;position:relative;}[/COLOR][/COLOR]

To fix your issues more easily we would need a link to the page or at least to working example of the menu and all its contents :slight_smile:

I know inline styling is bad, I apologise it is a bad habit of mine… sorry
With the not that much area of the penguin remaining for it to be a hot link… I think there is. Because when the cursor is focusing on navigation it creates the sub Nav, which covers the bottom of the penguin yes,
As seen here
but on focus or hover of anything besides a navigation element reveals the majority of the penguin.
As seen here

The new code you gave me using the ud hotlink for the ul to separate it worked and now I do not have to use inline styling. Thanks.

do you have any tips on how I can avoid using <br /> and   but still having spacing and breaks.
For breaks would I use separate <p> <p> paragraphs?
And for spacing would I use padding. Well for spacing I mean, how would I have more than one space between two words besides

<p>This has  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; six spaces </p>

Regarding the not giving you a link to the code for my menu, I am sorry for wasting your time.
I uploaded just my navigation to my server. It works fine in google chome, but in firefox the background images show; however, I am pretty sure I know why and I put this isolated menu together just to share it with you. Also one could use google chrome dev tools to examine my code and access the linked files.
my Navigaiton

So on hover the jQuery i wrote (hybridCode3.js) writes a subNavigation, in the blank div tags identified as #subNavContent and #subNavContainer at lines 55 & 56

How my navigation is ordered is:
general container
navigation container
navigation
close navigation container
search container
search
close search container
close general container
*/This is the space i think /
sub Navigation container
/
the jQuery writes a inline unordered list for the subNavigation here */
close sub Navigation container

So, as one can see here

A slightly small space appears which seems to separate the main Navigation and the sub Navigation by showing the background-- in the screenshot it is the penguin and title logo
In the uploaded version it is just the white body colour fill

So how could I remove this space? I tried padding-bottom, but that seems to do nothing and padding-top pushes it down more as it should.

Thanks in advance!! :slight_smile:

** Edit** P.S. Also,
The above has the highest priority, but how can I learn how to use the coordinates to make anchors shaped as boxes so I know what area it is covering. Is there a GUI or graphical way of me being able to see the achor area as I type in coordinates like hotspots in dreamweaver or is it guess and check?
For example, If you created an achor, as you did in the header image, to cover the red life-saver in this image what would the coordinates or the positioning numbers be so that I could have a li that has an <a>, whic links it to bbc.co.uk? As you did it for the header parts?
Thanks and Regards!

Not tpo speak for Paul but all PHP questions should generally have a thread made (and last time I checked, Paul doesn’t know thatm uch PHP (no offense to him if there is any there :p)

The PHP forum here has a lot of gurus who can help you out with any issue :tup: :slight_smile:

Thank you very much paul.
Isn’t it early in the morning in England, like 1 am?
I appreciate you helping me even more if your working at this time, it is just your profile said you were in hampshire.
Anyhow, Thanks and I will be more than happy to send you a link of the finished site.

Also do you have any PHP experience, by which I mean could i pm you a question on php i had?

Regards,
Team 1504

Thanks ryan. Ill try to post in the php section sometime.
Also tip of my hat to your rubix cube time. mine is 1:03

Thank you Paul, Eric, and Rayzur for helping me with this. Thank you for helping me with the css problem i had i appreciate your guys’ help.

However why implementing it on my website, i encountered some issues. I think I tackled the majority of the problem but there was a minor thing that I was hoping you guys could help me with.

So um i’m just going to explain the problem, my solution, and the minor problem that derived from my solution which i can hope you can help me with…

Inside the #header div tag, which i talked about before, i have my navigation menu. This is a complex navigation menu; therefore, I have not attached it’s html or css, but can if it would help.
But it is basically like this:

<div id="headerContainer">
<div id="header">

     <li class="sitepoint" style="position:absolute;"><a title="Home"       href="http://team1504.com"></a></li>
<li class="w3schools" style="position:absolute;"><a title="Home" href="http://team1504.com"></a></li>
<li class="google" style="position:absolute;"><a title="Home" href="http://team1504.com"></a></li>

     <div id="navigationContianer"> <!--Hold Search & Navigation inline -->
         <div id="global-Navigation"></div>
         <div id="search"></div>
     </div>
</div>
<div id="subNavContainer"></div>
</div>

When i added the css code Paul gave me, for the hot spot links in the css background of the #header div, it negated the css of my navigation menu or at least messed it up.

The code Paul gave me:

<style type="text/css">

#header {
            position:relative;
            background:url(assets/media/images/navigation/header.png) no-repeat 0 0;
            width:1000px;
            height:190px;
            margin:auto;
}

#header ul {
                margin:0;
                padding:0;
                list-style:none;
                position:absolute;
                top:0;
                left:0;
                z-index:2;
}

#header li {
               /*position:absolute; */
               text-indent:-999em;
}

#header li a {
                  display:block;
                  width:100&#37;;
                  height:100%;
                  outline:0;

}

#header li a:hover {
                    z-index:99;
}

li.sitepoint {
                top:62px;
                left:0;
                width:144px;
                height:126px;
}

li.w3schools {
                  top:0px;
                  left:133px;
                  width:498px;
                  height:126px;
}

li.google {
             top:82px;
             left:648px;
             height:37px;
             width:347px;
}
</style>

As seen in the attachment cssProblem.jpg

What it looked like before I added the code is shown in cssNotAdded.jpg

I fixed the problem by seeing which style element conflicted with my navigation. I found that upon deletion of the 22nd line of the css,

position:absolute; 

for #header li {} , the navigation reappeared properly but only the link anchor for the penguin worked. So I added the styling just in the <li> tags the following

<li class="sitepoint" style="position:absolute;"><a title="Home" href="http://team1504.com"></a></li>
<li class="w3schools" style="position:absolute;"><a title="Home" href="http://team1504.com"></a></li>
<li class="google" style="position:absolute;"><a title="Home" href="http://team1504.com"></a></li>

Now the three <li> and anchor tags are in the proper positions and work. As well as the main-navigation, which is inside the #header div as well.

My problem occurs with some positioning. On hover of each of my navigation elements a corresponding subNav appeared underneath.
I had the container that my subNav is placed in on hover right underneath the navigation’s container. With the addition if the three <li> tags the subNav container; & therefore subNav when written in the container, is slightly higher than it should be— as seen in this screen shot: notLowEnough.gif

It appears behind the main navigation because the main navigation’s z index is higher because it has a higher importance than the sub navigation.
Anyhow, So my problem comes to positioning the sub nav where it belongs. If I use one <br /> tag it is not enough and two <br /> tags are too much…
I am speaking about putting the line breaks here towards the end of this code snippet:

<div id="headerContainer">
<div id="header">

    <li class="sitepoint" style="position:absolute;"><a title="Home"       href="http://team1504.com"></a></li>
    <li class="w3schools" style="position:absolute;"><a title="Home" href="http://team1504.com"></a></li>
    <li class="google" style="position:absolute;"><a title="Home" href="http://team1504.com"></a></li>

     <div id="navigationContianer"> <!--Hold Search & Navigation inline -->
         <div id="global-Navigation"></div>
         <div id="search"></div>
     </div>
</div>
<br/>
<br/>/* 2 line-breaks push it down too much */
<div id="subNavContainer"></div>
</div>

As seen in 2BR.gif
So is there a way i can use one and a half <br /> or padding or some other positioning that will always place by subNav directly below the main navigation. So it looks like it did before I added the <li> tags
as seen in working.gif

I hope you can help me get my header styled correctly in the proper positioning and have the hotspots anchors working! :slight_smile:

If you need any further explanation or have any comments, just ask :slight_smile:

Again my utmost gratitude to you guys thus far, thanks in advance,and Regards, Team 1504

Hi Ray,

Yes I didn’t get around to implementing that bit :slight_smile: I was going to change the absolute positioning to be on the anchor itself (and not the list element) and then then raise the z-index on hover so that that if there were any overlaps of other anchors the current one stays highlighted. It’s a trick I use where there are overlaps and the current item stays hovered even when you pass over the rectangle of the next link.

It could be changed to li:hover instead but we then just lose ie6.

If you want to put a little more work in you could do irregular shaped anchors (for the pinguen etc). http://www.visibilityinherit.com/code/irregular-shaped-anchor.php

I just knocked up a quick demo of the second method I mentioned above and you can find it here:

http://www.pmob.co.uk/temp/team15-2.htm

It uses a double image so that all states are preloaded and manipulates the background position on hover to reveal the highlighted image.

Yes I added the colours in as a last thought but forgot to remove the red from the original list declaration which had more weight.

Your image can be done almost exactly with the code I just gave you. I just changed the positioning to match the elements.

You can see a live version here:
http://www.pmob.co.uk/temp/team15.htm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#header {
    position:relative;
    background:url(images/team15.png) no-repeat 0 0;
    width:1000px;
    height:190px;
    margin:auto;
}
#header ul {
    margin:0;
    padding:0;
    list-style:none;
    position:absolute;
    top:0;
    left:0;
    z-index:2;
}
#header li {
    position:absolute;
    text-indent:-999em;
}
#header li a {
    display:block;
    width:100%;
    height:100%;
    outline:0;
}
#header li a:hover {
    z-index:99;
}
li.sitepoint {
    top:62px;
    left:0;
    width:144px;
    height:126px;
}
li.w3schools {
    top:0px;
    left:133px;
    width:498px;
    height:126px;
}
li.google {
    top:82px;
    left:648px;
    height:37px;
    width:347px;
}
</style>
</head>
<body>
<div id="header">
    <ul>
        <li class="sitepoint"><a title="Sitepoint" href="http://www.sitepoint.com">Sitepoint</a></li>
        <li class="w3schools"><a title="W3Schools" href="http://www.w3schools.com">W3Schools</a></li>
        <li class="google"><a title="google" href="http://www.google.com">Google</a></li>
    </ul>
</div>
</body>
</html>


We can only do rectangular areas and its best that they don’t overlap much but the example in your header are pretty much separate anyway.

Of course you could split your header into three and apply each as a background to the anchor. That would allow you to create a double image for each anchor that could rollover on hover to highlight the link and give more of a clue that it was a link. Of course that’s a lot more work and you would need to create another version of your header with a highlighted state.

Hi Welcome to Sitepoint :slight_smile:

If you just want some square areas of the image to be linkable then all you need to do is absolute position an anchor over the part of the image you want to be clickable.

This would involve adding position:relative to the #header div to act as a stacking context for the absolutely placed children.

Assuming the header div had a background image you could do something roughly like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#header {
    position:relative;
    width:960px;
    margin:auto;
    height:200px;
    background:#fcc;
}
#header ul {
    margin:0;
    padding:0;
    list-style:none;
    position:absolute;
    top:0;
    left:0;
    z-index:2;
}
#header li {
    position:absolute;
    width:100px;
    height:50px;
    background:red;
    text-indent:-999em;
}
#header li a {
    display:block;
    width:100&#37;;
    height:100%;
}
li.link1 {
    top:10px;
    left:400px;
    background:green
}
li.link1 {
    top:120px;
    left:300px;
    height:20px;
    background:blue
}
li.link2 {
    top:140px;
    left:500px;
    height:30px;
    background:teal
}
li.link3 {
    top:130px;
    left:700px;
    height:70px;
    background:yellow;
}
li.link4 {
    top:20px;
    left:800px;
    height:40px;
    background:green
}
</style>
</head>
<body>
<div id="header">
    <ul>
        <li class="link1"><a href="#">Link 1</a></li>
        <li class="link2"><a href="#">Link 1</a></li>
        <li class="link3"><a href="#">Link 1</a></li>
        <li class="link4"><a href="#">Link 1</a></li>
    </ul>
</div>
</body>
</html>


Hello Paul,
I think I understand the code you posted. Were each of the inner rectangles supposed to be different colours? Because they are all a darker red, while the header div is a washed out red…

Anywho, I am having trouble relating this with what I wanted to do, but your code is something I did not know one could do and is interesting…

so, suppose my code is this:


    <html>
    <head>
     <title>
     Parts of background, can they link?
      </title>
      
       <style type="text/css">
         #header{
             background:url(header.png) no-repeat;
             width:1000px;
              height:190px;
             }
       </style>
     </head>
      <body>
        <div id="'header">
        </div>
     </body>
     </html>

So as you can see with the attached image, which is header.png, can I have it so that certain parts of the div; therefore, it’s background link to certain areas. So let us say the penguin could go to www.sitepoint.com , the text Team 1504 could go to www.w3schools.com , and the text text the desperate penguins would go to www.google.com.
All of them would go the those pages on click, but if the user clicked in an area not set to go anywhere (such as the surrounding space) it would not go anywhere

I hope I made my situation more clear and I hope you can help

Thanks again and Regards
Here from you soon,

                         Team 1504

Hi Paul, I may be missing something here but why is there a z-index on the li a:hover.

I don’t see any positioning applied to the anchor on any state, all I see is display:block on the a.


#header li a {
    display:block;
    width:100&#37;;
    height:100%;
    outline:0;
    background:url(images/team15-2.png) no-repeat 0 0;
}
#header li a:hover {
    z-index:99;
}

Is it because it’s a child of an AP parent? That would require position:inherit; though wouldn’t it. It doesn’t seem to have any effect when it is removed.