www.webdeveloper.com
Results 1 to 8 of 8

Thread: Conditional CSS

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    4

    Unhappy Conditional CSS

    Hi Guys,
    I have a question about CSS. I have a class called .cal_event
    This basically controls the formating within a calendar for me.
    I want to duplicate this so that I have four variations of this class
    .cal_eventAB
    .cal_eventCD
    .cal_eventEF
    .cal_eventGH

    Each of these are the same apart from the background colour.

    Within my HTML I want to reference these classes so I have the row

    <td class="cal_event${ITSEQ}">

    The end of this row${ITSEQ} is a field in my database that shows a set of initials. Eg AB, CD, ED or GH.

    So in theory, if my data shows a record with the ITSEQ = EF it should use the correct class for that.

    The problem is I think my line of code is incorrect as it doesn't seem to work.

    Any ideas?

    <td class="cal_event${ITSEQ}">


    Thanks

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Why don't you use multiple classes?
    Code:
    .cal_event{
    /* common properties */
    }
    .AB{
    /* background for AB */
    }
    .CD{
    /* background for CD */
    }
    
    /* ... and so on ... */
    And HTML should be:
    Code:
    <td class="cal_event AB">
    <td class="cal_event CD">
    // and so on ...

  3. #3
    Join Date
    Nov 2011
    Posts
    4
    Potentially this could be ok, but the key problem here is that in the HTML you are suggesting hardcoding the AB or CD part of the class.

    I need this to be a field which then gets read, and if this field contains CD then the class is cal_eventCD. If the field contains AB then the class resolves to be cal_eventAB

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    Quote Originally Posted by sparx1981 View Post
    Potentially this could be ok, but the key problem here is that in the HTML you are suggesting hardcoding the AB or CD part of the class.

    I need this to be a field which then gets read, and if this field contains CD then the class is cal_eventCD. If the field contains AB then the class resolves to be cal_eventAB
    I'm sorry, that's dumb. If you can code class="cal_eventCD", why can't you code class="cal_event CD" if a certain conditional is met?
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  5. #5
    Join Date
    Nov 2011
    Posts
    4
    maybe I'm missing something here?
    The problem isn't setting the class to be hard coded to CD. It's simple to type that in.
    But I want the class to be cal_eventXYZ where XYZ is the content of a field. Not hardcoded.

    I thought I could simply reference the field e.g. class="cal_event${ITEMP}" but this doesn't work.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  7. #7
    Join Date
    Nov 2011
    Posts
    4
    Sorry ITEMP was meant to be ITSEQ as per the first part of this thread.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I really don't understand. It is a variable written in a server-side language? Looks like a SMART syntax... Anyway, how your generated HTML code looks like? What you see on your View Source Code? That is important...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles