当方向是内嵌时,我知道如何设计样式。
<div dir="rtl">foo</div>
div[dir="rtl"]
{
....;
}但是如何设计
<div style="direction:rtl">foo</div> ?两者的行为都是预期的(文本的正确“对齐”),但我需要对内部的一些元素进行更精细的调整(浮动,文本对齐.)在第二种情况下,我不能正确地设定我的规则。
我不能编辑html。我必须使用style=“方向:rtl”.
发布于 2014-03-19 15:59:05
由于您不能修改HTML,所以真正的hacky选择器应该是:
div[style*="direction:rtl"] {
...
}JSFiddle demo。
注意,我使用的是style*=而不是style=,因为这也将匹配元素,这些元素不仅仅是在元素的style属性中声明的direction:rtl。
对于选择器中的额外强度,还可以使用[style*="direction: rtl"]处理style属性,这些属性使用空格将值与属性分隔开来:
[style*="direction:rtl"], [style*="direction: rtl"] { ... }或者,在这种情况下,您可以只匹配包含"rtl“的style属性,因为我非常肯定该字符组合不用于任何其他属性(忽略外部资源,比如背景图像文件名):
[style*="rtl"] { ... }Updated JSFiddle demo。
发布于 2016-07-01 10:37:24
在窗体和插入文本上使用dir=“自动”,以便自动检测运行时提供的内容的方向。
<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="لا إله إلا الله محمد رسول الله" >
发布于 2017-04-08 18:47:18
只需将类"rtl“添加到html标记即可。
<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>https://stackoverflow.com/questions/22511460
复制相似问题