美文网首页
2021-11-08、Float页面布局

2021-11-08、Float页面布局

作者: 疋瓞 | 来源:发表于2021-11-09 17:44 被阅读0次

1、案例说明:

  • 演示float属性和clear属性的使用方法,以及利用margin属性实现块元素水平居中对齐的方法

2、案例演示

2.1、代码

wxml

<view class="box">
    <view class="title">Float页面布局</view>
    <view class="f1">
        <view class="box1">box1</view>
        <view class="box2">box2</view>
        <view class="box3">box3</view>
        <view class="box4">box4</view>
    </view>
    <view class="f2">
        <view class="header">header</view>
        <view class="leftBar">leftBar</view>
        <view class="main">main</view>
        <view class="rightBar">rightbar</view>
        <view class="footer">footer</view>
    </view>
</view>

wxss

.f1{
    height: 240px;
    width: 200px;
    margin: 10px auto;/*上下外边距10px,左右实现居中对齐(左右边距平均分配)*/
}
.box1{
    height: 80px;
    width: 100px;
    margin: 0px auto;
    background-color: red;
}
.box2{
    height: 80px;
    width: 100px;
    float: left;
    background-color: yellow;
}
.box3{
    height: 80px;
    width: 100px;
    float: left;
    background-color: rgb(229, 255, 0);
}
.box4{
    height: 80px;
    width: 100px;
    clear: left;
    margin: 0px auto;
    background-color: green;
}
.f2{
    height: 300px;
    width: 300px;
    margin: 10px auto;
    text-align: center;
}
.header{
    line-height: 75px;
    width: auto;
    background-color: red;
}
.leftBar{
    line-height: 100px;
    width: 50px;
    background-color: yellow;
    float: left;
}
.main{
    line-height: 100px;
    width: 200px;
    background-color: rgb(0, 255, 128);
    float: left;
}
.rightBar{
    line-height: 100px;
    width: 50px;
    background-color: yellow;
    float: left;
}
.footer{
    line-height: 75px;
    background-color: red;
    clear: left;
}

2.2、结果展示

结果.jpg

3、总结

知识点.jpg
float属性的合法值.jpg
clear属性的合法值.jpg
利用margin属性实现水平居中对齐.jpg
  • 关于wxml中元素层级的认识
    类似view和image之类的都是“组件”,组件当中会有“属性”,每个属性需要设定“合法值”,注意属性设定合法值一般是通过“:”,也有特殊的属性像class和style,设定合法值用“=”
  • 是否在同一容器中使用一次float都要在下一个元素中加clear
    建议添加

相关文章

  • 2021-11-08、Float页面布局

    1、案例说明: 演示float属性和clear属性的使用方法,以及利用margin属性实现块元素水平居中对齐的方法...

  • 跟高老师学习Web前端之46.

    今天开始进入新课程的学习---页面布局元素。 页面布局元素包含:display、float、clear、visib...

  • css-布局

    历史 1 .table布局2 .float布局3 .fllex布局 默认:正常流布局 1 .在不对页面进行任何布局...

  • CSS布局 ——从display,position, float

    CSS布局 ——从display,position, float属性谈起 页面布局,或者是在页面上做些小效果的时候...

  • CSS的浮动属性

    CSS浮动和清除浮动 1.浮动float div配合float浮动来做页面的布局,浮动最常用的地方就是用来做布局。...

  • css中常见的布局方式

    三栏布局 三栏布局是页面中比较常见的布局方式,也有好几种实现方式,分别是flex布局,grid布局,float布局...

  • CSS布局-float/flex

    Get Started • 布局• float布局• flex布局 布局是什么 把页面分成一块一块,按左中右,上中...

  • 页面布局:absolute/relative/float

    块元素前后都要独占一行而內联元素不需要,这是基础。 position:fixed 当元素设置该属性之后,这个元素...

  • css布局

    css页面布局是对页面的文字、图像或表格进行格式化排列,网页布局对改善网站的外观非常重要。 1.左右布局float...

  • CSS3 flex盒子语法介绍

    在以前页面布局多依赖于table,但table标签太多,于是有了absolute布局,float布局等,但它们小问...

网友评论

      本文标题:2021-11-08、Float页面布局

      本文链接:https://www.haomeiwen.com/subject/cszuzltx.html