CSS綜合

1.說一說你平時寫代碼遵守的編碼規范

  • 命名技巧

    1. 語義化標簽優先
    2. 基于功能命名、基于內容命名、基于表現命名
    3. 簡略、明了、無后患
  • 書寫規范

    1. tab 用兩個空格表示
    2. css的 :后加個空格, {前加個空格
    3. 每條聲明后都加上分號
    4. 換行,而不是放到一行
    5. 顏色用小寫,用縮寫, #fff
    6. 小數不用寫前綴, 0.5s -> .5s;0不用加單位
    7. 盡量縮寫, margin: 5px 10px 5px 10px -> margin: 5px 10px
  • 編碼規范

2.垂直居中有幾種實現方式,給出代碼范例

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    .box{
      width: 700px;
      border: 1px solid;
      background-color: white;
      padding-top: 20px;
      padding-bottom: 20px;
    }
   .box1 {
     width: 300px;
     height: 300px;
     border: 1px solid;
     background-color: red;
    }
  </style>
</head>
<body>
<div class="box">
  <div class="box1">
    
  </div>
</div>
</body>
</html>

效果圖


image.png
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    .box {
  width: 600px;
  height: 800px;
  border: 1px solid;
  position: absolute;
}
.box1{
  width: 200px;
  height: 200px;
  border: 1px solid;
  background-color: red;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -100px;
  margin-left: -100px;
}
  </style>
</head>
<body>
<div class="box">
<div class="box1">

</div>
</div>
</body>
</html>

效果圖

image.png
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
  .box {
  border: 1px solid;
}
.box1 {
  width: 100px;
  height: 300px;
  border: 1px solid;
  background-color: red;
  display: inline-block;
   vertical-align: middle;
}
.box2 {
  width: 10px;
  height: 30px;
  border: 1px solid;
  background-color: green;
  display: inline-block;
  vertical-align: middle;
}</style>
</head>
<body>
  <div class="box">
    <div class="box1"></div>
    <div class="box2"></div>
  </div>
</body>
</html>

效果圖

image.png
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    .box {
      border: 1px solid;
      width: 200px;
      height: 300px;
      display: table-cell;
      vertical-align: middle;
      text-align: center;
    }
    .box1 {
      width: 100px;
      height: 200px;
      border: 1px solid;
      background-color: red;
      vertical-align: middle;
      display: inline-block;
    }
  </style>
</head>
<body>
<div class="box">
  <div class="box1"></div>
  <div class="box2"></div>
</div>
</body>
</html>

效果圖

image.png

3.實現如下效果,每種效果都只使用一個html 標簽來實現 效果范果

代碼1

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
  .box {
  width: 200px;
  height: 100px;
  border: 1px solid;
  
}
.box:before {
  content: "";
  display: inline-block;
  width: 0px;
  height:0px;
  border: 10px solid transparent;
  border-bottom: 10px solid  gray;
  position: relative;
  left: 10px;
  top: -20px;
}
  </style>
</head>
<body>
<div class="box"></div>
</body>
</html>

代碼2

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    .box {
  width: 200px;
  height: 100px;
  border: 1px solid; 
}
.box:before {
  content: "";
  display: inline-block;
  width: 0px;
  height:0px;
  border: 10px solid transparent;
  border-top: 10px solid  red;
  border-right: 10px solid  red;
  float: right;
}
  </style>
</head>
<body>
<div class="box"></div>
</body>
</html>

代碼3

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
      .box {
        width: 200px;
        height: 100px;
        border: 1px solid;
  
      }
      .box:before {
        content: "";
        display: inline-block;
        width: 10px;
        height: 10px;
        border-top: 1px solid;
        border-left: 1px solid;
        transform: rotateZ(45deg);
        position: relative;
        top: -12px;
        left: 10px;
        background-color: white;
      }
  </style>
</head>
<body>
<div class="box">
  
</div>
</body>
</html>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容