Welcome to Dream.In.Code
Become an Expert!

Join 149,585 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,776 people online right now. Registration is fast and FREE... Join Now!




CSS conditional?

 
Reply to this topicStart new topic

CSS conditional?, if in CSS?

supersssweety
9 Oct, 2007 - 07:35 AM
Post #1

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 312



Thanked: 1 times
Dream Kudos: 125
My Contributions
I need the bg img to a wrapper be different on certain pages, is there a way you can write conditional statements in CSS like
pesudo
if url=about.html
then background-image = about.jpg
else if url=solutions.html
then background-image = soultions.jog

and so on?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: CSS Conditional?
9 Oct, 2007 - 07:56 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,133



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(supersssweety @ 9 Oct, 2007 - 08:35 AM) *

is there a way you can write conditional statements in CSS


No. You can either use server side execution to test a condition & load the correct css, or declare a specific css for each page.

CODE

/* css */
about {
  background-image = about.jpg;
}
solutions{
  background-image = solutions.jpg;
}
/* php code */
if($_SERVER['REQUEST_URI']="about.html") { echo "class=about "; }
else  { echo "class=solutions "; }


This post has been edited by no2pencil: 9 Oct, 2007 - 08:09 AM
User is online!Profile CardPM
+Quote Post

supersssweety
RE: CSS Conditional?
9 Oct, 2007 - 08:05 AM
Post #3

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 312



Thanked: 1 times
Dream Kudos: 125
My Contributions
BAH!
User is offlineProfile CardPM
+Quote Post

supersssweety
RE: CSS Conditional?
9 Oct, 2007 - 10:33 AM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 312



Thanked: 1 times
Dream Kudos: 125
My Contributions
ok so here is what I did:

CODE

#secondary-wrapper{
    background-color:#fff;
    background-position:top;
    background-repeat:no-repeat;
    background-color:#e6e7e9;
    border:1px solid #717073;
    width:1023px;
    margin:0 auto;    
}
#secondary-wrapper.solutions{
background-image:url(images/solutions-bg.jpg);
}
#secondary-wrapper.company{
background-image:url(images/company-bg.jpg);
}
#secondary-wrapper.contact{
background-image:url(images/contact-bg.jpg);
}
#secondary-wrapper.news{
background-image:url(images/news-bg.jpg);
}
#secondary-wrapper.benefits{
background-image:url(images/benefits-bg.jpg);
}
#secondary-wrapper.partner{
background-image:url(images/partner-bg.jpg);
}
#secondary-wrapper.service{
background-image:url(images/service-bg.jpg);
}

Internet explorer will only show the one that is stated first, in this case, .solutions, that bg shows, but the company one doesn't, they all show in FF. If I switch company and solutions then IE shows the company bg and not the solutions...wtf...here is how the html looks:

CODE

<div id="secondary-wrapper" class="solutions">

CODE

<div id="secondary-wrapper" class="company">

User is offlineProfile CardPM
+Quote Post

supersssweety
RE: CSS Conditional?
9 Oct, 2007 - 10:44 AM
Post #5

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 312



Thanked: 1 times
Dream Kudos: 125
My Contributions
I got it working like this:
CODE

#secondary-wrapper{
    background-color:#e6e7e9;
    border:1px solid #717073;
    width:1023px;
    margin:0 auto;    
}
.solutions{
  background-image:url(images/solutions-bg.jpg);
  background-position:top;
  background-repeat:no-repeat;
}
.company{
  background-image:url(images/company-bg.jpg);
  background-position:top;
  background-repeat:no-repeat;
}
.contact{
  background-image:url(images/contact-bg.jpg);
  background-position:top;
  background-repeat:no-repeat;
}
.news{
  background-image:url(images/news-bg.jpg);
  background-position:top;
  background-repeat:no-repeat;
}
.benefits{
  background-image:url(images/benefits-bg.jpg);
  background-position:top;
  background-repeat:no-repeat;
}
.partner{
  background-image:url(images/partner-bg.jpg);
  background-position:top;
  background-repeat:no-repeat;
}
.service{
  background-image:url(images/service-bg.jpg);
  background-position:top;
  background-repeat:no-repeat;
}

With the html as the same ...I hate CSS


QUOTE(no2pencil @ 9 Oct, 2007 - 08:56 AM) *

QUOTE(supersssweety @ 9 Oct, 2007 - 08:35 AM) *

is there a way you can write conditional statements in CSS


No. You can either use server side execution to test a condition & load the correct css, or declare a specific css for each page.

CODE

/* css */
about {
  background-image = about.jpg;
}
solutions{
  background-image = solutions.jpg;
}
/* php code */
if($_SERVER['REQUEST_URI']="about.html") { echo "class=about "; }
else  { echo "class=solutions "; }


I just noticed your code, its good but it wouldn't work because the pic for company.html goes to all the company sublinks...so that is 4 more pages the company pic will be on...see?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:59PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month