东莞浩智网站建设公司,文章采集网站,网站能给企业带来什么,番禺核酸检测点在哪版本说明
当前版本号[20231024]。
20231024初版
目录 文章目录 版本说明目录Flex布局01-标准流02-浮动基本使用产品区域布局HTML标签CSS样式 清除浮动场景搭建额外标签法单伪元素法双伪元素法overfow法 03-Flex布局Flex组成主轴对齐方式侧轴对齐方式修改主轴方向弹性伸缩比弹…版本说明
当前版本号[20231024]。
20231024初版
目录 文章目录 版本说明目录Flex布局01-标准流02-浮动基本使用产品区域布局HTML标签CSS样式 清除浮动场景搭建额外标签法单伪元素法双伪元素法overfow法 03-Flex布局Flex组成主轴对齐方式侧轴对齐方式修改主轴方向弹性伸缩比弹性盒子换行行内对齐方式 04-综合案例 – 某音解决方案 Flex布局
01-标准流
标准流也叫文档流指的是标签在页面中默认的排布规则例如块元素独占一行行内元素可以一行显示多个。 02-浮动
基本使用
作用让块元素水平排列。
属性名float
属性值
left左对齐right右对齐
float: left;特点
浮动后的盒子顶对齐浮动后的盒子具备行内块特点浮动后的盒子脱标不占用标准流的位置
首先我们先设计两个盒子代码如下
!DOCTYPE html
htmlheadmeta charsetutf-8title/title/headstyle.a{width: 200px;height: 200px;background-color: aqua;}.b{width: 350px;height: 350px;background-color: greenyellow;}/stylebodydiv classa第一个/divdiv classb第二个/div/body
/html得出下面这两个模型 那么首先我们先给第一个模型加上浮动
.a{width: 200px;height: 200px;background-color: aqua;float: left;}可以看到第一个就像浮起来的方块占据在了第二个盒子模型的上方 而一旦给第二个模型加上浮动的话
.b{width: 350px;height: 350px;background-color: greenyellow;float: left;}就可以看到第一个第二个模型并在了一起且第一个模型在第二个的左边 产品区域布局 仿照某商城的网页进行设计
左边一个大的div右边一个div中要包含四个小模型 !DOCTYPE html
htmlheadmeta charsetutf-8title产品区域布局/titlestyle*{margin: 0;padding: 0;}li{list-style: none;}.product{margin: 50px auto;width: 1226px;height: 628px;background-color:pink;}.left{width: 234px;height: 628px;background-color: green;}.right{width: 992px;height: 628px;background-color: aqua;}/style/headbodydiv classproductdiv classleft/divdiv classright/div/div/body
/html 由于粉色的是父容器div,第一个div绿色把父容器高度占满了下面的div蓝色要独占一行容纳不下就跑到外父容器外面了。
.left{width: 234px;height: 628px;background-color: green;float: left;}.right{width: 992px;height: 628px;background-color: aqua;float: right;}那么开始设置右边的八个li了
!DOCTYPE html
htmlheadmeta charsetutf-8title产品区域布局/titlestyle*{margin: 0;padding: 0;}li{list-style: none;}.product{margin: 50px auto;width: 1226px;height: 628px;background-color:pink;}.left{width: 234px;height: 628px;background-color: green;float: left;}.right{width: 992px;height: 628px;background-color: aqua;float: right;}.right li{width: 234px;height: 300px;background-color: orange;}/style/headbodydiv classproductdiv classleft/divdiv classrightulli/lili/lili/lili/lili/lili/lili/lili/li/ul/div/div/body
/html由于橙色中包含着八个lili是块级的独占一行我们如果不加任何边距就一行显示了想像上面商城那样呈现八个内容出来就要加浮动 加完浮动发现li标签没有完全覆盖是因为每个li的右边和顶部都有边距 在商城中这个边距为14px我们要把其完善到我们的代码里面 加入边框后我们发现在原本的商城中最后边的一列是不需要加右边距的加完之后可能会在以后运行里li标签跑到下面去 修改了最后边的一列取消掉右边距同时修改了些尺寸使得中间粉色出了一点后续也会进行处理
!DOCTYPE html
htmlheadmeta charsetutf-8title产品区域布局/titlestyle*{margin: 0;padding: 0;}li{list-style: none;}.product{margin: 50px auto;width: 1226px;height: 628px;background-color:pink;}.left{width: 234px;height: 628px;background-color: green;float: left;}.right{width: 978px;height: 628px;background-color: aqua;float: right;}.right li{width: 234px;height: 300px;margin-right: 14px;margin-bottom: 14px;background-color: orange;float: left;}.right li:nth-child(4n){margin-right: 0;}/style/headbodydiv classproductdiv classleft/divdiv classrightulli/lili/lili/lili/lili/lili/lili/lili/li/ul/div/div/body
/html输出结果如下 HTML标签
!-- 版心左右右面8个产品 → 8个 li --
div classproductdiv classleft/divdiv classrightulli/lili/lili/lili/lili/lili/lili/lili/li/ul/div
/divCSS样式
style* {margin: 0;padding: 0;}li {list-style: none;}.product {margin: 50px auto;width: 1226px;height: 628px;background-color: pink;}.left {float: left;width: 234px;height: 628px;background-color: skyblue;}.right {float: right;width: 978px;height: 628px;background-color: brown;}.right li {float: left;margin-right: 14px;margin-bottom: 14px;width: 234px;height: 300px;background-color: orange;}/* 第四个li和第八个li 去掉右侧的margin */.right li:nth-child(4n) {margin-right: 0;}/* 细节如果父级宽度不够浮动的盒子会掉下来 */
/style清除浮动
场景浮动元素会脱标如果父级没有高度子级无法撑开父级高度可能导致页面布局错乱
解决方法清除浮动清除浮动带来的影响
场景搭建 style.top {margin: 10px auto;width: 1200px;/* height: 300px; */background-color: pink;}.left {float: left;width: 200px;height: 300px;background-color: skyblue;}.right {float: right;width: 950px;height: 300px;background-color: orange;}.bottom {height: 100px;background-color: brown;}/stylediv classtopdiv classleft/divdiv classright/div
/div
div classbottom/div通过这段代码可以知道目前已经发生了浮动使得页面变得混乱 额外标签法
在父元素内容的最后添加一个块级元素设置 CSS 属性 clear: both
缺点是加多了一个标签在书写的时候会感觉到标签太多会有些混乱。
style
.clearfix {clear: both;
}
/stylediv classfatherdiv classleft/divdiv classright/divdiv classclearfix/div
/div直到能得到我们想要的答案 单伪元素法
准备 after 伪元素
.clearfix::after {content: ;display: block;clear: both;
}父级使用 clearfix 类
div classfather clearfix/div双伪元素法
准备 after 和 before 伪元素在其中before的功能是解决外边距塌陷的问题而after的功能便是清除浮动。
/* before 解决外边距塌陷问题 */
/* 双伪元素法 */
.clearfix::before,
.clearfix::after {content: ;display: table;
}/* after 清除浮动 */
.clearfix::after {clear: both;
}再让父级使用 clearfix 类使得双伪元素法生效从而清除浮动。
div classfather clearfix/divoverfow法
.top {margin: 10px auto;width: 1200px;/* height: 300px; */background-color: pink;overflow: hidden;}03-Flex布局
Flex 布局也叫弹性布局是浏览器提倡的布局模型非常适合结构化布局提供了强大的空间分布和对齐能力。
Flex 模型不会产生浮动布局中脱标现象布局网页更简单、更灵活。 Flex组成
设置方式给父元素设置 display: flex子元素可以自动挤压或拉伸
组成部分
弹性容器弹性盒子主轴默认在水平方向侧轴 / 交叉轴默认在垂直方向 主轴对齐方式
属性名justify-content 代码
style.top {display: flex;justify-content: center;border: 1px solid green;}.left {width: 200px;height: 300px;background-color: skyblue;}.right {width: 950px;height: 300px;background-color: orange;}.bottom {height: 100px;background-color: brown;}/stylediv classtopdiv classleft/divdiv classright/div
/div
div classbottom/divjustify-content: center;效果 justify-content: space-between;的形成原因是父级会把剩余的尺寸分配成间距
justify-content: space-between;效果 justify-content: space-around;效果其三个空白的间隔中间距离过大两边距离一样 justify-content: space-evenly;效果其三个空白的间隔距离都是一样的 侧轴对齐方式
align-items当前弹性容器内所有弹性盒子的侧轴对齐方式给弹性容器设置align-self单独控制某个弹性盒子的侧轴对齐方式给弹性盒子设置 align-items: stretch;效果 align-items: center;效果 修改主轴方向
主轴默认在水平方向侧轴默认在垂直方向
属性名flex-direction flex-direction: column;效果 代码注释 弹性伸缩比
作用控制弹性盒子的主轴方向的尺寸。
属性名flex
属性值整数数字表示占用父级剩余尺寸的份数。
在默认情况下主轴方向尺寸是靠内容撑开而侧轴默认拉伸
弹性盒子换行
弹性盒子可以自动挤压或拉伸默认情况下所有弹性盒子都在一行显示。
属性名flex-wrap
属性值
wrap换行nowrap不换行默认
flex-wrap: wrap;效果 行内对齐方式
属性名align-content 注意该属性对单行弹性盒子模型无效。 04-综合案例 – 某音解决方案 先制作一个简单的框预留 **ul 对应的盒子模型的位置 **即四个图形所在的盒子模型里面的位置
!DOCTYPE html
htmlheadmeta charsetutf-8title/titlestyle*{margin: 0;padding: 0;box-sizing: border-box;}li{list-style: none;}.box{margin: 50px auto;width: 1200px;height: 418px;border: 1px solid #ddd;border-radius: 10px;}/* ul对应的盒子模型,即四个图形所在的盒子模型里面 */.box ul{padding: 90px 40px 90px 60px;height: 418px;}/style/headbodydiv classboxulli1/lili2/lili3/lili4/li/ul/div/body
/html然后可以看到我们已经建好了4个 li 模型并且四周的 padding 的尺寸也是正确的 然后让弹性盒子换行
flex-wrap: wrap;使主轴对齐在一行之中让 li 之间有距离
justify-content: space-between;输出如下 可见底部存在一行的距离中间的距离也太低。于是我们进行行内对齐实现两行之间有距离
align-content: space-between;输出如下 给每一个li标签里面给补充好信息并且分好图片和文字对应的类相对应进行调整
ullidiv classpicimg src../img/1.svg alt/divdiv classtexth4一键发布多端/h4p发布视频到某音短视频、某瓜视频及某日头条/p/div/lilidiv classpicimg src../img/2.svg alt/divdiv classtexth4管理视频内容/h4p支持修改已发布稿件状态和实时查询视频审核状态/p/div/lilidiv classpicimg src../img/3.svg alt/divdiv classtexth4发布携带组件/h4p支持分享内容携带小程序、地理位置信息等组件扩展内容及突出地域性/p/div/lilidiv classpicimg src../img/4.svg alt/divdiv classtexth4数据评估分析/h4p获取视频在对应产品内的数据表现、获取某音热点及时进行表现评估/p/div/li/ul输出如下 最后只需要把 li 中的粉色背景色去掉即可完成本次案例。