![]() |
![]() OCAU News - Wiki - QuickLinks - Pix - Sponsors |
|
|||||||
| Notices |
|
Sign up for a free OCAU account and this ad will go away! Search our forums with Google: |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Member
Join Date: Dec 2002
Posts: 669
|
I'm wanting to use different images on my website depending on what style the user has selected. For example, the default and sabretoothe styles used on OCAU use different images.
I was wondering how this could be done with CSS. At the moment I'm using: Code:
XHTML:
<div class="ca"></div>
CSS:
div.ca
{
width:100px;height:100px;
background-image:url('image.gif');
background-position:center center;
background-repeat:no-repeat;
}
Code:
arrow:<img src="images/arrow.gif" alt="Arrow" /> msg_unread:<img src="msg_unread.gif" alt="Read Message" />
__________________
Grammar Joke: Q: What do you call Santa's helpers? A: Subordinate Clauses System: Foxconn NF4UK8AA-8EKRS | AMD Athlon 64 3000+ | 2x256MB DDR400 Corsair RAM | Xpertvision 6600GT (PCIe) | Antec SLK2650BQE | Samsung TS-H552U | Samsung 80GB SATA |
|
|
|
| Join OCAU to remove this ad! |
|
|
#2 |
|
Member
Join Date: Dec 2001
Location: Melbourne
Posts: 16,897
|
CSS doesn't support conditional statements so it can't be purely CSS. You should either look at a template system (most preferable) or use a style switcher: http://www.alistapart.com/articles/n4switch/
__________________
Doctore: Crixus! What is beneath your feet? Crixus: Sacred ground, Doctore. Watered with tears and blood. |
|
|
|
|
|
#3 | |
|
Member
Join Date: Jun 2001
Location: Canberra
Posts: 2,388
|
Quote:
Code:
<link rel="stylesheet" src="themes/$theme/style.css" media="screen, projection" /> <img src="themes/$theme/arrow.gif" alt="" /> <img src="themes/$theme/msg_unread.gif" alt="There are unread messages" /> This forum uses non-standard inaccessable presentational HTML, it hardly uses CSS at all. Not a good place to look for best practices. Last edited by Shinglor; 28th September 2004 at 6:58 PM. |
|
|
|
|
|
|
#4 |
|
Member
Join Date: Dec 2002
Posts: 669
|
Thanks, Shinglor. You're replies are always helpful.
However, I've come across a new problem. In some styles I only want to use images as the main navigational links. In others I want to use images and text, and in others I want only text. I know I can implement the image and text solution with the :before and :after pseudo-elements (or are they pseudo-classes?), but this is currently not supported by some browsers, inc. IE. What should I do in this case?
__________________
Grammar Joke: Q: What do you call Santa's helpers? A: Subordinate Clauses System: Foxconn NF4UK8AA-8EKRS | AMD Athlon 64 3000+ | 2x256MB DDR400 Corsair RAM | Xpertvision 6600GT (PCIe) | Antec SLK2650BQE | Samsung TS-H552U | Samsung 80GB SATA |
|
|
|
|
|
#5 | |
|
Member
Join Date: Jun 2001
Location: Canberra
Posts: 2,388
|
Quote:
Code:
<ul id="nav"> <li id="home"><a href="index.php"><span>Home</span></a></li> <li id="help"><a href="help.php"><span>Help</span></a></li> <li id="about"><a href="about.php"><span>About</span></a></li> </ul> If you want to replace the "Home" text with home.png you could do this Code:
li#home span {
visibility: hidden;
width: 100px;
height: 30px;
}
li#home a {
background: url('home.png') no-repeat;
width: 100px;
height: 30px;
}
Code:
li#home a {
background: url('home.png') no-repeat top;
padding-top: 30px;
width: 100px;
}
EDIT: Whoops, forgot to include the image in the anchor. Last edited by Shinglor; 28th September 2004 at 9:48 PM. |
|
|
|
|
|
|
#6 |
|
Member
Join Date: Dec 2002
Posts: 669
|
Tis exactly what I meant, thankyou Shinglor.
LI are block elements are they not? It's just that my navigation links are not necessarily going to be vertical, so I thought I could add the image through the anchor element's class. Could it work like this: Code:
CSS:
a.nav_home span{visibility:hidden}
a.nav_home {background:url('home.gif') no-repeat}
XHTML:
<a class="nav_home" href="home.php"><span>Home</span></a>
__________________
Grammar Joke: Q: What do you call Santa's helpers? A: Subordinate Clauses System: Foxconn NF4UK8AA-8EKRS | AMD Athlon 64 3000+ | 2x256MB DDR400 Corsair RAM | Xpertvision 6600GT (PCIe) | Antec SLK2650BQE | Samsung TS-H552U | Samsung 80GB SATA Last edited by SouthernMunk; 29th September 2004 at 11:56 AM. |
|
|
|
|
|
#7 | |
|
Member
Join Date: Jun 2001
Location: Canberra
Posts: 2,388
|
Quote:
Also you don't need to set a class on the span, using inheritance (a.nav_home span) will do the same thing. I've updated my code to make the image a part of the link so it's clickable. I haven't tested it though so there could be some mistakes. Generally if something is going to be unique use an id instead of a class. EDIT: I just figured out that you don't like the idea of using an unordered list for a list of links. A list is better for mobile devices, screen-readers and text browsers. Show me how you have it currently and I'll try and style it as a list. Last edited by Shinglor; 29th September 2004 at 4:10 AM. |
|
|
|
|
|
|
#8 | |
|
Member
Join Date: Dec 2002
Posts: 669
|
The width and height properties of anchors and spans cannot be set (at least, not with the browsers I am using). Because of this, the background image doesn't display correctly.
This seems to work for me, but I don't know how 'correct' it is: Code:
CSS:
li#home {
width:100px;height:100px;
background-image:url('image.gif');
background-position:center center;
background-repeat:no-repeat;
}
li#home span {
visibility:hidden;
}
XHTML:
<ul>
<a href="home.php"><li id="home"><span>Home</span></li></a>
</ul>
Quote:
Code:
<a href="home.php">Home</a> <a href="search.php">Search</a> <a href="members.php">Members</a> ... ... ...
__________________
Grammar Joke: Q: What do you call Santa's helpers? A: Subordinate Clauses System: Foxconn NF4UK8AA-8EKRS | AMD Athlon 64 3000+ | 2x256MB DDR400 Corsair RAM | Xpertvision 6600GT (PCIe) | Antec SLK2650BQE | Samsung TS-H552U | Samsung 80GB SATA |
|
|
|
|
|
|
#9 | ||
|
Member
Join Date: Jun 2001
Location: Canberra
Posts: 2,388
|
Quote:
Quote:
Code:
ul#nav {
list-style: none;
margin: 0;
padding: 0;
}
ul#nav li {
display: block
float: left;
}
EDIT: http://members.optusnet.com.au/shing...zontalnav.html I used display: none instead of visibility: hidden because the text can sometimes cause the box to expand. There was a reason I used visibility: hidden but I can't remember what it was. Last edited by Shinglor; 29th September 2004 at 3:37 PM. |
||
|
|
|
|
|
#10 | |
|
Member
Join Date: Dec 2002
Posts: 669
|
I've ended up with this - it seems to work OK, except that in IE6 the screen jumps around (I think this is the JavaScript functions).
Code:
CSS:
span.n_home {
background-image:url('n_home.gif');
background-position:center left;
background-repeat:no-repeat;
text-indent:25px;
}
span.n_home span {
display:none;
visibility:hidden;
}
XHTML:
<a href="home.php"><span class="n_home"><span>Home</span></span></a>
Quote:
I don't know if there is any other way to do this.
__________________
Grammar Joke: Q: What do you call Santa's helpers? A: Subordinate Clauses System: Foxconn NF4UK8AA-8EKRS | AMD Athlon 64 3000+ | 2x256MB DDR400 Corsair RAM | Xpertvision 6600GT (PCIe) | Antec SLK2650BQE | Samsung TS-H552U | Samsung 80GB SATA |
|
|
|
|
![]() |
| Bookmarks |
|
Sign up for a free OCAU account and this ad will go away! |
| Thread Tools | |
|
|