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

前端 未结 7 503
独厮守ぢ
独厮守ぢ 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:24

    Putting display:table; inside .outer-wrapper seemed to work...

    JSFiddle Link


    EDIT: Two Wrappers Using Display Table Cell

    I would comment on your answer but i have too little rep :( anyways...

    Going off your answer, seems like all you need to do is add display:table; inside .outer-wrapper (Dejavu?), and you can get rid of table-wrapper whole-heartedly.

    JSFiddle

    But yeah, the position:absolute lets you place the div over the img, I read too quickly and thought that you couldn't use position:absolute at all, but seems like you figured it out already. Props!

    I'm not going to post the source code, after all its 99% timshutes's work, so please refer to his answer, or just use my jsfiddle link

    Update: One Wrapper Using Flexbox

    It's been a while, and all the cool kids are using flexbox:

    stuff to be centered

    Full JSFiddle Solution

    Browser Support (source): IE 11+, FireFox 42+, Chrome 46+, Safari 8+, iOS 8.4+ (-webkit- prefix), Android 4.1+ (-webkit- prefix)

    CSS Tricks: a Guide to Flexbox

    How to Center in CSS: input how you want your content to be centered, and it outputs how to do it in html and css. The future is here!

提交回复
热议问题