Create a list item that includes an image with a corresponding label positioned beneath it

Currently attempting to convert my design into HTML and CSS for the first time, I've hit a roadblock with this particular task:

I'm trying to create a series of white boxes, with each item having a white border. However, I'm struggling to center the Label Tag horizontally. Additionally, after changing the img Label to block display, I can't seem to add padding or margin to create sufficient space between the label and the image.

This is what I have so far:

Html:

<div class="content">
<div class="container">

<ul class="grid">
    <li><img src="img/Icon-House.png"><label>Houses</label></li>

</ul>
</div>
</div>

CSS:

.content{
    background-color: #e24840;
    width: 743px;
    height: 300px;

    margin-top: 48px;
    margin-left: 183px;
    border-radius: 4px; 
    box-shadow: -5px 5px 10px #888888;
}

.content ul {
    float: left;

}

.content li {
    margin: 20px;
    width: 200px;
    height: 180px;
    border-color: white;
    border-width: 2px;
    border-radius: 4px;
    border-style: solid;
}

.content img{
    margin-left: auto;
    margin-right: auto;
    margin-top: 25px;
    display: block;
}

.content label{
margin-top: 48px;
margin-right: auto;
margin-left: auto;
}

Answer №1

I suggest using a figure instead of a label to enclose both the image and its figcaption.

.content {
  background-color: #e24840;
  width: 743px;
  height: 300px;
  margin-top: 48px;
  margin-left: 183px;
  border-radius: 4px;
  box-shadow: -5px 5px 10px #888888;
}
.content ul {
  float: left;
  list-style-type: none;
}
.content li {
  text-align: center;
  margin: 20px;
  width: 180px;
  height: 160px;
  border-color: white;
  border-width: 2px;
  border-radius: 4px;
  border-style: solid;
}
.content img {
  margin-left: auto;
  margin-right: auto;
  display: block;
  position: relative;
}
.content figcaption {
  background: yellow;
}
<div class="content">
  <div class="container">

    <ul class="grid">
      <li>
        <figure>
          <img src="http://lorempixel.com/output/city-q-c-100-100-4.jpg" />
          <figcaption>Houses</figcaption>
        </figure>
      </li>

    </ul>
  </div>
</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

Enhanced Compatibility of HTML5/CSS3 Modal Box with Internet Explorer

I'm experimenting with HTML5/CSS3 for the first time and have implemented a cool little link to display a dialog (modal) on one of my web pages. While this works perfectly in Chrome/Firefox, it unfortunately doesn't function properly in Internet ...

differences in rendering of flexbox align-items: center between Chrome and Firefox

As I was attempting to center a div inside another div using flexbox, an inconsistency in rendering between Firefox and Chrome caught my attention. In the scenario, there are 3 divs, each with properties display:flex, justify-content:center, and align-ite ...

Tips for updating the content of a div with fresh data using a slideshow effect in jQuery

Imagine you have a div called A and an array filled with text data. When t=0, div A will display $data[0]. Then, after every n seconds, I want the div to show the next piece of data in the array. I am interested in creating a transition effect similar to ...

Dropdown sidebar with collapsible sections

I am looking to create a unique navigation system for my website. I have a standard HTML list with menu items that will serve as anchor links on a long-scrolling page. My idea is to design it as a minimal vertical side navigation bar, where each item initi ...

Focused input filter in a tabular header style

I've been working on customizing the Tabulator header filter to have a more "flattened" style, as requested by my boss. In my CSS, I added the code ...input:focus{border:1px solid #1bb394} to change the input border to 1px green. While this change tak ...

Is it possible to retrieve JavaScript object properties using HTML elements?

I have fetched an array of objects using jQuery.getJSON(). Each object should be represented by an HTML div element, allowing users to click on the element and access all properties of the corresponding object. What is the most efficient approach for achie ...

Ways to examine the origin of an image based on the attributes of a React component that I have passed as a prop?

I'm facing an issue where I can't use the component's prop to set the src of an image that I imported from a file path in my component's JavaScript file. I have tried different syntaxes but none seem to be working. Here are the formats ...

The disappearance of IE7 floats is observed when their parent element is styled with position:relative

The issue I'm encountering in IE7 is related to the CSS properties position:relative;, float: right;, and float: left;. While this problem doesn't seem to occur in newer browsers, it's puzzling why position:relative; impacts the behavior of ...

Recursive instruction malfunctioning

I'm currently trying to develop a custom recursion directive, but unfortunately it's not functioning as expected. I have followed the instructions outlined here: Recursion in Angular directives For reference, you can view the fiddle here: http ...

Attempting to create a single function that can be utilized with numerous divs that share the same class in jQuery

Currently, I am working on creating a basic jquery gallery viewer. In my code, I have the following structure: <div class="photoset"> <img /> <img /> </div> <div class="photoset"> <img /> <img /> <i ...

Issue with Bootstrap Nav Pills only functioning properly for the initial option

When using Bootstrap nav pills, only the first one seems to work properly in my case. Even though I have inserted forms for each nav pill, it only shows a blank page. https://i.sstatic.net/QsL1l.png https://i.sstatic.net/Swmtq.png I have PHP code inside t ...

I am working on an HTML form that is designed vertically, but I am unsure of how to arrange two text fields side by side on the same line

I'm struggling with formatting my HTML form to have two text fields on the same line instead of stacked vertically. In the example below, I want the Size, Width, and Height fields to be aligned horizontally rather than one below the other. <form c ...

Utilizing the Bootstrap grid system to seamlessly display images

I have been attempting to design a column that is divided into two nested columns, each containing images that should fill the entire height and width of their respective columns. However, I am facing an issue where the images are extending beyond the boun ...

Displaying items in a row when the navbar is collapsed: Bootstrap 4 tips

Is there a way to change the display of items in the collapsed navbar so that they appear next to each other rather than in a column? You can see how it currently looks here: Navbar collapsed. My goal is to have the image displayed next to the username ins ...

Issue encountered when attempting to remove an element from an array using the delete method

Whenever I attempt to remove an input that has been added, an error message saying "Value is NULL" pops up. I'm looking for a solution where only the selected inputs are deleted when I click on DELETE, instead of all inputs being removed. The myFuncti ...

Guide to dynamically add tr element using CSS to a table

While using the $.each function in jQuery, I am retrieving data and adding it to a table in the following manner: $.each(segment, function (index, innerSegment) { var tr; tr = $('<tr/>'); tr.append("<td>" + segment[i].Airline.Air ...

"Jsoup interprets certain characters in a unique way during parsing

I attempted to parse this HTML file using Jsoup: <html><body>Maître Corbeau, sur un arbre perché</body></html> The line of code I used was: Document document = Jsoup.parse(input, "UTF-8"); However, when I tried to print the do ...

Sending target information as a property argument

I have encountered an issue with my app's two Bootstrap modals. It seems that many people are facing problems with opening the second modal. Is it possible to pass data-target and modal id properties as props in this manner: data-target={props.da ...

Emphasize a specific line of text within a <div> with a highlighting effect

I'm looking to achieve a similar effect as demonstrated in this fiddle As per StackOverflow guidelines, I understand that when linking to jsfiddle.net, it's required to provide some code. Below is the main function from the mentioned link, but f ...

Tips for implementing collapsible mobile navigation in Django with the help of Materialize CSS

I'm facing some issues with implementing a responsive navbar that collapses into a 'hamburger bar' on mobile devices and in split view. I have managed to display the hamburger bar, but when I click on it nothing happens. Here's my curre ...