首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >把英语句子的翻译放在右边

把英语句子的翻译放在右边
EN

Stack Overflow用户
提问于 2020-11-20 14:44:39
回答 4查看 43关注 0票数 0

我有一个英语句子,它的翻译就在它下面的RTL句子:

代码语言:javascript
运行
复制
<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句子放置在英语句子的右侧:

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2020-11-20 14:50:00

gridjustify-content可能会有所帮助:

代码语言:javascript
运行
复制
.sample-sentence {
  display: grid;
  justify-content: start;
}

/* snippet demo purpose */
body>p {text-align:center;background:none;}
p {margin:0;background:#bee}
代码语言:javascript
运行
复制
<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>

票数 1
EN

Stack Overflow用户

发布于 2020-11-20 14:52:22

margin-left: autodisplay: flexjustify-content: flex-end一起使用的目标元素是一种方法。

inline-block也被使用,因此父元素的宽度调整到它的内容。

代码语言:javascript
运行
复制
div, p {
  display: inline-block;
}
p {
  display: flex;
  justify-content: flex-end;
}
.rtl {
  margin-left: auto;
}
代码语言:javascript
运行
复制
<div class="sample-sentence">
   <p class="eng">I could make up a bed for you on the sofa.</p>
   <p class="rtl">برات آماده کنم</p>
</div>

票数 1
EN

Stack Overflow用户

发布于 2020-11-20 15:13:14

我给出了将底部文本放在右边的三个选项。但事实上,解决这个问题有很多选择:)

用于.sample-sentence的带有text-align: right

  1. 解决方案

代码语言:javascript
运行
复制
.sample-sentence {
  text-align: right;
}
代码语言:javascript
运行
复制
<div class="sample-sentence">
   <p class="eng">I could make up a bed for you on the sofa.</p>
   <p class="rtl">برات آماده کنم</p>
</div>

  1. 解决方案,width: fit-content用于.sample-sentence,伪类:nth-child用于第二个p标记:

代码语言:javascript
运行
复制
.sample-sentence {
    width: fit-content;
}

.sample-sentence p:nth-child(2) {
    text-align: right;
}
代码语言:javascript
运行
复制
<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

  1. 解决方案

代码语言:javascript
运行
复制
.sample-sentence {
    display: inline-flex;
    flex-direction: column;
}

.sample-sentence p:nth-child(2) {
    text-align: right;
}
代码语言:javascript
运行
复制
<div class="sample-sentence">
   <p class="eng">I could make up a bed for you on the sofa.</p>
   <p class="rtl">برات آماده کنم</p>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64931519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档