foodiv[dir="rtl"] { ....; }...">

Css: dir = "rtl" VS style = "direction: rtl"

I know how style is when direction is inline

<div dir="rtl">foo</div>

div[dir="rtl"]
{
 ....;
}

But style

<div style="direction:rtl">foo</div> ?

Both behave as expected (correct "alignment" of the text), but I need a more subtle change for some elements inside (float, text-align ...), and I can’t set up my rule correctly in the second case.

I can not edit html. I MUST use the style = "direction: rtl".

+4
source share
3 answers

As you cannot change the HTML, a really really hacked selector would be:

div[style*="direction:rtl"] {
    ...
}

JSFiddle demo .

, style*=, style=, , direction:rtl, element style.

[style*="direction: rtl"] style, :

[style*="direction:rtl"], [style*="direction: rtl"] { ... }

style, "rtl", , ( , ):

[style*="rtl"] { ... }

JSFiddle.

+6

dir = "auto" , ,

<div dir="auto">Hello, world!</div>
<br/>
<div dir="auto">لا إله إلا الله محمد رسول الله</div>
<br/>
<input type="text" dir="auto" value="Hello, world!" > 
<br/><br/>
<input type="text" dir="auto" value="لا إله إلا الله محمد رسول الله" >
Hide result

JSFIDDLE Demo https://jsfiddle.net/80k0drsf/

+7

just add the rtl class to the html tag

<html dir="rtl" class="rtl">
 <head>
   <style>
      html[class*="rtl"] body {
         background-color:blue;
      }
      html[class*="rtl"] div{
         background-color:green;
      }
   </style>
 </haed>

 <body>

 <div>
 </div>

 </body>
</html>
-1
source

Source: https://habr.com/ru/post/1532508/


All Articles