Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > CSS > CSS Cascading Style Sheets
|
CSS Cascading Style Sheets All issues relating to Cascading Style Sheets (CSS).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the CSS Cascading Style Sheets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2005, 01:49 PM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default new to forum, 1st project question for ya'll

Hello all,

I recently purchased the Beginning CSS book by Mr. York, and so far it's helping me greatly. I have a question that hopefully someone can drop an answer for....

I was reading in chapter 5, about the 'selection based on the value of an attribute', and it got me thinking. On an upcoming project, the banner navigation buttons/links are going to have ends that are rounded and overlapping. Based on the current page, one buttons images will be 'on' and overlapping the rest of the 'off' buttons. when a user clicks on a different nav button, the relative overlapping images will refresh to an 'on' image and the previous to off.

how would this be accomplished with CSS? I'm pretty new at implementing css, so any help, or even a basic dummy example would be greatly appreciated.

Thanks in advance.

 
Old February 8th, 2005, 02:16 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Basically you're saying that you want a different style based on the page the user is currently viewing.

In that case I believe that the following would get you what you need.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id='example-com'>
    <head>
        <style type='text/css'>
            img.nav {
                position: absolute;
            }
            img#about {
                left: 10px;
                z-index: 1;
            }
            img#contact {
                left: 20px;
                z-index: 2;
            }
            img#more {
                left: 30px;
                z-index: 3;
            }
            body#about-us img#about,
            body#more-info img#more,
            body#contact-us img#contact {
                z-index: 4;
            }
        </style>
    </head>
    <body id='about-us'>
        <img src='/images/about.jpg' id='about' class='nav' alt='About us.' />
        <img src='/images/contact.jpg' id='contact' class='nav' alt='Contact Us' />
        <img src='/images/more.jpg' id='more' class='nav' alt='More Information' />
    </body>
</html>
The underlying theory should be pretty straight-forward. Each page that you create receives a unique id name. As you see in the CSS this id name cannot be the same as the id name you assign each image. This style sheet works better as an external style sheet, BTW. But the premise is that each image overlaps in ascending order, that is until the last rule of the style sheet comes into play.

            body#about-us img#about,
            body#more-info img#more,
            body#contact-us img#contact {
                z-index: 4;
            }

This makes the current page's image the one on top. It defeats the previously defined rules via the cascade.

Of course you'll have to wrap those images in <div> elements if you want to use links on them, in which case you'd just name and position the <div> elements rather than the image elements.

This also assumes that you want to use the same images, whether they're 'on' or 'off'. If you want to use a different image as the 'off' image, it can still be done purely with CSS.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id='example-com'>
    <head>
        <style type='text/css'>
            img.nav {
                position: absolute;
            }
            img#about,
            img#about-off {
                left: 10px;
                z-index: 1;
            }
            img#contact,
            img#contact-off {
                left: 20px;
                z-index: 2;
            }
            img#more,
            img#more-off {
                left: 30px;
                z-index: 3;
            }
            body#about-us img#about,
            body#more-info img#more,
            body#contact-us img#contact {
                z-index: 4;
            }
            body#about-us img#about-off,
            body#about-us img#contact,
            body#about-us img#more,
            body#more-info img#more-off,
            body#more-info img#about,
            body#more-info img#contact,
            body#contact-us img#contact-off,
            body#contact-us img#more,
            body#contact-us img#about {
                display: none;
            }
        </style>
    </head>
    <body id='about-us'>
        <img src='/images/about.jpg' id='about' class='nav' alt='About us.' />
        <img src='/images/about-off.jpg' id='about-off' class='nav' alt='About us.' />
        <img src='/images/contact.jpg' id='contact' class='nav' alt='Contact Us' />
        <img src='/images/contact-off.jpg' id='contact-off' class='nav' alt='Contact Us' />
        <img src='/images/more.jpg' id='more' class='nav' alt='More Information' />
        <img src='/images/more-off.jpg' id='more-off' class='nav' alt='More Information' />
    </body>
</html>
Now you're including six images instead of three, and selectivly displaying and layering those images depending on which page the user is visiting.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old February 8th, 2005, 02:47 PM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for that detailed repsonse, I appreciate your time to post.

Best regards.

 
Old February 8th, 2005, 06:17 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

No worries, glad to be of help :-).

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old February 15th, 2005, 12:57 PM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've successfully been able to work with your 3 image example, and I'm in the process of trying to apply it to a bit more complex project, which will be viewed 99.99% in IE. I'm scratching my head a bit at what to do next, so here's where I'm at right now:

http://www.obnubes.com/Temp/banner2.html
(just using a friends webspace to display this page)

as you can see I have a banner menu of 5 items, that will have to turn 3 images off & on for each one:

- background image of each link area
- overlapping images on each side of the link area

This 2nd item is a bit foggy for me. for the 1st link, the left rounded image will be easy, (just on or off) & same for the right side of the last link. But those overlapping inbetween will have 3 possible states:

on-off, off-off, or off-on

I'm not sure exactly how to code for that, as can be seen on lines 13-15. (I just entered the 'concept of what needs to be done rather than working code). I've also put comments on lines 44 and 56. any help you can provide to helping to clear this up, I appreciate. nothing like jumping into the deep end on a 1st project..at least it feels like it!

Best regards.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - 1st exercise gomesdir BOOK: Beginning JavaServer Pages 4 April 6th, 2006 08:13 PM
Professional c# 1st edition HJ All Other Wrox Books 2 March 17th, 2005 10:47 AM
converting Forum.aspx to Forum.ascx (help) drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 1 July 11th, 2003 12:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.