How to vertically center a Bootstrap carousel-caption?

前端 未结 1 510
[愿得一人]
[愿得一人] 2020-11-28 04:49

I have a bootstrap carousel and I am trying to create a caption for the carousel that is always vertically centered and positioned slightly to the left. I have the css for t

相关标签:
1条回答
  • 2020-11-28 05:22

    You can use the translateY function of the CSS property transform to vertically align elements. Browser support is quite decent, including IE9. Therefore just add the following to your .carousel-caption CSS.

    top: 50%;
    transform: translateY(-50%);
    

    Now you need to get rid of the extra bottom space, added by the default bootstrap CSS. Add the following as well to your .carousel-caption CSS.

    bottom: initial;
    

    And last but not least give the parent element, in this case .item, the following CSS to prevent blurry elements when it's placed on half a pixel.

    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    transform-style: preserve-3d;
    

    Working Example

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