Is there a more effective method for placing text below an image?

I've been struggling to figure this out. Initially, when I attempted to keep the text below the image, it was constantly floated to the left. While this code seems to be effective, I suspect I made an error because when the width of .resmontage ul is changed from 70% to 60%, all the images shrink. They no longer adhere to the width or height I initially specified.

Why is it necessary to set .resmontage img to width: 100% to align it with .resmontage li? If the width is removed from resmontage li, everything falls apart! While bootstrap is an option, I prefer to handle this myself.

#bt {
  color: white;
  margin-top: 1%;
  margin-left: -8%;
}
.resmontage ul {
  float: left;
  background-color: black;
  width: 70%;
  height: 25%;
  padding-left: 7%;
  margin-top: 1%;
  border-radius: 1%;
}
.resmontage li {
  list-style-type: none;
  width: 20%;
  margin-top: 1%;
  float: left;
  padding-right: 3%;
}
.resmontage img {
  width: 100%;
  height: 65%;
}
.hello {
  text-align: center;
  color: white;
  margin-top: 2%;
}
.clearfix:after {
  content: "";
  display: both;
  clear: both;
}
<div class="resmontage clearfix">
  <ul>
    <div id="bt">Games that will be released next month.</div>
    <li>
      <img src="https://upload.wikimedia.org/wikipedia/en/a/a5/Grand_Theft_Auto_V.png" />
      <div class="hello">Gta v</div>
    </li>

    <li>
      <img src="http://media.steampowered.com/apps/valvestore/images/slider/store_image_02.png" />
      <div class="hello">CSGO</div>
    </li>

    <li>
      <img src="https://upload.wikimedia.org/wikipedia/commons/e/e0/Rocket_League_coverart.jpg" />
      <div class="hello">Rocket League</div>
    </li>

    <li>
      <img src="http://blogs-images.forbes.com/erikkain/files/2014/12/The-Witcher-3-Wild-Hunt.jpg" />
      <div class="hello">Witcher 3</div>
    </li>

  </ul>
</div>

Answer №1

You've already specified the width of the images by placing them in different li elements. By setting their width to 100%, you're essentially instructing them to occupy their container, the li, which itself has a width of 20%.

#bt {
  color: white;
  margin-top: 1%;
  margin-left: -8%;
}
.resmontage ul {
  float: left;
  background-color: black;
  width: 70%;
  height: 25%;
  padding-left: 7%;
  margin-top: 1%;
  border-radius: 1%;
}
.resmontage li {
  list-style-type: none;
  width: 20%;
  margin-top: 1%;
  float: left;
  padding-right: 3%;
}
.resmontage img {
  width: 100%;
  height: auto;
}
.hello {
  text-align: center;
  color: white;
  margin-top: 2%;
}
<div id="bt">Games launching next month.</div>
    <li>
      <img src="https://upload.wikimedia.org/wikipedia/en/a/a5/Grand_Theft_Auto_V.png" />
      <div class="hello">Gta v</div>
    </li>

    <li>
      <img src="http://media.steampowered.com/apps/valvestore/images/slider/store_image_02.png" />
      <div class="hello">CSGO</div>
    </li>

    <li>
      <img src="https://upload.wikimedia.org/wikipedia/commons/e/e0/Rocket_League_coverart.jpg" />
      <div class="hello">Rocket League</div>
    </li>

    <li>
      <img src="http://blogs-images.forbes.com/erikkain/files/2014/12/The-Witcher-3-Wild-Hunt.jpg" />
      <div class="hello">Witcher 3</div>
    </li>

  </ul>
</div>

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

"The Node.js program is unable to access the contents of the browser.js file when loaded in

After spending an unreasonable amount of time trying to debug this issue, I am still unable to resolve it. Currently, I am following a udemy tutorial where the instructor implements the same code provided below. However, despite my efforts, the code is not ...

The issue of the Dropdown Menu Not Remaining Fixed While Scrolling

There is a challenge with a Datetime Picker Dropdown Menu not staying in place when the user scrolls. Previous attempts to use .daterangepicker {position: fixed !important;} have been unsuccessful, causing the Datetime Picker to not stay fixed in its posit ...

What is the best way to pass a CSS root constant to a separate CSS file?

In my Angular test project, I'm experimenting with using the same colors repeatedly. To achieve this, I created a constants.css file where I defined all my root constants, which currently consist of colors. However, I've hit a roadblock when atte ...

What is the best way to reduce the spacing between subplots?

