简体   繁体   English

将文字放在图片上以适合响应页面

[英]Put text over picture to fit responsive page

I was trying to put some text over a picture, but I don't want to set background-image . 我试图在图片上放一些文字,但是我不想设置background-image

I've created a jsfiddle to illustrate what I did, and I use bootstrap3. 我创建了一个jsfiddle来说明我的工作,并使用bootstrap3。

In the mobile size, it can display fine like 在手机尺寸上,它可以像

在此处输入图片说明

But if I resize the browser width, it will be broken. 但是,如果我调整浏览器宽度的大小,它将被破坏。

html html

<div class="col-xs-12 visible-sm-block visible-xs-block" style="text-align: center;">
    <p class="competion_text">
        This is inside the competiontion Box!
        <br> Second line
        <br> Third line
    </p>
    <img src="http://i.imgur.com/NajXOdH.png">
</div>

CSS CSS

.competion_text {
        text-align: center;
        position: relative;
        top: 252px;
        left: 7px;
        max-width: 225px;
        color: #FFCF83;
        font-size: 10pt;
    }

Try something like this. 尝试这样的事情。

.competion_text {
    text-align: center;
    position: relative;
    top: 252px;
    margin: 0 auto;
    max-width: 225px;
    color: #FFCF83;
    font-size: 10pt;
}

Here is workin jsfiddle 这是jsfiddle中的工作

 /* Latest compiled and minified CSS included as External Resource*/ /* Optional theme */ @import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css'); .holder { position: relative; width: 230px; margin: 0 auto; } .competion_text { position: absolute; top: 180px; left: 0; width: 100%; text-align: center; color: #FFCF83; font-size: 10pt; z-index: 2; } 
 <div class="col-xs-12 visible-sm-block visible-xs-block holder" style="text-align: center;"> <p class="competion_text"> This is inside the competiontion Box! <br> Second line <br> Third line </p> <img src="http://i.imgur.com/NajXOdH.png"> </div> 

I put another class on the parent. 我给父母上了另一堂课。 (.holder) (.holder)

Try this. 尝试这个。 Hope it helps! 希望能帮助到你!

Try as below, Set your parent element ie .col-xs-12 position as position:relative and child ie .competion_text position as position:absolute thus this aligns your text in the center of image, Now I have used CSS calc() function in top positing to align it vertically in center and that always stays there. 尝试如下操作,将您的父元素(即.col-xs-12位置设置为position:relative和子.competion_text.competion_text位置)设置为position:absolute从而使文本在图像的中心对齐,现在我使用CSS calc() function在顶部位置以使其垂直居中对齐,并且始终保持在该位置。

 /* Latest compiled and minified CSS included as External Resource*/ /* Optional theme */ @import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css'); .col-xs-12{ width:auto; height:auto; margin:auto; text-align:center; position:relative; } .col-xs-12 > .competion_text { position: absolute; top: calc(100% - 30%); left: 0; width: 100%; height:auto; color: #FFCF83; font-size: 10pt; text-align:center; } 
 <div class="col-xs-12 visible-sm-block visible-xs-block"> <p class="competion_text"> This is inside the competiontion Box! <br> Second line <br> Third line </p> <img src="http://i.imgur.com/NajXOdH.png"> </div> 

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

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