简体   繁体   English

Bootstrap响应式多行文字叠加

[英]Bootstrap Responsive Multiline text overlay

I am trying to add a text overlay to my images, but I am struggling making it responsive, and vertically centered. 我正在尝试在图像上添加文字叠加层,但是我正在努力使其具有响应性并垂直居中。

Here is where I got : http://jsfiddle.net/r8rFc/910/ 这是我得到的地方: http : //jsfiddle.net/r8rFc/910/

.img-overlay {
    position: relative;
}

.project-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(41,128,185,0.9);
    color: #fff;

}

.centered-text
{
  display:table;
  height:100%;
  width:100%;
  text-align:center;
  vertical-align:center;
}

I am able to center the text horizontally, but I cannot make it vertically... I really have no clue how to do that. 我可以将文本水平居中,但不能垂直放置...我真的不知道如何做到这一点。 All I checked was either non responsive, or it was just a logo at the center of the overlay... 我检查的所有内容要么都不响应,要么只是覆盖层中心的徽标...

Thanks ! 谢谢 !

Thanks to Henrique Barcelos, I have been able to solve the issue. 感谢Henrique Barcelos,我得以解决此问题。 Here is the fiddle giving the solution : http://jsfiddle.net/r8rFc/912/ 这是提供解决方案的小提琴: http : //jsfiddle.net/r8rFc/912/

.project-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(41,128,185,0.9);
    color: #fff;
    display:flex;
  justify-content: center;
  flex-direction: column;
  text-align: center;

}

How about setting .project-overlay as such 这样设置.project-overlay怎么样

.project-overlay {
    position: absolute; 
   top: 45%; 
   left: 0;
   text-align: center; 
   width: 100%; 
    background-color: rgba(41,128,185,0.9);
    color: #fff; 
}

With this you can try setting a wrapper div to set the background color to whatever color it is that you want 这样,您可以尝试设置包装器div来将背景色设置为所需的任何颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM