父元素的filter樣式影響子元素樣式
現(xiàn)象
-
解決前示例-標題文本看不清
解決前
- 解決前代碼如下
<template>
<view class="person-center">
<!-- 頭部的背景處理 -->
<view class="header">
<view class="header_title">
<text>個人中心</text>
</view>
</view>
</view>
</template>
<script>
export default {
};
</script>
<style lang="scss" scoped>
.person-center {
.header {
width: 100%;
height: 428rpx;
background: linear-gradient(180deg, #80C8FE 0%, rgba(247, 249, 252, 0) 100%);
filter: blur(10rpx);
padding-top: 88rpx;
.header_title {
height: 88rpx;
line-height: 88rpx;
text-align: center;
}
}
}
</style>
解決辦法
將filter樣式添加給父元素的偽元素上
-
解決后示例
解決后 解決代碼如下
<template>
<view class="person-center">
<!-- 頭部的背景處理 -->
<view class="header">
<view class="header_title">
<text>個人中心</text>
</view>
</view>
</view>
</template>
<script>
export default {
};
</script>
<style lang="scss" scoped>
.person-center {
.header {
width: 100%;
height: 428rpx;
position: relative;
&::before {
content: '';
height: 100%;
width: 100%;
position: absolute;
z-index: -1;
background: linear-gradient(180deg, #80C8FE 0%, rgba(247, 249, 252, 0) 100%);
filter: blur(10rpx);
}
.header_title {
height: 88rpx;
padding-top: 88rpx;
line-height: 88rpx;
text-align: center;
}
}
}
</style>

