Why is width: 100% not working on div {display: table-cell}?

前端 未结 7 500
独厮守ぢ
独厮守ぢ 2020-12-25 10:46

I\'m trying to vertically and horizontally center some content overlaying an image slide (flexslider). There were some similar questions to this one, but I couldn\'t find a

7条回答
  •  佛祖请我去吃肉
    2020-12-25 11:07

    I figured this one out. I know this will help someone someday.

    How to Vertically & Horizontally Center a Div Over a Relatively Positioned Image

    The key was a 3rd wrapper. I would vote up any answer that uses less wrappers.

    HTML

    My Title

    Subtitle

    CSS

    html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    }
    
    ul {
        width: 100%;
        height: 100%;
        list-style-position: outside;
        margin: 0; padding: 0;
    }
    
    li {
        width: 100%;
        display: table;
    }
    
    img {
        width: 100%;
        height: 100%;
    }
    
    .outer-wrapper {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      margin: 0; padding: 0;
    }
    
    .table-wrapper {
      width: 100%;
      height: 100%;
      display: table;
      vertical-align: middle;
      text-align: center;
    }
    
    .table-cell-wrapper {
      width: 100%;
      height: 100%;  
      display: table-cell;
      vertical-align: middle;
      text-align: center;
    }
    

    You can see the working jsFiddle here.

提交回复
热议问题