【问题标题】:expanding text background color to fit portion of div box扩展文本背景颜色以适应 div 框的一部分
【发布时间】:2022-11-29 11:40:36
【问题描述】:

我正在尝试获取附加的结果。 (https://i.stack.imgur.com/WjMrN.png) 整个页面采用网格布局。

每次我尝试将高度调整为 100% 以尝试填充选项卡 div 框时,它都会像这样溢出 (https://i.stack.imgur.com/9nXRN.png)。

      .tabs{
        display: inline-block;
        font-size: 20px;
      }
      
      .prints {
        display: inline-block;
        background: black;
        width: 100%;
        height: 100%;
        color: #ffffe6;
        transform: rotate(90deg);
        text-align: center;
        top: 7%;
      }

      .shop{
        display: inline-block;
        background: #e95514;
        color: black;
        transform: rotate(90deg);
        top: 85%;
        text-align: center;
      }
      <div class="tabs">
        <div class="prints">
        PRINTS
        </div>
        <div class="shop">
          SHOP
        </div>
      </div>

【问题讨论】:

    标签: html css


    【解决方案1】:

    我这里有一个解决方案,您只需旋转 div 的内容(prints 和 shop)。我在 prints 和 shop 中添加了 p 标签,这样我就可以旋转 div 的内容。

    body {
      margin: 0;
      padding: 0;
    }
    
    .tabs {
      position: fixed;
      right: 0;
      top: 0;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      font-size: 20px;
    }
    
    .prints {
      display: inline-block;
      background: black;
      color: #ffffe6;
      width: 100%;
      text-align: center
    }
    
    .shop {
      display: inline-block;
      background: #e95514;
      color: black;
      width: 100%;
      text-align: center;
    }
    
    .prints, .shop {
      padding: 1rem 0;
    }
    
    .prints > p, .shop > p {
      transform: rotate(90deg)
    }
    <body>
      <div class="tabs">
        <div class="prints">
          <p>PRINTS</p>
        </div>
        <div class="shop">
          <p>SHOP</p>
        </div>
      </div>
    </body>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多