Pictures arranged neatly within a grid, with detailed descriptions placed prominently at the center

I've been exploring this area and came across some helpful answers, but I'm still having trouble figuring it out. My goal is to create something similar to what's shown in this image.

I want to have 5 small images, each with a number above them. I attempted it, but as you can see, the numbers were not centered (only testing the first row).

.grid-img {
display: inline-block;
}
<div class="grid-img">
<p>1</p>
    <img src="img1" alt="image1">
</div>
<div class="grid-img">
<p>2</p>
    <img src="img2" alt="image2">
</div>
<div class="grid-img">
<p>3</p>
    <img src="img3" alt="image3">
</div

Answer №1

Take a look at this: by using text-align: center;, you can position the number in the center. Remember to add <br/> after the 3rd div element. Here is the modified code snippet below.

.grid-img {
  display: inline-block;
  text-align: center;
}
<div class="grid-img">
  <p>1</p>
  <img src="img1" alt="image1">
</div>
<div class="grid-img">
  <p>2</p>
  <img src="img2" alt="image2">
</div>
<div class="grid-img">
  <p>3</p>
  <img src="img3" alt="image3">
</div>
<br/>
<div class="grid-img">
  <p>4</p>
  <img src="img1" alt="image1">
</div>
<div class="grid-img">
  <p>5</p>
  <img src="img2" alt="image2">
</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

Troubleshooting issues with dropdown functionality in HTML when using Bootstrap

I'm encountering an issue with my dropdown menu not functioning properly when using bootstrap. The dropdown only appears on screens smaller than the $md variable. The problem arises when I try to click on the dropdown icon and it does not respond as ...

Is there a way to have a border specifically on the top side?

Is there a way to have the border show up only on the top when hovering over it? Here's the current code I'm using: a:hover { border-top: 3px white; border-style: solid; } Even though this code is in place, the border still appears on ...

configuring radio buttons with a default value using PHP

I am facing an issue in setting a default value for radio buttons in my form. The default value needs to be fetched from the database. I am aware of how to set a default value using checked="checked", however, in my specific case, I am struggling with in ...

What is the method for connecting to a JavaScript function?

Is there a way to have JavaScript code that creates a sliding div with expanded information when clicking on a text string, and then navigate to that specific page with the text already clicked on and expanded? If so, how could this be achieved? JSFidldle ...

Is there a concept of negative margin "wrapping"?

I am currently working on the website . I am facing an issue where the left arrow is not appearing in the same position as the right arrow. When I try to mirror the same adjustment I made for the left arrow by using margin-left: -75px, it seems to 'wr ...

Having trouble aligning the md-button to the left side

When working with material design, I have encountered an issue where I want a button to align left. To achieve this, I added the layout-align attribute as follows: <button md-button (click)="someFunc()" class="md-primary" layout-align="end center"> ...

Utilizing Bootstrap 4 to seamlessly transition the navbar-brand image to overlap on larger screens, and shrink-to-fit on smaller screens

I have a challenge that I'm working on. My goal is to make the navbar-brand image overlap with the navbar without changing its height, as the navbar itself has a fixed height of 80px. The current solution kinda works, but I am facing an issue ...

Zoom in to see the header spanning the entire width of the page

http://jsfiddle.net/CPSKa/ Whenever I zoom in on the header of my website, the line underneath it starts to shrink. Is there a way to prevent this from happening? Here is the HTML Code: <div id="main_header"> <div id="main_header_wrapper"&g ...

jQuery toggle causing page layout glitches

I am working with a movie title table where each cell contains a hidden div with a summary of the movie. I have successfully implemented a toggle button to show and hide the summaries, but there is an issue with the page position jumping whenever the butto ...

An issue with the animation script in Ionic

I'm having trouble converting this to an Ionic application. Here's my code sample. Can anyone help me with putting this code correctly in Ionic? I'm trying to achieve something like this example <script src="https://cdnjs.cloudflare.com ...

Displaying error or success messages within the same webpage

This is my first time reaching out here because I couldn't resolve the issue on my own. Please keep in mind that I am relatively new to Spring and not very experienced in Java and coding in general. I am working on creating a Server application using ...

Tips for selecting itemid="" with CSS

Below is an example of HTML: <div itemid="MenuContainer" id="MenuContainer" class="MenuContainer"> Here is an example of CSS: #MenuContainer { /* Styles */ } Is there a way to target ItemID with CSS instead of the usual ID? ...

Establish restrictions for the minimum and maximum values for each year in the Date Range Picker

After searching for answers to my question, I have found some general solutions but none that fit my specific problem. I created a backend system for users to manage the availability of hotel rooms throughout the selected year. Using HTML/PHP/MySQL, I dis ...

Unable to scroll within ion-view component

I recently started working with the ionic framework and I am currently struggling with a scrolling issue in my page design. Below is the code from my index.html file: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> & ...

Having difficulty with CSS animation and background issues

I can't seem to get my rotating background to work using CSS keyframe animation. I've tried different things but can't figure out what's going wrong. Below is my code: .main-header { width: 100%; Height: 128px; } .main-header, ...

List that scrolls with a stationary button

I am working on an interface that includes a button with a dropdown list. Here is an example: <a href="https://jsfiddle.net/DTcHh/16589/" rel="nofollow">jsfiddle</a> While the list is scrollable, I am looking to add a fixed button at the botto ...

Version 4.1 of Bootstrap offers a versatile multirow card layout with two columns

How can I make a two-column, multi-row card display using Bootstrap v4.1? I need this setup three times, with each pair of cards grouped for different tasks. Please see the code below and provide assistance. body { backgroun ...

The appearance of the logout button may differ depending on the web browser being used

I have implemented a straightforward logout button using the following code: <li><a href="http://localhost:8666/web1/profile/mainpage/logout.php" onclick="return confirm('Are you sure to logout?');">Log Out</a>&l ...

CSS: Dynamically adjusting height based on parent element's current height

I'm seeking clarification on the topic at hand. Why am I unable to simply use the following code: <div style="min-height: 100vh"> <div style="height: 100%"> </div> </div> When I implement this code, ...

Creating a responsive div with inner content is a simple task that can be accomplished without relying

I am looking to create a responsive div along with its inner content, so that the div adjusts in size as I resize the window without relying on bootstrap. An example of what I'm trying to achieve is shown below: <div id="mapImage1" class= ...