Place some written content below a picture

I'm currently designing a website and I'm trying to create a layout with four images in a square arrangement, each with text underneath them. However, I'm facing an issue where the text is not appearing underneath the images as intended.

Here's the HTML code:

<section class="section-2">
    <div class="item">
        <img src="#">
        <p>text</p>
    </div>
    <div class="item">
        <img src="#">   
        <p>text</p>
    </div>
    <div class="item">  
        <img src="#">
        <p>text</p>
    </div>
    <div class="item">
        <img src="#">
        <p>text</p>
    </div>
</section>

And here's the CSS code:

.section-2 {
margin: 200px 30px 30px 30px;
width:100%;
float:right;
min-height:1000px;
height:100%;
}

img {
float:left;
margin: 0px 100px 200px 150px;
width: 30%;
height: 30%;

Answer №1

If you're looking for a simple and efficient way to align cards, consider using a grid layout. By applying display: grid;, you can easily arrange the cards in a grid format. To have 2 cards aligned side by side, just include

grid-template-columns: repeat(2, 1fr);
in your styling. You can adjust the number within the parentheses to control how many cards appear horizontally next to each other. To add spacing between the cards, utilize grid-gap: followed by the desired gap value.

.section-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 15px;
}

.section-2 div img {
  width: 100%;
}
<section class="section-2">
  <div>
    <img src="https://www.tacoshy.de/Images/Yoshi/IMAG0735.jpg">
    <p>I'm a Syrian Hamster</p>
  </div>
  <div>
    <img src="https://www.tacoshy.de/Images/Yoshi/IMAG0736.jpg">
    <p>I like to eat watermelons</p>
  </div>
  <div>
    <img src="https://www.tacoshy.de/Images/Areno/IMAG0865.jpg">
    <p>I love to burrow tunnels and caves</p>
  </div>
  <div>
    <img src="https://www.tacoshy.de/Images/Areno/IMAG0863.jpg">
    <p>And I really enjoy sleeping in my self-dug caves</p>
  </div>
</section>

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

Alignment of label not remaining centered vertically, issue with bootstrap

Struggling with getting this label to stay centered vertically? It always seems to appear at the top. Any help would be greatly appreciated. Thank you! Check out the code here <div class="container"> <div class="row"> <div clas ...

Reducing size of HTML components using CSS

Can child HTML elements be resized using only CSS? Below is an example for reference. I am interested in different approaches to achieve this effect without using JQuery. Is there a simpler method? <div class="your_custom_styling_here_for_resizing"&g ...

Generate a vertical line that spans the entire length of the webpage in a vertical direction

Looking for a way to add vertical borders that span the entire webpage to some text? Check out this HTML snippet: <div id="vLine"> <h1>text</h1> </div> Here's the accompanying CSS: #vLine { height: 100%; width: 5 ...

Issues with the z-index in a dropdown menu

Hey, need a little assistance here. I'm facing an issue with my drop down menu. It seems to always be one layer behind the body, even though I've set the z-index of the menu to 999 and the z-index of the body to -999. Could you please take a loo ...

What is the method for determining the number of unique tags on a webpage using JavaScript?

Does anyone have a method for determining the number of unique tags present on a page? For example, counting html, body, div, td as separate tags would result in a total of 4 unique tags. ...

Is it possible to use PHP to open a specific folder on my computer when a certain button is clicked? Additionally, I need it to be compatible

Can PHP be used to open a computer directory with a click event? <body> <a href="file://C:/Users/Pictures/">Click here to view the directory</a> </body> ...

Ways to troubleshoot an unusual margin issue in a static column of an HTML table

I have been exploring various resources to create an HTML table with a fixed first column using CSS only. Despite my efforts, the fixed column is consistently appearing lower than the rest of the content, and I'm unsure why. Check out the code I&apos ...

Ways to tally elements that have been dynamically loaded onto the webpage through AJAX requests

My page has a dynamic region that is continuously updated using jQuery's .ajax and .load methods. In order to submit the form, there need to be at least 3 of these 'regions', so I have to keep track of the number of DIVs with a specific cla ...

After refreshing the page, RouterLinkActive in Angular 6 fails to work

Scenario In my application, there is a menu with various items. The selected item is distinguished by adding the selected class to it, which changes its appearance. https://i.sstatic.net/JEPHH.png Problem While navigating between routes works smoothly, ...

Animating CSS3 keyframes on backgrounds with a full width and height dimension

I'm currently working on animating the background of a full-width and full-height element using a simple CSS3 animation that steps through a sprite image. Here's what the animation code looks like: .play-intro{animation: play 2s steps(6);} @key ...

Display either the Web or Mobile modal upon page load based on the screen size

For my design project, I have crafted two unique modals that will pop up when their corresponding button is clicked. However, I have set it up so that each button is only visible on certain screen sizes using CSS @media query. Now, I am looking to make a ...

Disorganized HTML Elements

If you visit diartefloral.tech and use a cellphone in the "Sobre Nosotros" section of the menu, the footer overlaps an image. I'm not sure how to fix this issue. The most relevant code is shown below; I am using Bootstrap. Previously, I had an issue w ...

Can Puppeteer be utilized for converting PDFs to HTML format?

Is it possible to convert PDF to HTML in addition to HTML to PDF? I haven't come across any resources that address this specific conversion process. ...

Using SVG as a background image on Internet Explorer with zoom capabilities

I am having an issue with my SVG used as a background image: <div class="bubble"></div> Here is the CSS I am using: .bubble { background-image: url(https://beta.creasoft.cz/Images/bubble-small.svg); background-repeat: no-repeat; width ...

Guide to changing the class of a particular child element when the parent element is clicked with vanilla JavaScript

Upon clicking the parent button, a class within its child element will toggle to show or hide. If the child element is selected, a loading animation will appear for a brief moment before reverting back to its original hidden state. I attempted to achieve ...

Icon and div-based carousel/slider for a unique visual experience

I have a project in progress that requires dynamically displaying icons based on the user's selection. These icons are essentially glyphs with a two-word title underneath them. Essentially, there is an <div class="col-md-9"> ...

"Python Flask: Resolving issues with favicon not appearing on website

I've been attempting for the past 45 minutes to find a way to display my favicon on my Flask webpage. Here is the code I'm currently working with: from flask import Flask, render_template, send_from_directory, url_for import os app = Flask(__na ...

The fixed-top navbar in Bootstrap 5 is not displaying the toggle button

I have encountered an issue with the Bootstrap 5 navbar. When I set it to be fixed at the top, the toggle button does not show up when resizing the browser window. However, if I remove the 'fixed-top' class, the toggle appears as expected. What c ...

Is there a way to utilize jQuery to redirect to the href included in the HTML attachment?

I am looking to add a redirection feature to my website using the href provided in the code by jQuery. This will be done after playing an animation for better user experience. $(document).ready(function(){ $("a").click(function(event){ event.prev ...

Angular animation causing unexpected behavior with CSS z-index

I am currently working on incorporating a drag and drop feature into my application. My goal is to designate the drop zones with text that will disappear once an item is added. In terms of design, I would like to utilize animate.css's bounce in animat ...