uniapp flex:1不生效

文章讨论了在Vue模板中,由于view层级结构问题,无法在container-content-box内直接使用display:flex。作者指出这可能导致flex布局失效,并可能需要考虑其他布局方式或调整组件结构以解决这个问题。
摘要由CSDN通过智能技术生成
包裹view顶层 不能添加 display: flex;
<template>
	<view class="container">
		<tHeader :title="'采购管理'" :showScrollTar="true" :scroll="scroll" :tabList="tabList" :isFixed="true"
			@change="changeTar" :current='current'>
		</tHeader>
		<view class="container-content-box">
			<view v-for="(item,index) in inventoryCostList" :key="index">
				<view class="cost-item-title-box">
					<uni-icons type="staff" color="#2167FF" size="24"></uni-icons>
					<view class="cost-item-title-name-box">
						{{item.deptName}}
					</view>
				</view>
				<view class="cost-item-content-box">
					<view class="cost-item-content-flex-box">
						<view class="cost-item-content-flex-name-box">
							自采成本
						</view>
						<view class="cost-item-content-flex-value-box">
							¥{{item.selfPrice}}
						</view>
					</view>
					<view class="cost-item-content-flex-box">
						<view class="cost-item-content-flex-name-box">
							采购调拨成本
						</view>
						<view class="cost-item-content-flex-value-box">
							¥{{item.allotPrice}}
						</view>
					</view>
					<view class="cost-item-content-flex-box">
						<view class="cost-item-content-flex-name-box">
							采购调拨成本
						</view>
						<view class="cost-item-content-flex-value-box">
							¥{{item.allotPrice}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<style lang="scss">
	.container {
		background-color: #F4F8FB;
		height: 100%;
		width: 100%;

		.btn-box {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			padding-right: 24rpx;
			color: #FFF;
		}

		.container-title-height {
			height: calc(var(--status-bar-height) + 150rpx);
		}

		.date-picker-box {
			background-color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #00327D;
			font-size: 30rpx;
			line-height: 30rpx;
			padding: 30rpx 0;

			.date-icon {
				display: inline-block;
				width: 30rpx;
				height: 30rpx;
			}

			.start-text {
				padding-left: 20rpx;
			}

			.date-connect {
				padding: 0 8rpx;
			}
		}

		.container-content-box {
			background-color: #FFF;
			border-radius: 10rpx;
			margin: 25rpx;
			padding: 25rpx;

			.cost-item-title-box {
				display: flex;
				align-items: center;
				justify-content: center;
				color: #333;
				flex-direction: row;

				.cost-item-title-name-box {
					font-size: 30rpx;
					font-weight: bold;
				}
			}

			.cost-item-content-box {
				background-color: #F7FAFF;
				padding: 25rpx;
				margin: 20rpx;
				flex-direction: row;
				border-radius: 10rpx;
				display: flex;

				.cost-item-content-flex-box {
					display: flex;
					flex: 1;
					align-items: center;
					justify-content: center;
					color: #333;
					flex-direction: column;

					.cost-item-content-flex-name-box {
						color: #666;
						display: flex;
						font-size: 26rpx;
					}

					.cost-item-content-flex-value-box {
						color: #333;
						font-size: 24rpx;
						margin-top: 15rpx;
						font-weight: bold;
					}
				}
			}
		}
	}
</style>

这一层级,不能写display: flex;写了底下的 flex:1 不生效
.container-content-box{}

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UniApp中使用position: sticky属性时可能会遇到不起作用的问题。有几个常见的原因可能导致这种情况发生。 首先,必须指定top、right、bottom或left四个阈值之一,并且达到设定的阈值,才能使粘性定位生效。如果没有指定这些阈值,position: sticky的行为将与position: relative相同。因此,请确保在设置position: sticky时指定了相应的阈值。 其次,position: sticky的元素的任意父节点的overflow属性必须是visible。如果父容器的overflow属性不是visible,则position: sticky将无法起作用。因此,请确保position: sticky元素的任意父节点的overflow属性设置为visible。 另外,设置了position: sticky的元素的父容器的高度必须大于当前元素的高度。如果父容器的高度小于position: sticky元素的高度,粘性定位也会失效。所以请确保父容器的高度足够大以容纳position: sticky元素。 最后,如果你使用的是Flex布局,请将position: sticky元素的高度设置为fit-content。在Flex布局中,设置position: sticky的元素的高度为fit-content可以确保它正常工作。 总结一下,在UniApp中使用position: sticky时,请确保指定了top、right、bottom或left的阈值,并且达到了设定的阈值。同时,父容器的overflow属性应设置为visible,父容器的高度应大于position: sticky元素的高度。如果使用了Flex布局,请将position: sticky元素的高度设置为fit-content。这样就能确保position: sticky属性正常工作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [position:sticky用法介绍及浏览器兼容性](https://download.csdn.net/download/weixin_38724919/14829608)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [设置position: sticky;不生效的原因](https://blog.csdn.net/weixin_42337801/article/details/125197355)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [uniapp scroll-view顶部吸附之position: sticky;](https://blog.csdn.net/m0_50080847/article/details/127552750)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值