我有一个英语句子,它的翻译就在它下面的RTL句子:
<div class="sample-sentence">
<p class="eng">I could make up a bed for you on the sofa.</p>
<p class="rtl">برات آماده کنم</p>
</div>
到目前为止,我只能把RTL的句子定位在英语的最左边或中间。
如何将RTL句子放置在英语句子的右侧:
发布于 2020-11-20 14:50:00
grid
和justify-content
可能会有所帮助:
.sample-sentence {
display: grid;
justify-content: start;
}
/* snippet demo purpose */
body>p {text-align:center;background:none;}
p {margin:0;background:#bee}
<div class="sample-sentence">
<p class="eng">I could make up a bed for you on the sofa.</p>
<p dir="rtl">برات آماده کنم</p>
</div>
<hr>
<p>no matter the initial direction of the doc</p>
<hr>
<div dir="rtl" >
<div class="sample-sentence">
<p>برات آماده کنم</p>
<p dir="ltr" class="eng">I could make up a bed for you on the sofa.</p>
</div>
</div>
发布于 2020-11-20 14:52:22
margin-left: auto
与display: flex
和justify-content: flex-end
一起使用的目标元素是一种方法。
inline-block
也被使用,因此父元素的宽度调整到它的内容。
div, p {
display: inline-block;
}
p {
display: flex;
justify-content: flex-end;
}
.rtl {
margin-left: auto;
}
<div class="sample-sentence">
<p class="eng">I could make up a bed for you on the sofa.</p>
<p class="rtl">برات آماده کنم</p>
</div>
发布于 2020-11-20 15:13:14
我给出了将底部文本放在右边的三个选项。但事实上,解决这个问题有很多选择:)
用于.sample-sentence
的带有text-align: right
的
.sample-sentence {
text-align: right;
}
<div class="sample-sentence">
<p class="eng">I could make up a bed for you on the sofa.</p>
<p class="rtl">برات آماده کنم</p>
</div>
width: fit-content
用于.sample-sentence
,伪类:nth-child
用于第二个p
标记:
.sample-sentence {
width: fit-content;
}
.sample-sentence p:nth-child(2) {
text-align: right;
}
<div class="sample-sentence">
<p class="eng">I could make up a bed for you on the sofa.</p>
<p class="rtl">برات آماده کنم</p>
</div>
基于flex
的
.sample-sentence {
display: inline-flex;
flex-direction: column;
}
.sample-sentence p:nth-child(2) {
text-align: right;
}
<div class="sample-sentence">
<p class="eng">I could make up a bed for you on the sofa.</p>
<p class="rtl">برات آماده کنم</p>
</div>
https://stackoverflow.com/questions/64931519
复制相似问题