How to place text on top of a thumbnail in Bootstrap using HTML

I've come across similar questions here, but none of the suggested solutions have worked for me. (I attempted making the image a background as recommended on how to display text over an image in Bootstrap 3.1, but it didn't seem to be effective)

My goal is to overlay text on top of an image using Twitter's Bootstrap.

I'm currently using the thumbnail class because it automatically resizes the image to fit a column. However, I haven't found a satisfactory way to center the text on the image.

Here's a screenshot of the current page layout: https://i.stack.imgur.com/GR9uQ.jpg

Below is the code snippet in question:

<div class="menuphotos">
<div class="container">
    <h2> Lorem Ipsum</h2>
        <p>Bal Bla Bla Bla </p>
        <div class="row">
            <div class="col-md-4">
                  <div class="thumbnail">
                    <a href="#"><img src="http://imgur.com/4uEiK33.jpg"></a>
                     <div class="h2 strong">Geology and Geophysics</div>
                     <p> Bla Bla Bla</p>
                </div>
            </div>

            <div class="col-md-4">
                 <div class="thumbnail">
                    <a href="#"><img src="http://imgur.com/U5IO8eV.jpg"></a>
                    <div class="h2 strong">Astronomy</div>
                <p> Bla Bla Bla</p>
                </div>
            </div>

            <div class="col-md-4">
                 <div class="thumbnail">
                    <a href="#"><img src="http://imgur.com/OZ5C3Wy.jpg"></a>
                   <div class="h2 strong">Etc</div>
                   <p> Bla Bla Bla</p>
                </div>                
            </div>
        </div>
    </h2>
</div>

and

.menuphotos{
background-color: #efefef;
border-bottom: 1px solid #dbdbdb
}

.menuphotos h2 {
    color: #393c3d;
    font-size: 24px;
}

.menuphotos p {
    font-size: 15px;
    margin-bottom: 13px;
}

You can view the full code here: http://pastebin.com/ghYwGPg1 (HTML) and here: http://pastebin.com/EgjywRr9 (CSS)

If it's not feasible to centrally position text on top of the image with the thumbnail class, what alternative approach can I take to ensure the image auto-resizes to fit the column? The images I'm using are all different sizes but share the same aspect ratio (2:3).

Answer №1

To create a layered effect with an image and text, you can apply a class to the thumbnail to make its position relative. Then, using absolute positioning, you can layer a div containing the text on top of the image.

Here's an example:

<div class="thumbnail rel-pos">
  <a href="#"><img src="http://imgur.com/U5IO8eV.jpg"></a>
  <div class="over-text">
   <h2>Astronomy</h2>
   <p> Bla Bla Bla</p>
  </div>
</div>

.rel-pos {
  position: relative;
}

