CSS: Basic yet effective image display showcase

Web development is not my main focus, but when I delve into it, CSS always presents a frustrating challenge. My goal is to create a basic class that combines images with descriptions in a structured manner. Specifically, I aim to display two rows, each containing three images - a simple layout indeed.

The code I have for showing images exclusively seems to be functioning adequately.

img {
  position: relative;
  margin: 0 auto;
  max-width: 650px;
  padding: 5px;
  margin: 10px 0 5px 0;
  border: 1px solid #ccc;  
}

<h3>Screenshots</h3>

<p>
<a href="images/img1.png"><img src="images/img1.png" width="200" height="140"></a>
<a href="images/img2.png"><img src="images/img2.png" width="200" height="140"></a>
<a href="images/img3.png"><img src="images/img3.png" width="200" height="140"></a>
<a href="images/img4.png"><img src="images/img4.png" width="200" height="140"></a>
<a href="images/img5.png"><img src="images/img5.png" width="200" height="140"></a>
<a href="images/img6.png"><img src="images/img6.png" width="200" height="140"></a>
</p>


<h3>Installation</h3>

The current display showcases the images exactly as intended, with three in each row followed by a padding from < p > and then an Installation section. To add descriptions below the images within the same div, I modified 'img' in the CSS to 'div.img' and updated the HTML code:

<h3>Screenshots</h3>

<p>
<div class="img">
  <a target="_blank" href="images/img1.png"><img src="images/img1.png" width="200" height="140"></a>
</div>
<div class="img">
  <a target="_blank" href="images/img1.png"><img src="images/img1.png" width="200" height="140"></a>
</div>
<div class="img">
  <a target="_blank" href="images/img1.png"><img src="images/img1.png" width="200" height="140"></a>
</div>
<div class="img">
  <a target="_blank" href="images/img1.png"><img src="images/img1.png" width="200" height="140"></a>
</div>
<div class="img">
  <a target="_blank" href="images/img1.png"><img src="images/img1.png" width="200" height="140"></a>
</div>
<div class="img">
  <a target="_blank" href="images/img1.png"><img src="images/img1.png" width="200" height="140"></a>
</div>
</p>

<h3>Installation</h3>

Assuming that the resulting web page would maintain the same appearance since 'img' in both cases carry identical attributes, this assumption proved wrong. With this adjustment, each div extends the full width of the column while the images stack vertically on the left side within each div.

I've also experimented with this code from W3Schools, yet this caused the Installation text and all subsequent content to overlap the images, disregarding the bottom margin set on the < p > tag.

Answer №1

If you want to simplify things, consider replacing your divs with <span> elements or setting display: inline in your CSS for the divs. This will alter their behavior to act as inline instead of block elements.

Additionally:

  • Omit the margin: 0 auto as it does not center inline elements like it does block elements
  • The inclusion of position: relative may be unnecessary unless you plan on using absolute positioning within the div in the future

Check out this jsfiddle link without the mentioned properties and with display: inline applied to the divs: http://jsfiddle.net/3BwKY/.

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

Utilizing Conditional Styling for an Array of Objects within a Textarea in Angular 6

