Jump to content

Creating variables for CSS Pseudo-classes


Texan78

Recommended Posts

Hello, is it possible to created a variable for a pseudo class?

 

For example I normally do something like this. 

$tableWrapper = "background-color:{$alertColor};font-size:12px; padding: 0px 5px 5px 5px;text-align:center;";

Then when I use it in my HTML I would call the variable like so. 

$tData .= "<div style='{$tableWrapper}'>\n";

But for something like this 

$ul.alertLegend li

Wouldn't work because of the period. Is this possible to do? I really need to be able to do this since the color that will be included in the class is being pulled from an array depending on a certain value. So is it possible to created a variable for for pseudo class?

 

-Thanks

  • Like 1
Link to comment
Share on other sites

Why is that? Maybe wrap $ul in curly braces?

 

Are generating css dynamically? Maybe you should look at SASS.

 

Usually when you create a variable for a class the variable is your class name. 

 

I.E. $var = "your styles here";

 

echo "<div class='$var'>YADA</div>

 

In this case you can't use ul.alertLegend li as the name of the variable because its a pseudo class

 

So how do I create a variable with a pseudo class? 

Link to comment
Share on other sites

Sorry, hansford for the mis-interpretation, you are correct I meant class selector, not pseudo class. That is what lack of sleep and and previously working with some pseudo classes does. HA! 

 

I was actually making it harder than it was. What I ended up doing was this and just breaking it down. 

// Lets create some styles for the list
    $ulStyle   = "display:inline;padding:15px;";
    $liStyle   = "display:inline;";
    $spanStyle = "background-color:{$alertColor};border:solid 1px #333;width:15px;height:10px;display:inline-block;'> </span><span style='font-size:12px;color:#555;";

//Let's create the list
     $legend .= "<ul style='{$ulStyle}'>";
     $legend .= "<li style='{$liStyle}'><span style='{$spanStyle}'> {$event}</span></li>";
     $legend .= "</ul>";

Now my next issue is do I even want to use an unordered list and if so how I can limit it to only 5 before it breaks to a new line or if I want to use a table and use columns instead. I also still need to figure out a way to filter out duplicates. 

 

You can see what I mean from the link. http://www.mesquiteweather.net/inc/inc-legend.php

Link to comment
Share on other sites

Personally, since this is data related, and that's what tables are for, I would use a table.

You want everything to be flush and presentable. Tables are not "bad" like everyone is lead to believe with CSS. Otherwise, they would have dropped them from the specs. Use what available resources you have is my "opinion". As far as the dups go - store the events in an array and then compare them as a string to see if they match.

Edited by hansford
Link to comment
Share on other sites

I completely agree. If tables are used properly which in this case to display data then they are completely fine to use. Which is why I debated on using tables instead but, wasn't sure how to roll over to a new row after X amount of columns. 

 

I have done something similar before with an array which I am still trying to master which would help me with what I am trying to do now. Only issue is it doesn't restrict to just one entry. It will show all of that entry if it exists more than once in the data. 

 

Here is the example. http://www.mesquiteweather.net/inc-weather_radio_alert.php

 $alertValue = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement');


        $events = array_intersect($alertValue, $event);


        $message = array_shift($events);




// Set the alert colors for the banner background


include ('inc-NWR-alert-colors.php');


// Lets assign some styles for the banner


         $bannerStyle = '"color: #333; width:100%; border-top-style:solid; border-bottom-style:solid; border-color:#FFF; border-width:1px; font-size:11px; font-weight:normal; font-family: Arial,Helvetica,sans-serif; text-align: center; background-color:' .$alertColor. '; margin-bottom:5px; padding: .2em 0em .2em 0em"';


// Lets assembly the banner to display


         $radiowarning = '<div style='.$bannerStyle.'>
                 <strong>WEATHER BROADCAST ALERT - '.$message.'</strong>... Listen now to our LIVE NOAA Weather Radio Stream <a href="'.$feed.'" onclick="return popup(this, \'noaa\')" title="Live NOAA Radio For Dallas County"><span style="color:FFF">[Click here to listen]</span></a>
                 </div>';


foreach( $alertValue as $alert )
{
if (in_array($alert, $event))
{
             echo $radiowarning;
}
}
Link to comment
Share on other sites

I don't know what the event arguments look like, but try this:

$alertValue = array('Tornado Warning', 'Tornado Watch', 'Severe Thunderstorm Warning', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement');

$event = array('Tornado Warning', 'Tornado Watch', 'Severe Thunderstorm Warning', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement');

$events = array_intersect($alertValue, $event);

$alertValue = array_keys(array_flip($events));



foreach( $alertValue as $alert )
{
    echo $alert . '<br />';
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.