webgis入门之html与css(2)

 WEBGIS开发

目录

 WEBGIS开发

01、选择器权重问题1

02、选择器权重问题2

03、form表单

04、浮动

05、为什么不用内联块标签

06、浮动问题

07、解决浮动问题

08、css引入

09、定位

10、使用z-index决定图层显示顺序

11、固定定位

12、transform

13、shadow阴影

14、flex布局

15、flex练习


01、选择器权重问题1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            background-color: blue !important;/*!import优先级最高*/
        }
        /*类选择器权重大于标签选择器*/
        .box{
            background-color: brown;
        }
        /*id选择器大于类选则器*/
        .app{
            background-color: blanchedalmond;
        }
    </style>
</head>
<body>
    <div class="box" id="app" style="background-color: black;"></div>
</body>
</html>


02、选择器权重问题2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /*选择器嵌套越深优先级越高*/
        .li{
            color: red;
        }
        ul>li{
            color: aqua;
        }
        .parent ul li{
            color: aquamarine;
        }
        html body .parent ul li{
            color: purple;
        }
    </style>
</head>
<body>
    <div class="parent">
        <ul>
            <li>
                hello
            </li>
        </ul>
    </div>
</body>
</html>


03、form表单

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <div>
            用户名:<input type="text" placeholder="请输入用户名">
            用户名:<input type="password" placeholder="请输入密码">
        </div>
        <hr>
        <div>
            <!-- type="radio"就是单选框  但是name要一致 -->
            男<input type="radio" name="sex">
            女<input type="radio" name="sex">
        </div>
        <hr>    
        <div>
            <!-- type="checkbox"为多选框 -->
            爱好:
            <input type="checkbox" name="" id="">吃饭
            <input type="checkbox" name="" id="">睡觉
            <input type="checkbox" name="" id="">打豆豆
        </div>
        <hr>
        <div>
            请选择城市:
            <select name="" id="">
                <option value="北京">北京</option>
                <option value="上海">上海</option>
                <option value="广州">广州</option>
                <option value="深圳">深圳</option>
            </select>
        </div>
        <hr>
        <div>
            <!-- 长文本 -->
            <textarea name="" id="" cols="50" rows="20"></textarea>
        </div>
        <div>
            <!-- type="submit" input为一个提交按钮 -->
            <input type="submit">
        </div>
    </form>
</body>
</html>


04、浮动

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .one{
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;
            /* 浮动元素就会脱离文档流 浮动的目的就是并排显示 */
        }
        .two{
            width: 200px;
            height: 200px;
            background-color: blue;
            float: left;
            /* 浮动元素就会脱离文档流 浮动的目的就是并排显示 */
        }
    </style>
</head>
<body>
    <div class="one"></div>
    <div class="two"></div>
</body>
</html>


