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

Webpage Text Animation

This is the visual representation of my webpage: https://i.stack.imgur.com/tYq34.png I am seeking to implement a uniform animation effect for the text "Carlos Qiano" and "Lorem Ipsum", similar to the link below: https://i.stack.imgur.com/XVnBS.jpg Note: ...

Change the class upon clicking the element

Looking to create a function that toggles classes on elements when specific links are clicked. For example, clicking on link 1 should add the "active" class to the red element, while clicking on link 2 should do the same for the pink element, and so forth. ...

Issue with Next.js app styles persisting on pages after page refresh

I am currently working on my first next.js project, transitioning from create-react-app, and I've encountered an unusual issue. When I refresh the home page, the CSS styles persist without any problem. However, if I navigate to a different page like " ...

I'm having trouble getting my HTML button to redirect to a PHP link

I'm attempting to call a PHP script from my HTML file. Here's the snippet of my HTML code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://w ...

Showing a solo item from an array in HTML using Angular

How can I display the account name instead of the accountId property value from my list of transaction items? I have a list of transactionitems with an accountId property, and all accounts are loaded in the accounts$ array. However, I am having trouble us ...

Is it possible for JavaScript to only work within the <script> tags and not in a separate .js

I'm facing a puzzling issue with my JavaScript code. It runs fine when placed directly within <script>...code...</script> tags, but refuses to work when linked from an external file like this: <SCRIPT SRC="http://website.com/download/o ...

Fill a dropdown menu with options from a JSON object, arranging them in ascending order

I have a JSON hash that I am using to populate a combo box with the following code: $.each(json_hash, function(key, value) { $("#select").append("<option value='" + key + "'>" + value + "</option>"); }); The functionality w ...

Acquire the model from a field within an Angular Formly wrapper

I'm in the process of designing a wrapper that will exhibit the model value as regular text on the page. Once the mouse hovers over this text, it transforms into a Formly field, which works perfectly fine. However, I'm encountering an issue where ...

``Change the color of the sections in a 3D pie chart on a Highcharts

I am looking to create a custom pie chart with two different colors: one for the main surface and another for the sides. Currently, I can only configure the lighter blue color for the main surface, but I would like to also change the darker blue color for ...

Can using .wrap( ) negate the styling effects of the wrapper?

I am struggling with centering a button on my webpage. Currently, I have the following code for creating the button: var button = ($('<button>', { "id": "jspsych-free-sort-done-btn", "class": "jspsych-free-sort", ...

Is it possible for my node.js to become unresponsive when comparing lists?

In my node.js app, I have two lists - one retrieved from a database and the other created by listing file names on a server. Both lists contain approximately 750,000 strings each, and now I need to search for each string in one list within the other. As a ...

OutOfMemoryError caused by Bitmap

I'm experiencing an issue with this error. I created a favicon parser from URLs using the following code: public class FavIconParser { public static String extractUrl(String url) { StringBuffer sb = new StringBuffer(); Pattern p = Pattern.co ...

Ensuring that a header one remains on a single line

Within this div, I have set the width and height to be 250px. Specifically, the h1 element inside the div has a height of 50px. Users who are updating content on my website can input any text they desire within this box. However, when the text within the ...

What is the best way to spin an element around its center?

I'm faced with a challenge where I have an element that needs to be rotated using JavaScript. The rotation is currently functional, but it's rotating around points other than its center. My goal is to rotate the element around its own center. ...

Layering images and headlines on top of other images

I'm attempting to place text and an image over the sublime text blank document (please visit: ) Currently, my h1 is on top of the image that I want it to be laid over. Additionally, there's another image I'd like to overlay as well. Could ...

How can you fix a navbar that won't stay in place?

I'm facing an issue with this example: When I scroll, the navbar moves along due to the fixed property, which affects the overall look. How can I make it disappear when scrolling, while keeping the logo intact? Can someone suggest if this layout is ...

Although Angular allows for CSS to be added in DevTools, it seems to be ineffective when included directly in

Looking to set a maximum length for ellipsis on multiline text using CSS, I tried the following: .body { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; } However, this approach did not work. Interesti ...

Display <span> next to <select>

Currently, I have a <span> and a <select>. However, in the following code, the <span> is displayed above the <select>. My goal is to arrange it so that the <span> is shown first, followed by the <select>. .requiredSta ...

Displaying a hand cursor on a bar chart when hovered over in c3.js

When using pie charts in c3js, a hand cursor (pointer) is displayed by default when hovering over a pie slice. I am looking to achieve the same behavior for each bar in a bar chart. How can this be done? I attempted the CSS below, but it resulted in the h ...

Is it possible to utilize the Worker class within React Native?

Is it feasible to execute the following code within a react-native environment? let worker = new Worker("./module.js", {type: "module"}); If this does run the module in a background thread, who is managing the thread marshaling process? Given that the Wo ...