Inserting text underneath an image within a numbered list using HTML

I am attempting to achieve a specific layout where I have images in a list with text placed directly below each image. However, my attempts using <figure> and <figcaption> have not been successful.

Below is the HTML code for my list:

<div class="verticalStrip">
    <br>
    <ul>
        <li><img src="image1.png" alt="im1"/></li>
        <li>text1</li>
        <li><img src="image2.png" alt="im2"/></li>
        <li>text2</li>
    </ul>
</div>    

Unfortunately, this is the result I currently have:

My desired outcome should look like this:

Any assistance on achieving this layout would be greatly appreciated.

UPDATE1: Adding the following CSS rule as suggested in one of the responses:

img { display: block; }

Resulted in the following changes:

Answer №1

After making changes to the HTML structure:

<div class="verticalStrip">
    <br>
    <ul>
        <li><img src="image1.png" alt="im1"/>text1</li>
        <li><img src="image2.png" alt="im2"/>text2</li>
    </ul>
</div>    

Here is a suggestion for the CSS:

img {
    display: block;
}

You can view the demo on JS Fiddle here.

In response to the question from the original poster in the comments:

is there any way to create some spacing between text1 and image2?

The answer is, indeed, 'yes.' You can add a margin-bottom to the <li> elements, like this:

li {
    margin-bottom: 2em;
}

Check out the modified layout on JS Fiddle here.

Alternatively, you could use padding-bottom instead:

li {
    padding-bottom: 2em;
}

See the updated design on JS Fiddle here.

Answer №2

Perhaps using a table is the solution? Give this a try.

<html>
<head>
<body>
<div class="verticalStrip">
    <br>
    <table>
        <tr><td><img src="image1.png" alt="im1"/><br/>text1</td></tr>

        <tr><td><img src="image2.png" alt="im2"/><br/>text2</td> </tr>
    </table>
</div>    
</body>
</html>

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

What is the method for attaching a keypress event to an HTML document?

Looking to add an interactive touch to my website by creating a "press any key" page. When a key is pressed, I want it to kick off animations that bring the page to life - like sliding elements in from different directions. Open to using jQuery or plain ...

Is there a way to make a table stay at a specific width for screen sizes larger than 1000px, but then adjust its size accordingly as the window size decreases?

<table id="example" class="row-border compact" style="width:1000px; table-layout:fixed;"> The table is currently set to have a width of 1000px, but I would like it to be 90% of the screen width when the window size is less than 1000px. Is it possibl ...

Display a DIV element when hovering over another DIV element using CSS or JavaScript without them being directly related as parent and

So I've figured out how to use CSS to show a hidden div when you hover over its parent. But what if the hidden div is not a child of the parent you want to hover on? How do you make it appear then? For example: <div class="field-1"></div> ...

The jQuery UI button only functions correctly for a specific element, not any other element

I have incorporated jQuery UI buttons to create an answer form: http://example.com The initial set of buttons is working well, placed under the HTML box. However, when a user clicks on the first button, the subsequent set of radio buttons does not inherit ...

Pick out grouped objects without the use of Javascript

I am looking to design a single page where the display of categorized items changes based on user selection. Ideally, I want this to be chapter/hash (:target) dependent, but checkboxes influencing state would also work. As an experiment, I am trying to ac ...

Step-by-step guide to making a circular "clip-path" work in both Internet Explorer and Firefox

Can someone help me with circle-masking in different browsers? It's working fine on Chrome. I need to make it work on Firefox and IE as well. Looking for a solution without using radius-border... .circle { -webkit-clip-path: circle(100px at 100p ...

Tips for selecting a dropdown item that shares the same data-testid

I am attempting to use Selenium to click on an option in a dropdown menu. The options all have the same 'data-testid', and the only unique identifier appears to be the link text. Does anyone know of a way to select a specific choice within the dr ...

Is there a way to ensure that an inner div always stretches to the full width of the browser window regardless of its parent's width configurations and size?

Can an inner div always be made to have the width of the full browser window regardless of its parent's width settings and dimensions? Additionally, can this div be positioned at the left side of the page with a CSS property of left: 0, relative to th ...

Creating a new variable in Python with enumerate in list comprehension

Consider a scenario where you need to determine the number of jumps between consecutive 1's in a binary string, for example, with the binary representation of 169 being 10101001. The expected answer would be 3, 2, 2 since starting from the rightmost ...

What is the best way to achieve consistent alignment in Javascript?

I have been attempting to incorporate HTML code within JavaScript for alignment and styling. Despite searching on Google for 3 to 4 days, I have not found a suitable answer yet. What exactly am I looking for? Here is a snippet of my JavaScript code: funct ...

Unconventional arrangement of gaps for radio buttons

Hey there, I've been searching for solutions on various platforms but haven't found any luck so far. These are the questions I've looked into: Radio buttons and label to display in same line Documentation on <FIELDSE ...

Using jQuery to show and hide elements on a webpage

One issue I'm facing is changing the content on a page depending on the clicked link. The problem arises when the displayed content for one link persists even after clicking another link, despite setting it to not display when another link is clicked. ...

coding with javascript and css

Essentially, I am trying to add padding specifically to the left side of this code snippet: if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("live ...

Implemented an HTML hyperlink element precisely positioned

I have the following HTML code. I am trying to fix the position of an anchor tag called "View All" so that it stays in a specific location. However, whenever the value in the dropdown menu changes, the anchor tag moves according to the length of the new se ...

My goal is to display the information retrieved from my AJAX response within my jQuery data table

I am attempting to display my AJAX response in a jQuery data table. The structure of my table is as follows: <div style="margin: 20px;"> <table id="example" class="display" style="width:100%"> ...

Node.js express failing to load CSS files

I am currently developing a weather app using node.js and express, but I'm facing an issue where the CSS is not loading. I have followed the instructions provided in this link, however, I have not been successful so far. It's worth mentioning tha ...

Guide to overlaying an SVG on a PNG in an HTML document

Can anyone provide guidance on how to position an SVG logo on top of a PNG image, centered within it? Here is the image I am working with: https://i.sstatic.net/GWrGs.png This is the desired outcome: https://i.sstatic.net/PEgVw.png Below is my SVG file ...

What is the best way to prioritize .py-md-6 over .p-3 in Bootstrap 4?

I have set the padding for the class .py-md-6 as follows: .py-md-6 { padding-top: 6rem !important; padding-bottom: 6rem !important; } Despite this, there seems to be a conflict with the .p-3 class in my HAML element: #id.p-3.py-md-6 It appears th ...

Canvas Frustratingly Covers Headline

Several months ago, I successfully created my portfolio. However, upon revisiting the code after six months, I encountered issues with its functionality. Previously, text would display above a canvas using scrollmagic.js, and while the inspector shows that ...

Achieve uniform height for two elements using Material UI

Here is the code snippet I have: <div className="center"> <TextField variant="outlined" className="manualUserFollowTxt" required id="manualUserFollowTxt" label="Username" name="username" autoComplete="username" a ...