How to delcare a vraible in CSS?

Discussion in 'PHP' started by Danielz, Jun 19, 2008.

  1. #1
    Dear all, how to declare a variable in CSS? Please help me. Thanks in advance.:)
     
    Danielz, Jun 19, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Too vague.

    Do you mean CSS variables.

    
    @variables {
      CorporateLogoBGColor: #fe8d12;
    }
    
    div.logoContainer {
      background-color: var(CorporateLogoBGColor);
    }
    
    Code (markup):
    or actual PHP variables.

    
    <?php
    header("Content-type: text/css");
    $color = "green";
    echo <<<CSS   
    h2
    	{
    	color: $color;  /* <--- use the variable */
    	font-weight: bold;
    	font-size: 1.2em;
    	text-align: left;
    	}
    CSS;
    ?>
    
    PHP:
     
    Danltn, Jun 19, 2008 IP
    J.T.D. likes this.
  3. J.T.D.

    J.T.D. Peon

    Messages:
    86
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey Danltn, wow, I never knew about css variables, (your #1 example). Thanks.

    - JTD
     
    J.T.D., Jun 19, 2008 IP
  4. Danielz

    Danielz Peon

    Messages:
    115
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi Danltn, Thank you very much.
     
    Danielz, Jun 19, 2008 IP
  5. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Wow, new thing, I never know or use Css variables before.
     
    koolman, Jun 20, 2008 IP
  6. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Yeah but be careful with CSS variables, not many people know about them (as I can tell from your reactions) and normally they need to be stored in .cssp files.

    It's worth having a look into it though, just a Google search can do.

    Dan
     
    Danltn, Jun 20, 2008 IP