IOS margin-bottom失效

本文探讨了H5页面在iOS设备上margin-bottom样式无效的问题,通过实验发现将margin-bottom改为padding-bottom可以解决问题,初步判断与iOS系统自动管理margins有关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近做一个H5移动端活动,发现一个问题:H5页面设置了margin-bottom,在模拟器和安卓手机上都是正常的,但是IOS手机上就没有效果,一开始以为是层级问题,改为在父层上设置,但是仍然没有效果。

解决:margin-bottom改为padding-bottom或者设置一个div用高度撑开

原因:具体不详,以下是网友总结

参考资料

从IOS8开始,UIView的属性var layoutMargins:UIEdgeInsets指定该View的subview同其edge的间距。AutoLayout使用margins来放置内容。其默认值为8pt。

如果一个View是ViewController的rootview,系统会自动设置和管理margins,top和bottom。margins为0pt。所以自己设定的margin-bottom会失效。

 

(内容高度超出所属父容器,父容器有min-height,内容height是auto)

<template> <view class="container"> <view class="banner-section"> <image class="banner-image" src="/static/IntegrityCulture.png" /> </view> <view class="title">廉洁文化资讯</view> <view class="news-list"> <scroll-view scroll-y="true" :enhanced="true" :use-passive="true" :show-scrollbar="false" class="scroll-container" > <view v-for="item in newsList" :key="item.id" class="news-item" @click="navigateToDetail(item)" > <view class="news-content"> <text class="news-title">{{ item.title }}</text> <text class="news-summary">{{ item.summary }}</text> <text class="news-date">{{ item.publishDate }}</text> </view> <view class="status-box" :class="item.read ? 'read' : 'unread'" > {{ item.read ? '已阅' : '未阅' }} </view> </view> </scroll-view> </view> </view> </template> <script setup> import { ref, onMounted } from 'vue'; const newsList = ref([]); const fetchData = () => { setTimeout(() => { newsList.value = [ { id: 1, title: '廉洁从业,从我做起', summary: '廉洁从业是每一位员工应尽的责任和义务,本文介绍了公司廉洁文化建设的相关要求和实践。', publishDate: '2024-09-10', read: true }, { id: 2, title: '加强反腐倡廉,构建阳光企业', summary: '公司持续加强反腐倡廉工作,推动形成风清气正的企业文化氛围。', publishDate: '2024-09-08', read: false }, { id: 3, title: '廉洁文化进班组,清风正气润人心', summary: '公司组织廉洁文化进班组活动,通过宣传、培训等方式提升员工廉洁意识。', publishDate: '2024-09-05', read: false } ]; }, 500); }; onMounted(() => { fetchData(); // 添加被动事件监听器(可选) setTimeout(() => { const scrollEl = uni.createSelectorQuery().select('.scroll-container'); scrollEl.boundingClientRect(data => { if (data) { console.log('滚动容器高度:', data.height); } }).exec(); }, 300); }); const navigateToDetail = (item) => { uni.navigateTo({ url: `/pages/IntegrityCulture/IntegrityCultureDetail/IntegrityCultureDetail?id=${item.id}` }); }; </script> <style scoped> /* 被动事件优化 */ scroll-view { touch-action: pan-y; -webkit-overflow-scrolling: touch; overflow-scrolling: touch; } .container { padding: 30rpx; background-color: #f9f9f9; height: 100vh; overflow: hidden; box-sizing: border-box; } .banner-section { margin-bottom: 40rpx; border-radius: 16rpx; overflow: hidden; box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1); } .banner-image { width: 100%; height: 320rpx; display: block; } .title { font-size: 36rpx; font-weight: bold; text-align: center; margin-bottom: 40rpx; } .news-list { background-color: #fff; border-radius: 16rpx; overflow: hidden; height: calc(100vh - 500rpx); min-height: 300rpx; } .scroll-container { height: 100%; } .news-item { padding: 30rpx; position: relative; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1rpx solid #eee; } .news-content { flex: 1; padding-right: 20rpx; } .news-title { font-size: 32rpx; font-weight: bold; color: #333; display: block; margin-bottom: 10rpx; } .news-summary { font-size: 28rpx; color: #666; display: block; margin-bottom: 10rpx; line-height: 1.5; } .news-date { font-size: 24rpx; color: #999; display: block; } .status-box { padding: 8rpx 16rpx; font-size: 24rpx; border-radius: 8rpx; min-width: 80rpx; text-align: center; } .status-box.read { background-color: rgba(76, 175, 80, 0.1); color: #4caf50; } .status-box.unread { background-color: rgba(244, 67, 54, 0.1); color: #f44336; } /* 移动设备优化 */ @media (max-height: 600px) { .news-list { height: calc(100vh - 450rpx); } } </style> 我想要news-list板块内部滚动不影响页面其他内容,同时去掉滚动条
最新发布
08-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值