亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

邊框九宮格

1. 前言

由于實現九宮格最方便的方式就是網格布局,所以邊框九宮格咱們來拿網格實現法舉例,邊框九宮格的關鍵點其實并不在于用哪種方式實現九宮格,所以很容易融會貫通。

2. 笨方法

相信大家都有過這樣的經歷(假裝你們有過):有一道數學題你并不會,但是你卻想到了一個耿直的辦法來解開這道數學題,答案都是正確的,只不過過程曲折了些:

比如問你6 x 9 = ? 突然你就忘記了九九乘法表,但是你知道6 x 9 = 9 + 9 + 9 + 9 + 9 + 9。
于是乎你就算唄,最后終于算出來了,頂多麻煩了點,但依然得出了正確答案不是嗎?(即使會被數學老師diss一番)

邊框九宮格也是同理,咱們不懂怎么讓兩個邊框并在一起的時候怎么變細,但是咱們可以用笨方法:
讓兩個相鄰的盒子的其中一個的相鄰邊不顯示邊框不就完了!
圖片描述
這樣的邊框合在一起就不會出現兩個邊框貼在一起啦!
思路有了,那咱們再來個動態程序看一眼:

實例演示
預覽 復制
復制成功!
<!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標簽引入中文漸變色 -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/chinese-gradient">
  <style>
    /* 清除默認樣式 */
    * { padding: 0; margin: 0; }

    /* 全屏顯示 */
    html, body, ul { height: 100% }

    /* 父元素 */
    ul {
      /* 清除默認樣式 */
      list-style: none;

      /* 顯示為網格布局 */
      display: grid;

      /* 均分成三行三列 */
      grid: repeat(3, 1fr) / repeat(3, 1fr);

      /* 給個合適的間距 */
      gap: 20px;

      /* 調用動畫 */
      animation: clear-gap 5s ease-out infinite alternate
    }

    /* 子元素 */
    li {
      /* 兩像素的邊框 */
      border: 2px solid black
    }

    /* 定義動畫 */
    @keyframes clear-gap { to { gap: 0 } }

    /* 第一個子元素 */
    li:first-child {
      border-right: none;
      border-bottom: none;
    }

    /* 第二個子元素 */
    li:nth-child(2) {
      border-bottom: none;
    }

    /* 第三個子元素 */
    li:nth-child(3) {
      border-left: none;
      border-bottom: none;
    }

    /* 第四個子元素 */
    li:nth-child(4) {
      border-right: none;
    }

    /* 第六個子元素 */
    li:nth-child(6) {
      border-left: none;
    }

    /* 第七個子元素 */
    li:nth-child(7) {
      border-top: none;
      border-right: none;
    }

    /* 第八個子元素 */
    li:nth-child(8) {
      border-top: none;
    }

    /* 第九個子元素 */
    li:last-child {
      border-top: none;
      border-left: none;
    }
  </style>
</head>
<body>
  <ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul>
</body>
</html>
運行案例 點擊 "運行案例" 可查看在線運行效果

運行結果:

3. 小結

這么做完全可以實現,絕對沒毛病,但一般來說大家用笨方法解出來的數學題,即使答案正確,老師也不會給滿分,因為 6 x 9 = ? 就是想考察你的乘法水平,但你卻用了加法,雖然答案一樣但卻饒了許多彎路。如果去參加面試的時候這么實現出來,面試官也不會給你滿分,那么下一小節我們來看看有沒有不那么麻煩的方法。