.over-text {
  width: 100%;
  position: absolute;
  top: 300px;
  text-align: center;
  z-index: 10;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Achieving Dynamic Center Alignment for One or Two DIVs

My goal is to create a page layout with three DIVS arranged as Left|Center|Right, while still being able to display different combinations such as Center, Left|Center, or Center|Right in the center of a wrapper div. I have been using jQuery toggle to swit ...

Creating a customized design for a React application with the use of Scss and JavaScript variables

Is there a method to incorporate JavaScript variables into an SCSS file? For instance, I have a JavaScript file containing the following code: // sky blue const PRIMARY_COLOR = '#489FEF' export { PRIMARY_COLOR} and I would like to utilize it ...

How to make divs occupy the entire space of a parent div?

I've been scouring the website for a solution, but nothing I've found has been helpful. I'm attempting to create a grid within a containing div where a default (and eventually user-specified) number of divs will fill up the space. I'm t ...

Tips for adding an image into a PDF document using the jsPDF library in HTML

Due to the lack of support for utf8 characters in jspdf, I'm experimenting with replacing some characters with images before exporting to pdf. To illustrate, I've created a code sample where I insert an image into an html div and then attempt to ...

"Utilizing Bootstrap CSS along with a variety of other CSS/HTML component bundles

Recently diving into the world of Bootstrap for my ASP.NET MVC project has been a game-changer! I'm in awe of its capabilities and functionality. However, I can't help but wish there were more ready-to-use components available to streamline the d ...

Ensure the clarity tabs labels have the padding-left CSS property added

In my project, there are 2 clarity tabs (you can view the StackBlitz reference here). I want to apply the padding-left property specifically to Tab1 (the tab label itself, not the content) in order to create some space around it. Through Chrome Dev Tools, ...

How can you refresh the .replaceWith method in jQuery?

Is there a way to reset the .replaceWith function so that the html, css and javascript elements are restored to their original state? I am looking to have an icon replace the text when the user clicks on "contact", and then have the text return when the u ...

Is it possible to create an HTML textarea that supports HTML formatting?

Is it possible to have HTML tag support in an HTML textarea within a form, similar to what is seen on Stack Overflow when asking a question? I would like to be able to capture the user's input in a textarea using PHP and print exactly what the user ty ...

Tips on how to achieve a 50% width within a bootstrap input group

Need help setting the width of a select tag <div class="input-group"> <select class="form-select" style="width: 50%;"> <option selected value="dummy">Dummy</option> <opt ...

Glitch with menu presentation in Safari browser

I'm currently working on a website for a client who specifically wants a traditional, non-responsive design. The site has been successful over time, but I've encountered an issue with the menu display in Safari. While it looks fine on other brows ...

Sturdy and adaptable in a container designed with a responsive width

Currently, I am developing a responsive app and I am facing the challenge of making some parts of the search bar responsive while keeping others fixed in width (like the search icon). I attempted to achieve this using the following code: .wrapper{ ...

HTML and Python synchronize perfectly when handling date formatting

Here is a code snippet I am working with: {% for x in fixtures %} <TR style="display:block" onclick="team_visibility('match{{ forloop.counter }}');"> <TD> {{ x.fixturedate }}</TD> ...

Crafting a template for mixing up images and quotes without any specific connection - here's how!

I came across some interesting templates that can generate random quotes and others that create random pictures. My goal is to develop a template that generates both a random quote and a random picture, similar to this example, without any relation betwee ...

What is the best way to transform height in pixels to percentage in order to create a responsive design that adjusts smoothly on

Currently, I am in the process of developing a responsive grid system by using a max-width of 980px to convert my fixed PX widths to percentages. However, I am facing some challenges in updating the heights that are also set in PX to %. Could anyone provid ...

Is there a way to have a fixed width div positioned in the center of the screen, with two additional divs on either side

I have come across this stunning image: https://i.stack.imgur.com/tUYMc.png It serves as a header for a website - click on it to see the full size. I am trying to replicate this using HTML, CSS, and images, but I'm struggling. It needs to be 100% w ...

Incorporate a new JavaScript animation as the background for an established website, replacing the static background image

Seeking assistance with my portfolio as I delve into the world of Webdesign and learn the basics from templates. How can I integrate this javascript code into the background of my site, replacing the current minecraft image? Every attempt to implement it ...

I'm looking for guidance on how to merge my JavaScript and CSS files together. Can anyone provide me

As a beginner in web development, I have been looking into combining JS and CSS files. However, explanations using terms like minifies and compilers on platforms like Github and Google are still confusing to me. Here are the CSS files I have: bootstrap ...

Using jQuery to locate text and apply a specific class

Explaining My HTML Structure: <div id="test-listing"> <article> <a>Some URL</a><h3>Some Text</h3> <p>Drink this coffee</p> </article> <article><a>Some URL</a><h3>Some Text</h ...

Creating a Chrome extension that opens multiple tabs using JavaScript

Currently, I am working on a chrome extension that includes several buttons to open different tabs. However, there seems to be an issue where clicking the Seqta button opens the tab three times and clicking the maths book button opens the tab twice. Below, ...

Cut out a passage by using a polyline shape

I am looking to create a unique effect by clipping a text like a heading1 using an svg polyline. The concept is to place the H1 text behind the polyline background and make it appear frosted or blurred. I have successfully achieved this in the past but see ...