简体   繁体   English

使用CSS3从右到左排列/重复Div

[英]Arrange/Repeat Div From Right side To Left using CSS3

I am developing website which support RTL. 我正在开发支持RTL的网站。 So I am repeating my div using foreach. 因此,我使用foreach重复了div。

 <?php foreach ($list as $key => $row) { ?>
   <div>---contents---</div>
 <?php } ?>

as usual it is placing from left side to right side. 像往常一样,它是从左侧放置到右侧。

How can I make div repeating from left side to right side? 如何使div从左侧重复到右侧? 在此处输入图片说明

You are looking for the dir attribute. 您正在寻找dir属性。 Something like this should work: 这样的事情应该起作用:

<dir dir="rtl">
  <div>a</div>
  <div>b</div>
  <div>c</div>
  <div>d</div>
</dir>

Add this bit of css to make sure the divs layout in a row: 添加以下CSS来确保div布局连续:

div {
  display: inline-block;
}

See the plunkr. 见矮人。

You can either use display: flex; 您可以使用display: flex; and flex-direction: row-reverse on the container element. flex-direction: row-reverse容器元素上的flex-direction: row-reverse This will have some additional effects which you even might have been looking for (position and size of child elements). 这将带来一些您甚至可能一直在寻找的附加效果(子元素的位置和大小)。

Or you put float: right; 或者你把float: right; on all the child elements (and to be on the safe side, overflow: hidden; on the container, so that subsequent elements will be at the right vertical position) 在所有子元素上(为安全起见, overflow: hidden;在容器上,以便后续元素将位于正确的垂直位置)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM