H5:常用css3属性box-sizing,display:box

本文详细介绍了CSS3中的盒模型属性,包括box-sizing的作用及不同取值的效果,display:box和box-flex属性如何实现按比例布局,以及box-orient、box-direction和box-align等属性的应用方法。

box-sizing属性:允许您以特定的方式定义匹配某个区域的特定元素。

box-sizing有三个取值:content-box|border-box|inherit;默认情况下值为content-box

content-box:宽度和高度分别应用到元素的内容框。在宽度和高度之外绘制元素的内边距和边框。

border-box:为元素设定的宽度和高度决定了元素的边框盒。为元素指定的任何内边距和边框都将在已设定的宽度和高度内进行绘制。通过从已设定的宽度和高度分别减去边框和内边距才能得到内容的宽度和高度。

inherit:规定应从父元素继承 box-sizing 属性的值。

兼容性:

Internet Explorer、Opera 以及 Chrome 支持 box-sizing 属性。

Firefox 支持替代的 -moz-box-sizing 属性。

box-sizing:border-box;

-moz-box-sizing:border-box; /* Firefox */

-webkit-box-sizing:border-box; /* Safari */




display:box,box-flex属性是css3新添加的盒子模型属性,可以实现按比例布局,比如垂直等高、水平均分。

浏览器兼容性:

firefox(-moz-)、opera(-o-)、chrome/safari(-webkit-)。

display:-moz-box;

display:-webkit-box;

display:box;

子元素:

-moz-box-flex:1;

-webkit-box-flex:1;

box-flex:1;


注意:

必须给父容器定义css属性display:box其子容器才可以进行划分,如果定了display:box则该容器定义为了内联元素,如果其中一个子容器或多个子容器设置了固定宽度,设置固定宽度的子容器的宽度是固定的,其他元素的宽度是父元素宽度减去设置了宽度的子容器的宽度,然后再按照比例划分:


例如:

.wrap{

    width:300px;

    height:100px;

    display:-moz-box;

    display:-webkit-box;

    display:box;

}

.one{  

     -moz-box-flex:1;

     -webkit-box-flex:1;

     box-flex:1;

}

.two{

    width:200px;

 }


box-orient属性:用来确定父容器里子容器的排列方式,是水平还是垂直

取值有:

horizontal:可将子容器水平排列

vertical:可将子容器垂直排列

inline-axis :可将子容器水平排列

block-axis :可将子容器垂直排列

inherit : inherit属性则是让子容器继承父容器的相关属性。

.wrap{

width:600px;

height:200px;

display:-moz-box;

display:-webkit-box;

display:box;

-moz-box-orient:horizontal;

-webkit-box-orient:horizontal;

box-orient:horizontal;//水平排列

}

box-direction属性:box-direction用来确定父容器里的子容器排列顺序

取值:normal | reverse | inherit  


normal :normal是默认值,按照HTML文档里结构的先后顺序依次展示

reverse :可以反转排列顺序

inherit:继承父元素的设置

box-align:表示父容器里面子容器的垂直对齐方式  

取值:

start :居顶对齐

end:居底对齐

center :居中对齐

baseline:

stretch:

box-pack:父容器里面子容器的水平对齐方式

取值有:start | end | center | justify


获取更多的文章,欢迎关注微信公众号



