代码:
<template>
<div >
<div class='flexStyle'>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
<span class='contentStyle'></span>
</div>
</div>
</template>
<script>
export default {
data(){
return{
cj:1,
}
},
methods:{
}
}
</script>
<style>
.flexStyle{
height:100px;
display:flex;
justify-content:space-between;
/* 设置超出滚动 */
overflow-x:auto;
}
.contentStyle{
width:50px;
height:50px;
display:inline-block;
background:#a3a2a2;
margin-right:5px;
/* 超出滚动的关键,没有它元素会自动缩小,不会滚动 */
flex-shrink: 0;
}
::-webkit-scrollbar {
/* 隐藏滚动条 */
display: none;
}
</style>
效果:复习弹性布局的各个属性:
justify-content:默认值flex-start
/* Positional alignment */
justify-content: center; /* 居中排列 */
justify-content: start; /* Pack items from the start */
justify-content: end; /* Pack items from the end */
justify-content: flex-start; /* 从行首起始位置开始排列 */
justify-content: flex-end; /* 从行尾位置开始排列 */
justify-content: left; /* Pack items from the left */
justify-content: right; /* Pack items from the right */
/* Baseline alignment */
justify-content: baseline;
justify-content: first baseline;
justify-content: last baseline;
/* Distributed alignment */
justify-content: space-between; /* 均匀排列每个元素
首个元素放置于起点,末尾元素放置于终点 */
justify-content: space-around; /* 均匀排列每个元素
每个元素周围分配相同的空间 */
justify-content: space-evenly; /* 均匀排列每个元素
每个元素之间的间隔相等 */
justify-content: stretch; /* 均匀排列每个元素
'auto'-sized 的元素会被拉伸以适应容器的大小 */
/* Overflow alignment */
justify-content: safe center;
justify-content: unsafe center;
/* Global values */
justify-content: inherit;
justify-content: initial;
justify-content: unset;
flex-shrink:该属性指定了 flex 元素的收缩规则,默认值为1。flex 元素仅在默认宽度之和大于容器的时候才会发生收缩,其收缩的大小是依据 flex-shrink 的值。flex-shrink值越大,收缩程度越高,值为0不收缩