how to display text over an image in Bootstrap 3.1

前端 未结 3 1663
无人及你
无人及你 2020-12-30 02:22

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

Essentially, this what my code looks like:

相关标签:
3条回答
  • 2020-12-30 02:59

    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>
    
    0 讨论(0)
  • 2020-12-30 03:12

    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/

    0 讨论(0)
  • 2020-12-30 03:18

    I don't think this is possible using bootstrap classes. You can just do something like this by adding thumbnail to the image and thumbnail_legend to the next div.

    .thumbnail_legend {
        background: none repeat scroll 0 0 #FFFFFF;
        opacity: 0.5;
        top:0;
        left:0;
        position: absolute;
    }
    
    .thumbnail {
        position:relative;
    }
    

    from: Bootstrap 3: Text overlay on image

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