My array contains objects structured as follows: list =[ { name:"name1", value:true } { name:"name2", value:false } { name:"name3", value:true } { name:"name4", value:false ...

Tips for utilizing the output of a pre-defined function within another function in SASS

How can I effectively utilize the outcome of darken( $var, 10% ) in the SASS function oppositeColor( $darkenedColor )? The code I am working with currently looks like this: $color1: #000000 !default; $color2: darken( $color1, 5% ) !default; $color3: oppos ...

Tips for Implementing Color-coded Manchu/Mongolian Script on Your Website

My journey began with a seemingly straightforward task. I had a Manchu word written in the traditional script and I wanted to change the color of all the vowels in the word (ignoring ligatures). <p>ᠠᠮᠪᡠᠯᠠ ᠪᠠᠨᡳᡥᠠ</p> < ...

Dynamically Allocating Page Heights

I am tasked with creating an ASP.NET MVC page that will display a template of controls. The controls will be retrieved from an XML file. One issue I am facing is that the number of controls is not fixed, so the page height needs to be dynamic. Our site has ...

Concealing excess background color in HTML/CSS

I'm currently experimenting with adding a background color shape, such as a large rotating div, to the background of my website. However, I've encountered an issue where placing this background in the desired location is causing a large margin to ...

Java Image Stacking

I'm struggling to set a background image properly in my code. Whenever I try to layer other elements on top of the background, it ends up covering everything. Can someone please guide me on how to correctly layer images? So far, the code I have for p ...

Add Text to Bootstrap Modal Window

The bootstrap modal body is not containing all of my content and some of it is overflowing. <div class="modal fade" tabindex="-1" role="dialog" id= "blockModel"> <div class="modal-dialog"> <div class="modal-content"> < ...

Positioning a button beside an input field within a table row

This is how my current table layout appears. Table: https://i.sstatic.net/wcHuz.png I am attempting to position the small x button next to the input textbox. Here is the code I have written so far. <table class="table table-hover"> <thead ...

Finding the Row Number of an HTML Table by Clicking on the Table - Utilizing JQuery

Seeking assistance to tackle this issue. I currently have an HTML table with a clickable event that triggers a dialog box. My goal is to also retrieve the index of the row that was clicked, but the current output is not what I anticipated. //script for the ...

Ways to resolve issues with resizing div elements while waiting for JavaScript to load

Apologies for the lack of a clear title to describe my issue. My problem involves this snippet of code, where I am creating a label to show time to users. <div class="content"> <div class="container"> <div class="card"> < ...

Unable to set focus on a disabled button programmatically, issue persists

$(function () { $('#save').click(function() { $('#save').attr('disabled', 'disabled'); console.log($(document.activeElement).attr('id')); }); $('#test').focus(); co ...

Choosing various items from the drop-down menu to display on the webpage

In my application, I have implemented a feature where data from an array is displayed in various panels. Users are given the option to remove panels from the view, with the removed panels then being populated in a dropdown menu. This allows users to select ...

Issue encountered when trying to integrate a CSS sticky footer with a liquid/fluid layout

I've been attempting to incorporate the CSS Sticky Footer technique demonstrated at cssstickyfooter.com. (I also experimented with Ryan Fait's solution without success). I believe I've followed all the instructions correctly. I have a conta ...

Refrain from adjusting the zoom on your wallpaper

Could someone please explain how to set the wallpaper on an Android device without it getting zoomed in? No matter what resolution image I use, it keeps getting zoomed and set as the wallpaper. Below is the code I am currently using: setWallpaper.setOnC ...

Can we isolate and package essential CSS classes exclusively within a web application?

I'm curious if there is a tool that can extract only the necessary CSS classes from my files and package them together. I currently use tools like 'gulp' and 'webpack' to bundle asset files, but I wonder if there's something s ...

Guide on dynamically changing the color of polymer 1.0 paper-button from an array of colors

I have an array called buttonColors that contains a set of colors in hex format. I am looking to create paper-buttons, each with the color from the buttonColors array. How can I achieve this in Polymer 1.0? <template is="dom-repeat" items="{{buttonCo ...

Require Assistance With Creating a Typing Animation in JavaScript?

Recently, I created a JavaScript text typer code: Here is the CSS: body { background-color: black; } #writer { font-family: Courier; font-size: 12px; color: #24FF00; background-color: black; } And here is the JavaScript: var text ...

Ways to format the direct descendant of a multi-level list?

Check out my nested ul list: <ul> <li> <a href="/"></a> </li> <li> <a href="/"> </a> &l ...

Using jQuery: If the URL includes a specific string, then modify the background color of a particular tag

I need to dynamically change the background color of a tag in my code based on the URL. If the URL contains Suisse, I want the background color of the tag #switch-univers li a.bilgroup to be green. JS if (window.location.href.indexOf("Suisse") > -1) { ...

Tips for including a photo in a php mysql database

I have created a database add page that successfully allows users to add objects to a database. However, I am struggling to incorporate images into the entries. Below is my current solution, which is working fine but lacks the ability to upload images. Wha ...