zoukankan      html  css  js  c++  java
  • 边框,css盒子模型,溢出

    昨日内容回顾

    选择器

    基本选择器

     1  元素选择器 p{color:red;}
     2  id选择器 #d1{color:red;}
     3  类选择器 .c1{color:red;}
     4  5  通用选择器 *{}
     6  组合选择器 
     7      后代选择器     选择器 选择器{}
     8      儿子选择器  选择器>选择器{}
     9      毗邻选择器  选择器+选择器{}
    10      弟弟选择器  选择器~选择器{}
    11  属性选择器
    12      [属性名] --- [title]
    13      [属性名=属性值] --- [title=xxx]
    14  伪类选择器
    15      a:hover{}  鼠标悬浮
    16      a:link{}   为未问的a标签
    17      a:active{} 点击瞬间设置的效果
    18      a:visited{} 已访问连接设置效果
    19      input:focus{}   获取焦点时设置的样式
    20  伪元素选择器
    21      选择器:first-letter 首字母
    22      选择器:before  选择器对应标签内部前面插入一些内容
    23      选择器:after  选择器对应标签内部后面插入一些内容
    24  分组选择器 选择器,选择器,选择器....{}
    25          
    26  选择器优先级
    27      继承    0
    28      元素    1
    2910
    30      id      100
    31      内敛     1000
    32      最牛逼   !important  color:red!important;
    33      
    34      

     

    css属性相关

    字体属性

     1  字体  font-family:'宋体'
     2  字体大小  font-size:48px; 默认16px
     3  字体颜色  color:red;
     4           color:#ffffff
     5           color:rgb(0,0,0)
     6           color:rgba(0,0,0,0.3) 0.3透明度
     7  子重   font-weight:bold; 100-900的数字
     8  字体对齐 text-align:left;right;center
     9  文字装饰:text-decoration:none;underline;overline;line-through;
    10  首行缩进:text-indent:32px;  16px
    11

     

    背景属性

    1  背景颜色  
    2  背景图片  background-image:url('图片路径')
    3  背景平铺  background-repeat:no-repeat;
    4  图片位置  background-position:100px 50px; 距离左100px,距离上50px;
    5  图片位置  background-position:right bottom;
    6  简写:background:red url('路径') no-repeat 100px 50px;
    7  ###background-attachment:fixed;  固定在屏幕的某个位置上

     

    今日内容

    边框

     1      div{
     2              
     3               200px;
     4              height: 200px;
     5              /*border-style: solid;*/  边框样式
     6              /*border-color: red;*/    边框颜色
     7              /*border- 10px;*/   边框宽度
     8              /*border:10px solid red;*/  简写方式
     9 10              
    11              
    12              /*border-left-style: solid;*/
    13              /*border-left- 10px;*/
    14 15              /*border-right-style: dashed;*/
    16              /*border-top-style: dashed;*/
    17              /*border-bottom-style: dashed;*/
    18              /*border-right- 5px;*/
    19              border-left:10px solid red;  单独设置边框的简写方式
    20 21          }
    22 23  控制圆角
    24      border-radius: 50%;  

     

    display属性

     1          div{
     2               100px;
     3              height: 100px;
     4              border: 1px solid red;
     5              /*display: inline;  !* 将标签设置为内敛标签 *!*/
     6              /*display: inline-block;  !* 将标签设置为同时具备内敛和块级标签的一些特性,比如可以设置高度宽度,但是不独占一行 *!*/
     7              /*display: none;  !* 隐藏标签 ,并且不占用自己之前的空间*!*/
     8  9          }
    10          span{
    11              border: 2px solid blue;
    12 13          }
    14 15          .c1{
    16               200px;
    17              height: 200px;
    18              /*display: inline-block;*/  
    19              display: block; /* 将内敛标签设置为块级标签 */
    20          }
    21          
    22       值             意义
    23       display:"none" HTML文档中元素存在,但是在浏览器中不显示。一般用于配合JavaScript代码使用。
    24       display:"block"    默认占满整个页面宽度,如果设置了指定宽度,则会用margin填充剩下的部分。
    25       display:"inline"   按行内元素显示,此时再设置元素的width、height、margin-top、margin-  bottom和float属性都不会有什么影响。
    26       display:"inline-block" 使元素同时具有行内元素和块级元素的特点。   
    27      
    28      
    29  隐藏标签
    30      visibility: hidden; /* 隐藏标签,但是标签还占用原来的空间 */
    31      /*display: none;  !* 隐藏标签 ,并且不占用自己之前的空间*!*/
    32  

    css盒子模型

     1  content内容区域  
     2  padding 内边距
     3  border 边框宽度
     4      div{
     5               200px;
     6              height: 100px;
     7              border: 2px solid deeppink;
     8              /*padding-top: 10px;*/
     9              /*padding-left: 5px;*/
    10              /*padding-right: 2px;*/
    11              /*padding-bottom: 4px;*/
    12              /*padding: 10px 20px;  !* 10px上下内边距 ,20px左右内边距 *!*/
    13              /*padding: 10px 20px 5px 2px;  !* 10px上下内边距 ,20px左右内边距 *!*/
    14              padding: 10px 20px 5px 0;  /* 10px上下内边距 ,20px左右内边距 */
    15              
    16          }
    17 18  margin 外边距
    19  top距离上面标签的距离
    20  bottom距离下面标签的距离
    21  left 距离左边标签的距离
    22  rigth 距离右边标签的距离
    23 24          .d1 {
    25               200px;
    26              height: 100px;
    27              border: 2px solid deeppink;
    28              margin-bottom: 200px;  
    29          }
    30          .d2{
    31              margin-top: 100px;  
    32              border: 2px solid blue;
    33 34          }
    35 36      两个简写的方式
    37      /*margin: 10px 20px;*/
    38      margin: 10px 5px 6px 3px;
    39 40      两个情况:
    41          垂直方向如果上下两个标签都设置了margin外边距,那么取两者的最大的值
    42          水平方法,两个标签都设这外边距,取两者的边距之和
    43 44

     

    浮动float

     1      .c1{
     2              background-color: red;
     3              height: 100px;
     4               100px;
     5              float: left;
     6          }
     7          .c2{
     8              background-color: blue;
     9              height: 100px;
    10               100px;
    11              float: right;
    12          }
    13          
    14  浮动会造成父级标签塌陷问题
    15  解决方法:
    16      1 父级标签设置高度
    17      2 伪元素选择器清除浮动,给父级标签加上下面这个类值
    18          .clearfix:after{
    19              content: '';
    20              display: block;
    21              clear: both;  清除浮动clear
    22          }
    23          
    24  clear的值和描述        
    25      值   描述
    26      left    在左侧不允许浮动元素。
    27      right   在右侧不允许浮动元素。
    28      both    在左右两侧均不允许浮动元素。

    overflow溢出属性

     1      .c1{
     2               200px;
     3              height: 200px;
     4              border: 1px solid red;
     5              /*overflow: hidden;*/
     6              overflow: auto;  
     7          }
     8      <div class="c1">
     9          总结一下:为什么要有浮动啊,是想做页面布局,但是浮动有副作用,父级标签塌陷,所以要想办法去掉这个副作用,使用了clear来清除浮动带来的副作用,我们当然也可以通过设置标签为inline-block来实现这种布局效果,但是把一个块级标签变成一个类似内敛标签的感觉,不好操控,容易混乱,所以一般都用浮动来进行布局。
    10      </div>
    11 12  值   描述
    13  visible 默认值。内容不会被修剪,会呈现在元素框之外。
    14  hidden  内容会被修剪,并且其余内容是不可见的。
    15  scroll  内容会被修剪,但是浏览器会显示滚动条以便查看其余的内容。
    16  auto    如果内容被修剪,则浏览器会显示滚动条以便查看其余的内容。

     

    圆形头像示例

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="UTF-8">
     5   <meta http-equiv="x-ua-compatible" content="IE=edge">
     6   <meta name="viewport" content="width=device-width, initial-scale=1">
     7   <title>圆形的头像示例</title>
     8   <style>
     9 
    10     .header-img {
    11        150px;
    12       height: 150px;
    13       border: 3px solid white;
    14       border-radius: 50%;
    15       overflow: hidden;
    16     }
    17     
    18     .header-img>img {
    19          100%;  #让img标签按照外层div标签的宽度来显示
    20 
    21     }
    22   </style>
    23 </head>
    24 <body>
    25 
    26 <div class="header-img">
    27   <img src="meinv.png" alt="">
    28 </div>
    29 
    30 </body>
    31 </html>

    总结一点:width宽度设置的时候,直接可以写100px,30%这种百分比的写法,它的宽度按照父级标签的宽度的百分比来计算.

    定位position:相对定位和绝对定位

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Title</title>
     6     <style>
     7         .c1{
     8             background-color: red;
     9             height: 100px;
    10              100px;
    11         }
    12         .c2{
    13             background-color: blue;
    14             height: 100px;
    15              100px;
    16             /*position: relative;  !*相对定位,保留原来的空间位置,相对自己原来的位置移动,以左上角为基准*!*/
    17 
    18             /*top: 20px; 往下移20px,距离原来位置的上边框20px */
    19             /*top: -20px;*/
    20             /*left: 20px;*/
    21             /*right: ;*/
    22             /*bottom: ;*/
    23 
    24             position: absolute; /* 绝对定位,不保留自己原来的位置,按照父级标签或者祖先级标签..设置了position为 relative的标签的位置进行移动,如果一直找不到设置了设个属性的标签,那么按照body标签来移动 */
    25 
    26             top: 20px;
    27             left: 20px;
    28         }
    29         .c3{
    30             background-color: green;
    31             height: 100px;
    32              100px;
    33         }
    34         .ccc{
    35             height: 100px;
    36              200px;
    37             background-color: purple;
    38         }
    39         .cc{
    40             position: relative;
    41             left: 200px;
    42         }
    43     </style>
    44 </head>
    45 <body>
    46 <div class="ccc"></div>
    47 <div class="cc">
    48     <div class="c1"></div>
    49     <div class="c2"></div>
    50     <div class="c3"></div>
    51 </div>
    52 
    53 </body>
    54 </html>

     

    回到顶部示例:position为fixed固定定位,通过相对于浏览器窗口的距离来设置位置.

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Title</title>
     6     <style>
     7         .c1{
     8             background-color: red;
     9             height: 500px;
    10              200px;
    11         }
    12         .c2{
    13             background-color: green;
    14             height: 500px;
    15              200px;
    16         }
    17 
    18         .s1{
    19             position: fixed; /*固定定位,位置是根据浏览器窗口来的*/
    20             /*top:20px;*/
    21             left: 20px;
    22             bottom: 20px;
    23             background-color: blue;
    24             height: 40px;
    25              80px;
    26             text-align: center;
    27 
    28             line-height: 40px; /* 和标签高度一致,标签内容就垂直居中 */
    29 
    30         }
    31         .s1 a{
    32             color: white;
    33             text-decoration: none;
    34         }
    35     </style>
    36 </head>
    37 <body>
    38 
    39 <!--<a name="top">这里是顶部,亲爱的</a>-->  <!-- 锚点 -->
    40 <div id="top">这是顶部</div> <!-- 锚点 -->
    41 
    42 <div class="c1"></div>
    43 <div class="c2"></div>
    44 
    45 <span class="s1">
    46     <a href="#top">回到顶部</a> <!-- 触发锚点 -->
    47 </span>
    48 
    49 </body>
    50 </html>
    51 
    52 
    53 锚点设置的两种方式
    54     <!--<a name="top">这里是顶部,亲爱的</a>-->  <!-- 锚点 -->
    55     <div id="top">这是顶部</div> <!-- 锚点 -->
    56 触发锚点的a标签写法
    57 <a href="#top">回到顶部</a> <!-- 触发锚点 -->

     

    z-index控制层级

    模态对话框示例:

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Title</title>
     6     <style>
     7         .shadow{
     8             position: fixed;
     9             top:0;
    10             bottom: 0;
    11             left: 0;
    12             right: 0;
    13             background-color: rgba(0,0,0,0.5);
    14             z-index: 99;
    15         }
    16         .mode{
    17             position: fixed;
    18             height: 400px;
    19              300px;
    20             background-color: white;
    21             z-index: 100;  /* 数值越大越在上层显示 */
    22             left: 50%;  /* 按照窗口宽度的50%来移动 */
    23             top:50%;    /* 按照窗口高度的50%来移动 */
    24             margin-left: -150px;
    25             margin-top: -200px;
    26 
    27         }
    28 
    29     </style>
    30 </head>
    31 <body>
    32 
    33 <div>
    34     <h1>
    35         22期,吴老板唱歌
    36     </h1>
    37 </div>
    38 
    39 
    40 <div class="mode">
    41 
    42 </div>
    43 
    44 <div class="shadow">
    45 
    46 </div>
    47 
    48 
    49 </body>
    50 </html>

     

    opacity透明度

     1         .c1{
     2             background-color: rgba(255,0,0,0.3); /* 背景颜色或者字体颜色等单独的透明度 */
     3             height: 100px;
     4              100px;
     5         }
     6         .c2{
     7             background-color: rgb(255,0,0);
     8             height: 100px;
     9              100px;
    10             opacity: 0.3;  /* 整个标签透明度 */
    11         }
    12 <div class="c1">
    13     你好
    14 </div>
    15 <div class="c2">
    16     我好
    17 </div>

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    30网络通信之多线程
    U盘自动拷贝
    多态原理探究
    应用安全
    应用安全
    编码表/转义字符/进制转换
    代码审计
    文件上传
    渗透测试-Web安全-SSRF
    中间人攻击
  • 原文地址:https://www.cnblogs.com/zhangxiangning/p/11195781.html
Copyright © 2011-2022 走看看