<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 ? &#39;read&#39; : &#39;unread&#39;" > {{ item.read ? &#39;已阅&#39; : &#39;未阅&#39; }} </view> </view> </scroll-view> </view> </view> </template> <script setup> import { ref, onMounted } from &#39;vue&#39;; const newsList = ref([]); const fetchData = () => { setTimeout(() => { newsList.value = [ { id: 1, title: &#39;廉洁从业,从我做起&#39;, summary: &#39;廉洁从业是每一位员工应尽的责任和义务,本文介绍了公司廉洁文化建设的相关要求和实践。&#39;, publishDate: &#39;2024-09-10&#39;, read: true }, { id: 2, title: &#39;加强反腐倡廉,构建阳光企业&#39;, summary: &#39;公司持续加强反腐倡廉工作,推动形成风清气正的企业文化氛围。&#39;, publishDate: &#39;2024-09-08&#39;, read: false }, { id: 3, title: &#39;廉洁文化进班组,清风正气润人心&#39;, summary: &#39;公司组织廉洁文化进班组活动,通过宣传、培训等方式提升员工廉洁意识。&#39;, publishDate: &#39;2024-09-05&#39;, read: false } ]; }, 500); }; onMounted(fetchData); const navigateToDetail = (item) => { uni.navigateTo({ url: `/pages/IntegrityCulture/IntegrityCultureDetail/IntegrityCultureDetail?id=${item.id}` }); }; </script> <style scoped> /* 整体容器 */ .container { padding: 30rpx; background-color: #f9f9f9; height: 100vh; overflow: hidden; box-sizing: border-box; display: flex; flex-direction: column; } /* 顶部区域 */ .banner-section { margin-bottom: 40rpx; border-radius: 16rpx; overflow: hidden; box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1); flex-shrink: 0; } .banner-image { width: 100%; height: 320rpx; display: block; } .title { font-size: 36rpx; font-weight: bold; text-align: center; margin-bottom: 40rpx; flex-shrink: 0; } /* 滚动区域 */ .news-list { background-color: #fff; border-radius: 16rpx; overflow: hidden; flex: 1; min-height: 0; display: flex; flex-direction: column; box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05); } /* 滚动容器 */ .scroll-container { flex: 1; height: 100%; overflow: hidden; box-sizing: border-box; } /* 隐藏滚动条 */ .scroll-container ::-webkit-scrollbar { display: none; width: 0; height: 0; color: transparent; } scroll-view { height: 100%; -ms-overflow-style: none; scrollbar-width: none; } /* 新闻项样式 */ .news-item { padding: 30rpx; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1rpx solid #eee; transition: background-color 0.2s; } .news-item:active { background-color: #f5f7fa; } .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; flex-shrink: 0; } .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) { .banner-image { height: 280rpx; } .news-list { border-radius: 12rpx; } } </style> 整个页面滚动,有没有可能是uniapp顶部的"navigationBarTitleText" : "廉洁文化",占据了一定页面高度,导致下面的页面内容高度超出了一部分所以会有整个页面滚动
08-15
<template> <view class="container"> <view class="title"> <view class="headSpan">照明</view> <view class="lineSpan">行业智能供应链</view> </view> <view class="search-top search-normal"> <view class="search-box"> <input placeholder="请输入" type="text" v-model="searchText" /> </view> </view> <IndustryData></IndustryData> </view> </template> <script setup> import IndustryData from "@/components/IndustryData.vue" import { ref } from &#39;vue&#39;; let searchText = ref(&#39;&#39;) </script> <style lang="scss"> @import "../../static/scss/publicContainer.scss"; $boxs-margin: 10px; //每个盒子之前的margin距离 .title { text-align: center; font-family: "PangMenZhengDao"; font-style: normal; display: flex; flex-direction: column; height: 50px; .headSpan { font-family: "PangMenZhengDao"; display: flex; width: 88px; height: 25px; flex-direction: column; justify-content: center; font-size: 22px; font-weight: 800; line-height: 22px; letter-spacing: 2.4px; background: linear-gradient(90deg, #E9BC82 12.5%, #FFEECB 51.09%, #E9BC82 89.67%); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } .lineSpan { display: flex; width: 88px; height: 15px; flex-direction: column; justify-content: center; flex-shrink: 0; font-family: "PangMenZhengDao"; font-size: 10px; font-weight: 800; line-height: 12px; letter-spacing: 1px; background: linear-gradient(90deg, #E9BC82 12.5%, #FFEECB 51.09%, #E9BC82 89.67%); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } } .search-top { position: sticky; top: calc(var(--status-bar-height) + $marginHead + $boxs-margin); } .search-normal { width: 65vw; } .search-box { display: flex; padding: 6px 12px; height: 28px; align-items: center; flex: 1 0 0; align-self: stretch; border-radius: 30px; background-color: #E6E6E6; color: black; z-index: 999; margin: $boxs-margin auto; } </style> 帮我修改代码,做到sticky触发的时候searchbox宽度为width: 65vw;,但是正常时候是100
06-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值