直接上代码
<template>
<view class="align-items">
<view>align-items属性定义项目在交叉轴上如何对齐。</view>
<view class="flex-start">
<view class="item1 red">
item1
</view>
<view class="item2 red">
item2
</view>
<view class="item3 red">
item3
</view>
<view class="item4 red">
item4
</view>
</view>
<view class="flex-end">
<view class="item1 yellow">
item1
</view>
<view class="item2 yellow">
item2
</view>
<view class="item3 yellow">
item3
</view>
<view class="item4 yellow">
item4
</view>
</view>
<view class="center">
<view class="item1 blue">
item1
</view>
<view class="item2 blue">
item2
</view>
<view class="item3 blue">
item3
</view>
<view class="item4 blue">
item4
</view>
</view>
<view class="stretch">
<view class=" orange">
item1
</view>
<view class=" orange">
item2
</view>
<view class=" orange">
item3
</view>
<view class=" orange">
item4
</view>
</view>
<view class="baseline">
<view style="margin-top: 55rpx;">第一行文字</view>
<view class="item1 purple">
item1
</view>
<view class="item2 purple">
item2
</view>
<view class="item3 purple">
item3
</view>
<view class="item4 purple">
item4
</view>
</view>
<view>
flex-start:交叉轴的起点对齐。
flex-end:交叉轴的终点对齐。
center:交叉轴的中点对齐。
baseline: 项目的第一行文字的基线对齐。
stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。
</view>
</view>
</template>
<script>
export default {
data() {
return {
};
}
}
</script>
<style lang="scss">
.item1{
width: 100rpx;
height: 50rpx;
}
.item2{
width: 100rpx;
height: 100rpx;
}
.item3{
width: 100rpx;
height: 125rpx
}
.item4{
width: 100rpx;
height: 150rpx;
}
.red{
background-color: red;
}
.yellow{
background-color: yellow;
}
.blue{
background-color: blue;
}
.orange{
background-color: orange;
}
.purple{
background-color: purple;
}
.flex-start{
display: flex;
align-items: flex-start;
width: 100%;
height: 200rpx;
border: 1Px solid gray;
box-sizing: border-box;
}
.flex-end{
display: flex;
align-items: flex-end;
width: 100%;
height: 200rpx;
border: 1Px solid gray;
box-sizing: border-box;
}
.center{
display: flex;
align-items: center;
width: 100%;
height: 200rpx;
border: 1Px solid gray;
box-sizing: border-box;
}
.stretch{
display: flex;
align-items: stretch;
width: 100%;
height: 200rpx;
border: 1Px solid gray;
box-sizing: border-box;
}
.baseline{
display: flex;
align-items: baseline;
width: 100%;
height: 250rpx;
border: 1Px solid gray;
box-sizing: border-box;
}
</style>

本文详细解释了CSSFlexbox中的align-items属性,展示了flex-start、flex-end、center、stretch和baseline五个对齐方式的示例,以及它们在调整元素在交叉轴上的位置时的作用。
1万+

被折叠的 条评论
为什么被折叠?