05、为什么不用内联块标签

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            height: 40px;
            background-color: pink;
        }
        .one{
            /* 不用inlineblock 因为元素之间存在空隙 */
            width: 40px;
            height: 40px;
            background-color: red;
            float: left;
            margin-right: 30px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="one"></div>
        <div class="one"></div>
        <div class="one"></div>
    </div>
</body>

</html>


06、浮动问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .parent{
            width: 200px;
            background-color: green;
        }
        .one{
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;
        }
        .two{
            width: 200px;
            height: 200px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <!-- 1、子元素使用浮动,会导致父元素高度坍塌 -->
    <!-- 2、对后面的元素造成了干扰 -->
    <div class="parent">
        <div class="one"></div>
    </div>
    <div class="two"></div>
</body>
</html>

07、解决浮动问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .parent{
            width: 200px;
            /* height: 100px;给高度 */
            background-color: green;

            /* 超出部分隐藏:里面元素浮动 */
            overflow: hidden;
        }
        .one{
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;
        }
        .two{
            width: 200px;
            height: 200px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <!-- 1、给父元素高度 防止坍塌 -->
    <!-- 2、使用overflow:hidden -->
    <div class="parent">
        <div class="one"></div>
    </div>
    <div class="two"></div>
</body>
</html>


08、css引入

.css文件

div{
    color: blue;
}

在html中引用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入外部样式 -->
    <link rel="stylesheet" href="./08、css引入.css">
    <style>
        /* 内部样式表 */
    </style>
</head>
<body>
    <!-- 直接写标签上为内联样式 不推荐 尽量不写 -->
    <div>
        hello
    </div>
</body>
</html>


09、定位

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 400px;
            height: 400px;
            background-color: blue;
            /* position: relative; */
        }
        .box2{
            width: 150px;
            height: 150px;
            background-color: red;
            position: absolute;
            left: 40px;
            bottom: 10%;
        }
        /* 相对定位 相对于自己原来的正常位置进行一个定位 */
        /* 绝对定位 先找自己的祖先元素 如果祖先有定位 根据祖先元素定位 否则根据body定位 */
    </style>
</head>
<body>
    <div class="box">
        <div class="box2"></div>
    </div>
</body>
</html>


10、使用z-index决定图层显示顺序

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 400px;
            height: 400px;
            background-color: blue;
        }
        .one{
            width: 100px;
            height: 100px;
            background-color: red;
            position: absolute;
            z-index: 3;
        }
        .two{
            width: 150px;
            height: 150px;
            background-color: green;
            position: absolute;
            z-index: 2;
            /* 元素重叠时层级用z-index */
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="one"></div>
        <div class="two"></div>
    </div>
</body>
</html>


11、固定定位

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            height: 2000px;
        }
        button{
            position: fixed;
            right: 30px;
            bottom: 30px;
        }
    </style>
</head>
<body>
    <div>1</div>
    <button>top</button>
</body>
</html>


12、transform

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 200px;
            height: 200px;
            background-color: black;
            /* 水平 垂直偏移 */

            /* 经典面试题 实现元素在页面的水平垂直居中 */
            position: absolute;
            top:50%;
            left:50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>


13、shadow阴影

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background-color: red;

            /* 左右偏移 上下偏移 模糊程度 阴影大小 阴影颜色 */
            box-shadow: 5px 5px 5px 5px #333;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>


14、flex布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* flex弹性盒子布局 */

        /* 容器 */
        .box{
            width: 460px;
            height: 320px;
            border: 1px solid #000;
            margin:0 auto;
            display: flex;
            
            /* 是否换行 */
            flex-wrap: wrap;
            /* 主轴对齐方式 space-around space-between space-evenly */
            justify-content: space-evenly;
            /* 纵轴对其方式 flex-start center flex-endf*/
            align-items: center;
            /* 设置主轴 row是水平 column是垂直 默认是水平 */
            flex-direction: row;
        }
        /* 项目 */
        .item{
            width: 100px;
            height: 100px;
            border:1px solid #000;
            background-color: red;
            border-radius: 10px 10px 10px 10px;

            /* 设置项目在纵轴上的对其方式 flex-start center flex-end */
            /* align-self: flex-start; */
        }
        .one{
            /* 占主轴宽度比例 */
            flex: 1;
        }
        .two{
            flex: 2;
        }
        .three{
            flex: 3;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <!-- <div class="item one"></div>
        <div class="item two"></div>
        <div class="item three"></div> -->
    </div>
</body>
</html>


15、flex练习

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 300px;
            border: 1px solid #333;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
            align-items: center;
        }

        .item {
            width: 10px;
            height: 10px;
            background-color: red;
            border-radius: 50%;
        }
        .t{
            width: 100px;
            height: 100px;
            border: 1px solid #333;
            position: relative;
        }
        .q1{
            display: flex;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            justify-content: center;
            align-content: center;
        }
        .q2{
            display: flex;
            position: absolute;
            top: 25%;
            left: 75%;
            transform: translate(-50%,-50%);
            justify-content: center;
            align-content: center;
        }
        .q3{
            display: flex;
            position: absolute;
            top: 75%;
            left: 25%;
            transform: translate(-50%,-50%);
            justify-content: center;
            align-content: center;
        }
        .q4{
            display: flex;
            position: absolute;
            top: 25%;
            left: 25%;
            transform: translate(-50%,-50%);
            justify-content: center;
            align-content: center;
        }
        .q5{
            display: flex;
            position: absolute;
            top: 75%;
            left: 75%;
            transform: translate(-50%,-50%);
            justify-content: center;
            align-content: center;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="t">
            <div class="item q1"></div>
        </div>

        <div class="t">
            <div class="item q2"></div>
            <div class="item q3"></div>
        </div>
        <div class="t">
            <div class="item q2"></div>
            <div class="item q1"></div>
            <div class="item q3"></div>
        </div>
        <div class="t">
            <div class="item q4"></div>
            <div class="item q2"></div>
            <div class="item q3"></div>
            <div class="item q5"></div>
        </div>
        <div class="t">
            <div class="item q1"></div>
            <div class="item q1"></div>
            <div class="item q1"></div>
            <div class="item q1"></div>
            <div class="item q1"></div>
        </div>
        <div class="t">
            <div class="item q1"></div>
            <div class="item q1"></div>
            <div class="item q1"></div>
            <div class="item q1"></div>
            <div class="item q1"></div>
            <div class="item q1"></div>
        </div>
    </div>
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值