Multiple classes to same tag not working

Discussion in 'CSS' started by Parka, Oct 15, 2008.

  1. #1
    Hi, I've the following problem. It should work but it doesn't.

    On my webpage is the following PHP code:

    <div class="{$adsense_class}">
    <p>Some adsense code here</a>
    </div>
    Code (markup):
    My CSS code is like this:

    .adsense {
    	float: right;
    	padding: 1em;
    	background-color: gray;
    	margin: 0 0 1em 3em;
    }
    
    .160by600 {
    	width: 160px;
    	height: 600px;
    }
    Code (markup):
    My page managed to print out the following HTML.
    But somehow only .adsense is working. .160by600 isn't. Any idea why?

    <div class="adsense 160by600">
    <p>Some adsense code here</a>
    </div>
    Code (markup):

     
    Parka, Oct 15, 2008 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    For one, classes can't start with numbers.
     
    blueparukia, Oct 15, 2008 IP
  3. emzdesign

    emzdesign Peon

    Messages:
    538
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well for start, you can't have two classes on one div (which looks like you're trying to do?)

    Secondly, shouldn't the php code look more like this:

    
    
    <div class="<?php echo $adsense_class; ?>">
    <p>Some adsense code here</a>
    </div>
    
    
    Code (markup):
    And then the class specified like so:

    
    
    <?php
    
    $adsense_class = adsense;
    
    ?>
    
    
    Code (markup):
    I don't see where it is you're trying to place the width of the ad, and I'm not sure why you're doing it this way.

    Please elaborate so we can help you more.
     
    emzdesign, Oct 16, 2008 IP
  4. Parka

    Parka Well-Known Member

    Messages:
    291
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Thanks. I forgot about the naming convention.
     
    Parka, Oct 16, 2008 IP
  5. Parka

    Parka Well-Known Member

    Messages:
    291
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Well, actually there can be multiple classes to a tag. It's a cool tip.

    In my case, all my ads are floated right. Depending on how much space my content takes up, php will generate the appropriate class for ad size, together with the float property.
     
    Parka, Oct 16, 2008 IP
  6. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #6
    Wrong.

    He'd already have the adsense variable set, and is being called by a template engine like thing called "Smarty". I dislike it - too slow, but it'd be what he is using.

    Did that fix the problem, though?

    Cheers
     
    blueparukia, Oct 16, 2008 IP
  7. Parka

    Parka Well-Known Member

    Messages:
    291
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    #7
    Thanks. It solved it.

    Anyway, I'm not using Smarty. Will be just having the adsense code in their individual php files and including them when needed. I'm only using very simple logic codes.
     
    Parka, Oct 16, 2008 IP
  8. emzdesign

    emzdesign Peon

    Messages:
    538
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Fair enough. I didn't know you could but then again I wouldn't use two classes on one thing.
     
    emzdesign, Oct 17, 2008 IP
  9. bigroddy

    bigroddy Peon

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I do it all the time...keeps the .css document smaller
     
    bigroddy, Oct 17, 2008 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #10
    It's also a handy thing to know if you are using a javascript to manipulate your content. Instead of going through and changing the display state, you can use a fixed class for general style info, and a second class that you swap to change it's state.

    That's how my accordion Javascript works. I have a set of classes that start with s_. s_radio# makes it part of a radio set, I swap s_expanding, s_expanded, s_shrinking and s_shrunk to change the state, while s_content tells me the box it's on is to be styled as a shrinking box.

    http://battletech.hopto.org/html_tutorials/accordion
     
    deathshadow, Oct 17, 2008 IP
  11. emzdesign

    emzdesign Peon

    Messages:
    538
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    How does it keep the css doc smaller if you're creating multiple classes for different things?
     
    emzdesign, Oct 17, 2008 IP
  12. bigroddy

    bigroddy Peon

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    to only have one class that did the same thing as two classes combined, would require more lines of code in your css...there'd be overlapping attributes.

    Note: I realize that statement in itself made no sense...so here's trying to clarify...

    Take tabular data rows for example (I may want to distinguish odd/even rows and regular or bolded text & numbers separately)
    Instead of creating .oddtext, .oddnum, .eventext, .evennum classes...
    I'd create .odd, .even, .text, .num and they wouldn't have overlapping attributes like the first 4 would.

    I usually do this when I'm applying styles dynamically, shooting through a loop
     
    bigroddy, Oct 17, 2008 IP