CSS3 border-radius

154 阅读1分钟
  • border-radius 介绍
<!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: 300px;
      height: 300px;
      border: 1px solid #000;
      background-color: pink;
      margin: 100px auto;

      /* 圆角 */
      /* 写法 border-radius: 60px; === border-radius: 60px/60px; */
      /* border-radius: 60px; */

      /* 顺序赋值 从左上角开始,顺时针赋值 */
      /* border-radius: 20px 60px 100px 140px; */
      /* 左上角 右下角: 20px 右上角 左下角: 60px, 如果只有两个值,则会取斜对角的值使用 */
      /* border-radius: 20px 60px; */

      /* 单个属性: 水平半径 垂直半径 */
      /* border-top-left-radius: 60px 120px;
      border-top-right-radius: 60px 120px;
      border-bottom-left-radius: 60px 120px;
      border-bottom-right-radius: 60px 120px; */

      /* 符合写法 */
      /* border-radius: 水平半径/垂直半径 */
      /* border-radius: 60px 60px 60px 60px/ 120px 120px 120px 120px; */

      /* 简写 */
      border-radius: 60px/120px;
    }
  </style>
</head>
<body>
  <div class="box">

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

  • border-radius 练习
<!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: 200px;
      height: 200px;
      border: 1px solid red;
      margin: 20px auto;
      text-align: center;
      line-height: 200px;
      color: #ccc;
      font-size: 50px;
    }
    .box:nth-child(1) {
      border-radius: 100px;
    }
    /* 如果是动态高度的话用百分比适配会更合适 */
    .box:nth-child(2) {
      border-radius: 50%;
    }
    .box:nth-child(3) {
      border-radius: 200px 0 0 0;
    }
    .box:nth-child(4) {
      height: 100px;
      line-height: 100px;
      border-radius: 100px/50px;
    }
    .box:nth-child(5) {
      width: 100px;
      border-radius: 50%;
    }
  </style>
</head>
<body>
  <div class="box">1</div>
  <div class="box">2</div>
  <div class="box">3</div>
  <div class="box">4</div>
  <div class="box">5</div>
</body>
</html>

练习效果