【问题标题】:blocks in a raw in html page with different width不同宽度的原始html页面中的块
【发布时间】:2017-01-31 16:25:23
【问题描述】:

我有this fiddle,它有三个等宽的块。我们如何制作不同的大小,比如给定 100%、第一个块 20%、第二个块 50% 和第三个 30%。

<div class="Row">
    <div class="Column">C1</div>
    <div class="Column">C2</div>
    <div class="Column">C3</div>
</div><div class="Row">
    <div class="Column">C1</div>
    <div class="Column">C2</div>
    <div class="Column">C3</div>
</div>


.Row
{
    display: table;
    width: 100%;
    table-layout: fixed;
    border-spacing: 10px;
}
.Column
{
    display: table-cell;
    background-color: red;
}

【问题讨论】:

    标签: html css


    【解决方案1】:

    你可以使用nth-child:

    .Row {
      display: table;
      width: 100%;
      table-layout: fixed;
      border-spacing: 10px;
    }
    
    .Column {
      display: table-cell;
      background-color: red;
    }
    
    .Column:nth-child(1) {
      width:20%;
    }
    .Column:nth-child(2) {
      width:50%;
    }
    .Column:nth-child(3) {
      width:30%;
    }
    <div class="Row">
      <div class="Column">C1</div>
      <div class="Column">C2</div>
      <div class="Column">C3</div>
    </div>

    【讨论】:

    • 我需要将每个单元格的红色背景颜色部分更改为第一个单元格 100% 第二个单元格 100% 和第三个单元格 50%,如何实现?
    • 我不明白你的意思。您是说第三个单元格应该是红色且不透明度为 50%?
    • 我的意思是第三个单元格在参考第三个单元格的总宽度时应该用红色和半白色填充一半。
    • 为此,您可能需要在该单元格上创建渐变背景。
    • 谢谢,它有效!但是有一个小问题,颜色边缘不清晰,它与右侧的其他颜色轻轻融合,不知道如何避免这种外观。
    猜你喜欢
    • 2023-03-16
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多