Reputation: 1
Does anyone know how to use condition in CSS? I'm using PHP CMS.
The thing is that I have a variable "Post Title" that sometimes may be in RTL language. So I want some sort of CSS code or any other solution that can detect if the language is arabic and set the direction to RTL, else LTR.
Thanks in advance.
Upvotes: 0
Views: 2295
Reputation: 3506
i think best way is write 2 different CSS, on for rtl , and another for ltr
and put it in your php code in <header></header>
html tag
if($lang['direction'] == "ltr" )
echo '<link rel="stylesheet" type="text/css" href="ltr.css">';
else
echo '<link rel="stylesheet" type="text/css" href="rtl.css">';
Upvotes: 0
Reputation: 16968
Instead of trying to generate the CSS on the fly, why not include the a stylesheet relevant to the content like so:
<?php
if($style_1){
echo '<link rel="stylesheet" type="text/css" href="stylesheet_1.css">
}else{
echo '<link rel="stylesheet" type="text/css" href="stylesheet_2.css">
}
?>
There are several ways you can achieve this, but in my opinion, the above is definitely the better of the methods
Upvotes: 1
Reputation: 7325
Try this, good example on how to style RTL blogs, but I'm not sure if its compatable with your CMS.
OR
You can have something e.g.
<?php if($lang="en"){?>
body .title{left to right styles}
<?php }else{?>
body .title{right to left styles}
<?php }?>
Just a simple example.
Upvotes: 0