CSS3如何横向居中+纵向居中 in grid container
Posted Rudon滨海渔村
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSS3如何横向居中+纵向居中 in grid container相关的知识,希望对你有一定的参考价值。
效果图
横向:三个子元素均匀分布 flex-direction: row; justify-content: space-between;
纵向:三个子元素垂直居中 align-items: center;
核心代码
.heng
display: flex;
flex-direction: row;
justify-content: space-between;
.heng > view
display: flex;
flex-direction: row;
justify-content: center;
.shu
align-items: center;
完整html.vue (in HBuilderX)
<template>
<view>
<view class="box">
<view class="r-header-wrapper heng shu">
<view class="rh-left">
<view class="popupCityWrapper" v-show="showingCities">
<view class="itemCity" v-for="(item, key) in cities" :key="key" @click="selectCity(item)">
<text>item</text>
</view>
</view>
<view class="rh-city-shower">
city
</view>
<view class="rh-city-icon" @click="tCity">
<uni-icons type="bottom" :size="20"></uni-icons>
</view>
</view>
<view class="rh-center">
<uni-easyinput v-model="search" placeholder="输入搜索关键词" prefixIcon="search" />
</view>
<view class="rh-right" @click="goScan">
<uni-icons type="scan"></uni-icons>
</view>
</view>
</view>
</view>
</template>
<script>
export default
data()
return
showingCities: false,
search : "",
cities: [
"上海",
"北京",
"广州",
"深圳"
],
city: ''
,
methods:
tCity (e)
this.showingCities = !this.showingCities
,
selectCity (e)
this.city = e;
this.tCity()
,
goScan (e)
,
onLoad ()
this.city = this.cities[0]
</script>
<style>
.box
background-color: white;
padding: 15rpx;
margin: 15rpx 25rpx;
border-radius: 12rpx;
.rh-left
width: 140rpx;
display: flex;
flex-direction: row;
position: relative;
.rh-right
width: 80rpx;
.r-header-wrapper
height: 100rpx;
.popupCityWrapper
position: absolute;
top: 60rpx;
left: 5rpx;
.itemCity
padding: 15rpx 30rpx;
border: #B1B5BC 1rpx solid;
border-radius: 10rpx;
background-color: white;
cursor: pointer;
.heng
display: flex;
flex-direction: row;
justify-content: space-between;
.heng > view
display: flex;
flex-direction: row;
justify-content: center;
.shu
align-items: center;
</style>
试过不行的终极解决方案:不生效
.flexBoxWrapper
place-content: center;
对齐
以上是关于CSS3如何横向居中+纵向居中 in grid container的主要内容,如果未能解决你的问题,请参考以下文章
PHPWordPHPWord动态生成表格table | 单元格横向合并单元格纵向合并单元格边框样式单元格垂直水平居中