小程序image上下水平居中

Vue / 342人浏览 / 0人评论

例子,.container是一个flex容器,它通过justify-content和align-items实现了水平和垂直居中。.image-container是组件的父容器,也使用flex布局来居中图片。.image是组件的样式,你可以根据需要调整宽度和高度。

在uniapp中要实现<image>组件的上下和水平居中结对定位,可以使用flex布局。

<template>
  <view class="container">
    <view class="image-container">
      <image src="your-image-url.png" class="image"></image>
    </view>
  </view>
</template>
 
<style>
  .container {
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 上下居中 */
    height: 100%; /* 容器高度 */
  }
 
  .image-container {
    display: flex;
    justify-content: center; /* 图片水平居中 */
    align-items: center; /* 图片上下居中 */
  }
 
  .image {
    width: 100px; /* 图片宽度 */
    height: 100px; /* 图片高度 */
  }
</style>

在这个例子中,.container是一个flex容器,它通过justify-content和align-items实现了水平和垂直居中。.image-container是<image>组件的父容器,也使用flex布局来居中图片。.image是<image>组件的样式,你可以根据需要调整宽度和高度。

转载注明:

扩展查找

0 条评论

还没有人发表评论

发表评论 取消回复

记住我的信息,方便下次评论
有人回复时邮件通知我