Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display text over an image in Bootstrap 3.1

I would like to add text which displays over an image.

Essentially, this what my code looks like:

<div class="ek-background">
<div class="row">
<section id="container">
    <div class="container col-sm-4 col-sm-offset-2">
    <div class="pull-right">
        <h1>TITLE HERE</h1>
            <h2>Let us build your preview for free</h2>
    </div>  
        <img src="img/img/flow-1.png" class="align-center img-responsive">
            <div class="col">
                <div class="col-sm-4">
                    <p>this is a test</p>
    </div>
</div>
</div>

I cannot manage to get "this is a test" onto the proposed section of the image.

I would like to use the parameters of bootstrap.min.css to keep everything consistent. Also, since this will be a responsive design website, I am wanting the text to be responsive with the image so that it does not lose its position

If anyone could help, that would be great :)

like image 691
user2231397 Avatar asked Mar 02 '14 00:03

user2231397


People also ask

How do I put text over an image in bootstrap?

Add class=carousel-caption to the HTML tag which contains your text which needs to be positioned over your image !. (And then if you wish add custom css top:xyz% to your . carousel-caption class in css stylesheet to make it align vertically at middle.)

How do I display images and text side by side in bootstrap?

To create image and text side by side use the grid system property of bootstrap and create 2 columns of span 6-6. Put your image in one column and your text in another. On smaller devices, it will automatically align vertically.

How do I overlap text over an image in HTML?

CSS position property is used to set the position of text over an image. This can be done by enclosing the image and text in an HTML “div”. Then make the position of div “relative” and that of text “absolute”.


2 Answers

I can suggest a way to go around the question: you can use a carousel with a single item, because you can insert text on carousel images thanks to captions:

<div id="mycarousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner">
        <div class="item active">
        <img src="img/yourimage.png" alt="" class="img-responsive">
           <div class="carousel-caption">
           Insert your text here !
           </div>
        </div>
    </div>
</div>
like image 152
SALAMAT Med Ayman Avatar answered Sep 19 '22 19:09

SALAMAT Med Ayman


You will need to paste additional css to give us an idea of what you're dealing with exactly, but here's my 2 cents anyway:

1) Start by placing the image and the text in something that will contain them both:

<div class="imageAndText">
    <img src="img/img/flow-1.png" class="align-center img-responsive">
    <div class="col">
        <div class="col-sm-4">
            <p>this is a test</p>
        </div>
    </div>
</div>

(Careful, your original code has an extra )

2) Add absolute positioning + z-index:

.imageAndText {position: relative;} 
.imageAndText .col {position: absolute; z-index: 1; top: 0; left: 0;}

Here's a jsFiddle illustrating: http://jsfiddle.net/sX982/

like image 43
Victoria Ruiz Avatar answered Sep 18 '22 19:09

Victoria Ruiz