前端五

作者: 要你何用杀了算了 | 来源:发表于2018-08-12 19:08 被阅读0次

今天是学习前端第五的学习内容,内容如下:
1.高度塌陷

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>高度塌陷 </title>
    <style type="text/css">
        .box{
            border: 10px red solid;
            
        }
        .box1{
            
            width: 100px;
            height: 100px;
            background-color: yellow;
            float: left;
        }
        .box2{
            height: 100px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1"></div>
    </div>
    <div class="box2"></div>
</body>
</html>

运行结果:


image.png

2.解决高度塌陷1

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>解决高度塌陷1</title>
    <style type="text/css">
        .box{
            border: 10px red solid;
            /*能解决有缺陷*/
            /*float: left;*/
            /*display: inline-block;*/
            /*能解决缺陷最小  经常用overflow: hidden;  zoom:1  两句一起写*/
            overflow: hidden;
            zoom:1;
        }
        .box1{
            
            width: 100px;
            height: 100px;
            background-color: yellow;
            float: left;
        }
        .box2{
            height: 100px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1"></div>
    </div>
    <div class="box2"></div>
</body>
</html>

运行结果:


image.png

3.导航条

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>导航条</title>
    <style type="text/css">
        *{
            margin:0px;
            padding: 0;
        }
        .nav{
            /*去掉小圆点*/
            list-style: none;
            /*颜色*/
            background-color: #6495ed;
            /*宽度*/
            width: 1000px;
            /*居中*/
            margin:50px auto;
            /*阻止塌陷*/
            overflow: hidden;
            zoom: 1;
        }
        .nav li{
            /*浮动   让它左浮动*/
            float: left;
            /*继承上面4/1*/
            width: 25%;
        }
        .nav a{
            display: block;
            /*继承上面4/1的100%*/
            width: 100%;
            /*距离*/
            padding: 5px 0;
            /*让文字具中间*/
            text-align: center;
            /*去掉下划线*/
            text-decoration:none;
            /*字母加粗*/
            font-weight: bold;
            color: #fff;

        }
        .nav a:hover{
            /*鼠标点击颜色*/
            background-color: #cc0000;
        }


    </style>
</head>
<body>
    <ul class="nav">
        <li><a href="#">首页</a></li>
        <li><a href="#">新闻</a></li>
        <li><a href="#">联系</a></li>
        <li><a href="#">关于</a></li>
    </ul>
</body>
</html>

运行结果:


image.png
image.png

4.清除浮动

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>清除浮动 </title>
    <style type="text/css">
        .dox{
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;
        }
        .dox1{
            width: 200px;
            height: 200px;
            background-color: blue;
            /*可以清除浮动 clear: */
            clear: left;
        }
        .dox2{
            width: 300px;
            height: 300px;
            background-color: yellow;
        }
    
    </style>
</head>
<body>
    <div class="dox"> </div>
    <div class="dox1"> </div>
    <div class="dox2"> </div>
</body>
</html>

运行结果:


image.png
  1. 解决塌陷2
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title> 解决塌陷2</title>
    <style type="text/css">
        .dox{
            
            border: 1px  solid red; 
        }
        .dox1{
            width: 100px;
            height: 100px;
            background-color: blue;
            float: left;        
        }
        /*没有浮动  可以撑开dox1*/
        .clear{
            clear:  both;   
        }
    
    </style>
</head>
<body>
    <div class="dox">
        a
        <div class="dox1"> </div>
        <div class="clear"> </div>
    
    </div>
</body>
</html>

运行结果:


image.png

6.解决塌陷2

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title> 解决塌陷2</title>
    <style type="text/css">
        .dox{
            
            border: 1px  solid red; 
        }
        .clearfix:after{
            content: "";
            display: block;
            clear: both;
        }
        .clearfix{
            zoom: 1;
        }
        .dox1{
            width: 100px;
            height: 100px;
            background-color: blue;
            float: left;        
        }
    
    
    </style>
</head>
<body>
    <div class="dox clearfix">  
        <div class="dox1"> </div>
    </div>
</body>
</html>

运行结果:


image.png

7.相对定位

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>相对定位</title>
    <style type="text/css">
        .dox{
            width: 100px;
            height: 100px;
            background-color: red;
            
        }
        .dox1{
            width: 100px;
            height: 100px;
            background-color: blue;
            /*定位  能让它移动 左右上下*/
            position: relative;
            left: 100px;
            top:100px;
        }
        .dox2{
            width:100px;
            height: 100px;
            background-color: yellow;
        }
    
    </style>
</head>
<body>
    <div class="dox"> </div>
    <div class="dox1"> </div>
    <div class="dox2"> </div>
</body>
</html>

运行结果:


image.png

8.绝对定位

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>绝对定位</title>
    <style type="text/css">
        .dox{
            width: 100px;
            height: 100px;
            background-color: red;
            
        }
        .dox1{
            width: 100px;
            height: 100px;
            background-color: blue;
            position: absolute;
            left: 0px;
            top: 0px;
        }
        .dox2{
            width:100px;
            height: 100px;
            background-color: yellow;
        }
    
    </style>
</head>
<body>
    <div class="dox"> </div>
    <div class="dox1"> </div>
    <div class="dox2"> </div>
</body>
</html>

运行结果:

image.png

9.固定定位

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>固定定位</title>
    <style type="text/css">
        .dox{
            width: 100px;
            height: 100px;
            background-color: red;
            
        }
        .dox1{
            width: 100px;
            height: 100px;
            background-color: blue;
            position:fixed;
            left: 0px;
            top: 0px;
        }
        .dox2{
            width:100px;
            height: 100px;
            background-color: yellow;
        }
    
    </style>
</head>
<body>
    <div class="dox"> </div>
    <div class="dox1"> </div>
    <div class="dox2"> </div>
</body>
</html>

运行结果:


image.png

相关文章

  • 前端五

    今天是学习前端第五的学习内容,内容如下:1.高度塌陷 运行结果: 2.解决高度塌陷1 运行结果: 3.导航条 运行...

  • 前端(五)

    解决塌陷 高度塌陷 在文档流中,父元素的高度默认是被子元素撑开的,也就是子元素多高,父元素就多高。但是当为子元素设...

  • 聊聊你对前端的了解

    我们都知道“前端工程师”,但是到底什么叫前端,前端是做什么的? 对于前端的称呼可谓是五花八门,在公司切图的是前端,...

  • 前端学习(五)

    CSS简介: 层叠样式表:CascadingStyleSheet 所谓层叠,可以将整个网页想象为多层叠合的结构,层...

  • 自学web前端到什么程度才能就业?

    做过五年web前端从业者,回答下这个问题 首先,这个问题主要问:自学web前端技术,如果才能找到一份web前端的工...

  • web前端学习规划

    做过五年web前端从业者,回答下这个问题 首先,这个问题主要问:自学web前端技术,如果才能找到一份web前端的工...

  • 好程序员web前端培训教程分享前端三大框架有哪些异同

    好程序员web前端培训教程分享前端三大框架有哪些异同,web前端的框架可谓五花八门,多到让你想象不到,但能沉淀下来...

  • 前端三大框架有哪些异同?

    前端三大框架有哪些异同,web前端的框架可谓五花八门,多到让你想象不到,但能沉淀下来的不多,而所谓的前端三大框架,...

  • 前端学习任务五

    问答 样式有几种引入方式? link 和 @import有什么区别? 有四种引入方法:1.link外链式2.@im...

  • 前端学习笔记五

    css:层叠样式表 所有标签都有默认样式,受浏览器影响。 css的三种编写方式:1.内联(行间)样式,直接在标签内...

网友评论

      本文标题:前端五

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