visiblity:hidden of table-cell hides background-color of parent table-row

前端 未结 5 1251
南笙
南笙 2021-01-18 10:13

I have some forms that are structured using display:table-row and display: table-cell. On Firefox 52, I could hide a cell element using visib

相关标签:
5条回答
  • 2021-01-18 10:40

    Add font-size: 0 option for hidden div.

    #tableRow{
      display: table-row;
      background-color: #e5e8ec;
    }
    .cell{
      display:table-cell;
    }
    #hide,
    #hide>* {
      font-size: 0;
      border: 0;
      outline: 0;
      margin: 0;
      padding: 0;
      height: 0;
      background: transparent;
      width: 75px
    }
    <div id="tableRow">
      <a href="#" class="cell">Visible</a>
      <a href"#" class="cell"id="hide">
        <input type="text"/>
        <button type="button">Click Me!</button>
        Not Visible</a>
      <a href="#" class="cell">Visible</a>
    </div>

    0 讨论(0)
  • 2021-01-18 10:45

    You can use trick with color:transparent and to prevent events(of a) use pointer-events: none;

    #tableRow{
      display: table-row;
      background-color: red;
    }
    .cell{
      display:table-cell;
    }
    #hide{
      color:transparent;
      pointer-events: none;
    }
    <div id="tableRow">
      <a href="#" class="cell">Visible</a>
      <a href"#" class="cell"id="hide">Not visible</a>
      <a href="#" class="cell">Visible</a>
    </div>

    With inputs:

        #tableRow{
          display: table-row;
          background-color: red;
        }
        .cell{
          display:table-cell;
        }
        #hide{
          color:transparent;
          pointer-events: none;
          border:none;
          outline:0;
          padding: 2px;
        }
    <div id="tableRow">
          <a href="#" class="cell">Visible</a>
          <input href"#" class="cell" id="hide"/>
          <a href="#" class="cell">Visible</a>
    </div>

    0 讨论(0)
  • 2021-01-18 10:50

    #tableRow{
      display: table;
      background-color: #f5f5f5;
    }
    .cell{
      display:table-cell;
    }
    #hide{
      visibility:hidden;
    }
    <div id="tableRow">
      <a href="#" class="cell">Visible</a>
      <a href"#" class="cell"id="hide">Not visible</a>
      <a href="#" class="cell">Visible</a>
    </div>

    0 讨论(0)
  • 2021-01-18 10:54

    Follow the structure

    #tableRow ul {
        display: table-row;
        background-color: #f5f5f5;
    }
    #tableRow ul li {
        display: table-cell;
    }
    
    #hide {
        visibility: hidden;
    }
    <div id="tableRow">
        <ul>
      <li>
    <a href="#" class="cell">Visible</a>
    </li>
        
        <li>
    <a href"#"="" class="cell" id="hide">Not visible</a>
    </li>
        
        <li>
    <a href="#" class="cell">Visible</a>
    </li>
      
      </ul>
    </div>

    0 讨论(0)
  • 2021-01-18 10:58

    I would consider box-shadow to simulate a background coloration and avoid this bug *

    .container {
      display: table;
    }
    
    #tableRow {
      display: table-row;
      box-shadow: -100vw 0 0 red inset;
    }
    
    .cell {
      display: table-cell;
      padding: 10px;
    }
    
    #hide {
      visibility: hidden;
    }
    <div class="container">
      <div id="tableRow">
        <a href="#" class="cell">Visible</a>
        <a href="#" class="cell" id="hide">Not visible</a>
        <a href="#" class="cell">Visible</a>
      </div>
    </div>

    *it's probably not a bug but I am not able to find any specification describing this behavior

    0 讨论(0)
提交回复
热议问题