html - CSS改变网格框的可变范围

标签 html css

我想根据下拉菜单中的选择更改网格框的背景颜色,但我不知所措。如果选择 A/3,框 1-3 将发生变化。如果选择 C/10,框 1-10 将发生变化。这是我的第一个 web 开发元素,所以我可能会处理这个错误。如果是这样,请告诉我。感谢您的帮助!

.menu
            {
             overflow: hidden;
             background-color: #29648A;
             margin:0 auto;
             }
          .dropdown
            {
             float: left;
             overflow: hidden;
             width: 25%;
             }
          .button
            {
             font-size: 16px;
             border: none;
             outline: none;
             color: white;
             padding: 10px 10px;
             background-color: inherit;
             width: 100%;
             text-align: center;
             }
          .dropdown:hover
            {
             background-color: #2E9CCA;
             }
          .list
            {
             display: none;
             position: absolute;
             background-color: #F9F9F9;
             box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
             width: 24.65%;
             }
          .list a
            {
             float: none;
             color: black;
             padding: 12px 16px;
             text-decoration: none;
             display: block;
             text-align: center;
             }
          .list a:hover
            {
             background-color: #ddd;
             }
          .dropdown:hover .list
            {
             display: block;
             }
          .wrapper
            {
             display: grid;
             grid-template-columns: repeat(4, 1fr);
             grid-template-rows: repeat(4, 100px);
             grid-gap: 10px;
             max-width: 400px;
             margin: 50px auto;
             }
          .box
            {
             background-color: #AAABB8;
             color: white;
             text-align: left;
             font-size: 20px;
             padding: 10px 10px;
             border-radius: 5px;
             max-width: 100px;
             }
<!DOCTYPE html>
    <html>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
    
      <head>
      </head>
    
      <body>
        <div class="menu">
          <div class="dropdown">
            <button class="button">A</button>
            <div class="list">
              <a href="#">1</a>
              <a href="#">2</a>
              <a href="#">3</a>
              <a href="#">4</a>
            </div>
          </div>
          <div class="dropdown">
            <button class="button">B</button>
            <div class="list">
              <a href="#">5</a>
              <a href="#">6</a>
              <a href="#">7</a>
              <a href="#">8</a>
            </div>
          </div>
          <div class="dropdown">
            <button class="button">C</button>
            <div class="list">
              <a href="#">9</a>
              <a href="#">10</a>
              <a href="#">11</a>
              <a href="#">12</a>
            </div>
          </div>
          <div class="dropdown">
            <button class="button">D</button>
            <div class="list">
              <a href="#">13</a>
              <a href="#">14</a>
              <a href="#">15</a>
              <a href="#">16</a>
            </div>
          </div>
        </div>
        <section>
          <div class="wrapper">
            <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>
            <div class="box">6</div>
            <div class="box">7</div>
            <div class="box">8</div>
            <div class="box">9</div>
            <div class="box">10</div>
            <div class="box">11</div>
            <div class="box">12</div>
            <div class="box">13</div>
            <div class="box">14</div>
            <div class="box">15</div>
            <div class="box">16</div>
          </div>
        </section>
      </body>
    </html>

最佳答案

您可以使用 addClass() & removeClass()使用 jquery 向每个框添加一些具有不同 id 的 if 语句,并将其用作选择器以将每一列连接到它自己的框! 试试看,如果需要我可以提供帮助。

关于html - CSS改变网格框的可变范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47973448/

相关文章:

javascript - 插入 4 个空格而不是制表符

javascript - 为什么 outerWidth 不适用于 jqgrid 行和列?

html - 包裹在 div 中的 vss 垂直图未在其父 div 中垂直居中

html - 带有页脚和中间面板的 CSS 布局

javascript - 检查浏览器宽度并执行一个 Javascript 文件并覆盖另一个 Javascript

css - Onfocus 阴影在 IE 中不起作用

html - 如何更改 &lt;input type = "submit"> 的高度

html - chrome什么时候支持显示: grid; layouts?

html - 如何使导航栏中的 Logo 居中

css - 为也在两个单独的样式表中定义的元素定义样式