首页 > 移动平台 > 详细

uniapp 子组件没有高度,却要设置里面内容水平垂直居中

时间:2020-02-03 20:20:30      阅读:741      评论:0      收藏:0      [点我收藏+]

场景:在无数据的子组件中,有图片提示,该页面无数据,想要将这个图片水平垂直居中

父组件

<!-- 无内容 -->
<template v-else>
    <no-thing></no-thing>
</template>


components:{
    noThing
},

子组件

<template>
    <view class="nothing">
        <image src="../../static/common/nothing.png" mode="widthFix"></image>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                
            };
        }
    }
</script>

<style lang="scss">
    .nothing{
        background: #FFFFFF;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        image{
            width: 50%;
        }
    }
</style>

可以在图片的父元素上同时使用定位方式和flex布局

uniapp 子组件没有高度,却要设置里面内容水平垂直居中

原文:https://www.cnblogs.com/zhongfang/p/12256636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!