我找不到一个解决方案,让绿色元素从容器的右下角开始,就像右图(“需要”)一样。
CSS是否提供了一种从底部对齐/定向元素的方法?
说明了“默认”和“需要”元素的位置。
段
.cnt {
width:200px;
height:300px;
border:1px solid green;
text-align:center;
display: table-cell;
vertical-align: bottom;
}
.itm {
transform: translate(0px, 0px) scale(1);
display: inline-block;
padding:10px;
width:20px;
margin:10px;
background: green;
color: white;
transition:transform 0.5s;
}
.itm:hover {
transform: translate(0px, -3px) scale(1.1);
}
<div class="cnt">
<div class="itm">1</div>
<div class="itm">2</div>
<div class="itm">3</div>
<div class="itm">4</div>
<div class="itm">5</div>
<div class="itm">6</div>
<div class="itm">7</div>
<div class="itm">8</div>
</div>
答案 0 :(得分:3)
CSS是否提供了一种从底部对齐/定向元素的方法?
令人惊讶的是,在水平书写模式下,它并没有出现。
有各种属性,包括writing-mode
,direction
,text-orientation
和flex-direction
,可让您重新安排内容流。
但是它们似乎都不允许从右下角开始以水平书写模式布置内容。也许有人可以纠正我。
同时,这是一个黑客(纯CSS):
.cnt {
display: flex;
flex-direction: row-reverse;
flex-wrap: wrap;
align-items: flex-start;
align-content: flex-start;
justify-content: center;
text-align: center;
width: 200px;
height: 300px;
border: 1px solid green;
transform: scaleY(-1);
}
.itm {
padding: 10px;
width: 20px;
margin: 10px;
background: green;
color: white;
transform: translate(0px, 0px) scaleY(-1) scaleX(1);
transition: transform 0.5s;
}
.itm:hover {
transform: translate(0px, -3px) scaleY(-1.1) scaleX(1.1);
}
<div class="cnt">
<div class="itm">8</div>
<div class="itm">7</div>
<div class="itm">6</div>
<div class="itm">5</div>
<div class="itm">4</div>
<div class="itm">3</div>
<div class="itm">2</div>
<div class="itm">1</div>
</div>
答案 1 :(得分:1)
It's easy if you can reverse the order of the itms in the source.
.cnt {
width:200px;
height:300px;
border:1px solid green;
text-align:center;
display: table-cell;
vertical-align: top;
transform:rotate(180deg);
}
.itm {
display: inline-block;
padding:10px;
width:20px;
margin:10px;
background: green;
color: white;
transform:rotate(180deg);
}
<div class="cnt">
<div class="itm">8</div>
<div class="itm">7</div>
<div class="itm">6</div>
<div class="itm">5</div>
<div class="itm">4</div>
<div class="itm">3</div>
<div class="itm">2</div>
<div class="itm">1</div>
</div>
答案 2 :(得分:0)
我知道这不完全是它,但它是我用纯CSS解决方案得到的最接近的。不过,这很丑陋。发布更多内容以便其他人可以看到并使用它来获得正确的答案。
.cnt {
width:200px;
height:300px;
border:1px solid green;
text-align:center;
display: table-cell;
vertical-align: bottom;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
align-content: flex-end;
}
.itm {
transform: translate(0px, 0px) scale(1);
display: inline-block;
padding:10px;
width:20px;
height: 20px;
margin:10px;
background: green;
color: white;
transition:transform 0.5s;
}
.itm:hover {
transform: translate(0px, -3px) scale(1.1);
}
.itm:nth-child(1) {
order: 8;
}
.itm:nth-child(2) {
order: 7;
}
.itm:nth-child(3) {
order: 6;
}
.itm:nth-child(4) {
order: 5;
}
.itm:nth-child(5) {
order: 4;
}
.itm:nth-child(6) {
order: 3;
}
.itm:nth-child(7) {
order: 2;
}
.itm:nth-child(8) {
order: 1;
}
&#13;
<div class="cnt">
<div class="itm">1</div>
<div class="itm">2</div>
<div class="itm">3</div>
<div class="itm">4</div>
<div class="itm">5</div>
<div class="itm">6</div>
<div class="itm">7</div>
<div class="itm">8</div>
</div>
&#13;