I am working on a subplot with multiple bar charts. Here is the code I have: fig = make_subplots(rows = 4, cols = 1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], ...

Disallow the use of punctuation marks such as dots, plus signs, minus signs, and the letter 'e' when entering

Is there a way to restrict the input of a dot, plus sign, minus sign, or letter 'e' when using semantic-ui-react library? I have searched for solutions but have not found any that work. Can someone provide assistance with this issue? ...

Packaging an Angular project without the need for compiling

In order to enhance reusability, I structured my Angular 6 Project into multiple modules. These modules have a reference to a ui module that contains all the style sheets (SASS) as values such as: $primary-text-color: #dde7ff !default; Although this app ...

The command `browser.find_elements_by_class_name('foo')` returned zero results

I'm encountering an issue with selenium while using Python 3.7. The website I'm working on has a structure similar to this: <html> <body> <div class="foo"> <div class="bar1">some ...

Strategies for eliminating all elements with a particular innerHTML content

function removeElements() { let li = document.getElementsByClassName("li"); for (var i = 0; i < li.length; i++) { if (li[i].innerHTML === "hello") { li[i].parentElement.remove(); } } } <li> <span class="li">hi</sp ...

Error: The column 'joinedactivities.searchact id = searchact.id' is not recognized in the 'on clause'

I keep encountering this particular error: Error: Unknown column 'joinedactivities.searchact id = searchact.id' in the 'on clause'. I have meticulously inspected the table names and even attempted to make modifications, but multiple err ...

Text alongside a perfectly aligned image

I'm facing a dilemma. I've been striving to replicate the layout of my training website blocks to look like this: http://prntscr.com/4cd4gm. However, aligning text and paragraphs has become an obstacle for me. Despite succeeding in aligning pictu ...

Applying Compiled CSS file in Node.js using Express and SASS not working as expected

Recently, I've delved into utilizing NodeJS with Express to serve my pug files. In addition, I decided to incorporate the "express-sass-middleware" to compile and serve the scss/css files in my project. While everything seems to be functioning as expe ...

What steps can I take to prevent the odd gaps from appearing in my horizontal flexbox gallery?

Take a look at this code: .gallery { display: flex; overflow-x: auto; resize: both; background-color: rgb(200, 200, 200); padding: 10px; height: 200px; } .item { display: flex; flex: 0 0 auto; max-width: 100%; } .item img { max-w ...

Creating a sleek full-page container with a navigation bar using TailwindCSS

I am currently utilizing Tailwind CSS and in need of creating a layout that consists of: A sticky navigation bar A full-page section with content centered Other sections with varying heights A footer Below is a simple representation: +------------------- ...

Images featuring a drop-down menu

I'm having trouble separating the two photos on this page. When I hover over one, the other also fades in. Additionally, the text box is overlapping the first photo. My goal is to have a total of 6 photos on the page, each with a dropdown list contain ...

Recreating a <select> element and verifying it once more using JS/HTML5

Before I delve into my issue, I would like to offer an apology for any errors in my English. So, the HTML code I am working with looks like this: <body> <div id="container"> <div id="taskList"> <div id="firstTask"> & ...

Why is there a thin line still visible on the other sides when a transparent background is used, but only on mobile devices, with a curved border on one side?

Recently, I've delved into the world of creating CSS art and stumbled upon a peculiar issue with CSS borders that has left me puzzled. When I apply a border to only one side of an element with a transparent background and rounded edges, I notice a fa ...

Effortlessly fill dropdown menus with data from JSON files

I've been using this jQuery code successfully, but I recently needed to add 3 more field columns to the JSON. My goal is to have the HTML select drop-downs dynamically change based on the data from the previous drop-down. Additionally, my current jQue ...

Utilize CSS and Bootstrap to ensure equal-sized responsive images in a row by scaling them down to the same dimensions

I am new to web design and struggling with resizing images using the img-fluid class in a particular portfolio view where they function as thumbnails. I will upload some images to clarify my goal. The challenge is maintaining consistency in size for each i ...

Ensuring Consistent TD Heights in Email Designs

I am currently facing a challenge in building an HTML email, specifically in ensuring that two TD elements have the same height across all email clients. Since it is a responsive email design, I have opted to separate the columns into two tables instead o ...

Retrieve the size of an element without having to wait for the browser to "recalculate style"

I am currently focused on optimizing the performance of some code that heavily relies on graphics. One of the main issues I am encountering is the delay in obtaining the dimensions of a specific div element. Most of the time, this process runs smoothly, bu ...