Photographs acting in a bizarre manner

A friend of mine encountered an issue with a website related to a school project. They were trying to set up a small gallery.

The first 5 pictures displayed correctly as intended, but then they appeared like this:

After testing various solutions for about an hour, we attempted placing the bottom 3 pictures in a separate div block with the class of bilder, but the outcome was the same. Rearranging the pictures in different orders to check if it had something to do with the images themselves also led to the same result.

div.wrapper {
    font-family: Calibri;
    width: 100%;
    float: left;
    color: white;
}

h1 {
    color: #F99F00;
    text-align: center;
}

body {
    background-color: black;
    margin: 0;
    padding: 0;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: black;
}

li {
    float: left;
    font-family: fantasy;
    font-size: 120%
}

li a {
    color: white;
    display: block;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover:not(.active) {
    background-color: green;
}

.active {
    backround-color: green;
}

li.selected  a {
    color: green;
    display: block;
}


#tct  {
    
    top: 15%;
    left: 5%;
    padding: 1%;
    color: #F99F00;
    font-size: 200%;
}



div.bilder img {
    padding: 1%;
    width: 18%;    
    float: left;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Counter-Strike: Global Offensive</title>
    <link href="../css/waffenliste.css" rel="stylesheet" type="text/css">
    <link href="pictures/csgotab.png" rel="shortcut icon" type="image/x-icon">
</head>
<body>
<div class="wrapper">
        <div>
            <h1>Counter-Strike: Global Offensive<h1>
        </div>
        <div>
            <ul>
                <li><a href="../index.html">Home</a></li>
                <li class="selected"><a href="waffenliste.html">Waffenliste</a></li>
                <li><a href="spray.html">Spray Patterns</a></a></li>
                <li><a href="ueber.html">Über</a></a></li>
                <li><a href="impressum.html">Impressum</a></li>
            </ul>
        </div>
        <div id="tct">
            <p>Kaufbar f&uuml;r: T und CT</p>
        </div>
        <div id="t">
            <p>Kaufbar f&uuml;r: Terroristen</p>
        </div>
        <div id="ct">
            <p>Kaufbar f&uuml;r: Antiterroreinheit</p>
        </div>
        <div class="bilder">
        <img id="awp" src="pictures/awp.PNG">
        <img id="scout" src="pictures/scout.PNG">
        <img id="dual" src="pictures/dual.PNG">
        <img id="p250" src="pictures/p250.PNG">
        <img id="deagle" src="pictures/deagle.PNG">
        <img id="nova" src="pictures/nova.PNG">
        <img id="negev" src="pictures/negev.PNG">
        <img id="m249" src="pictures/M249.PNG">
        </div>
        
</div>
            
</body>
</html>

Answer №1

If you're looking to improve your website's image gallery layout, consider implementing the following HTML and CSS structure:

section #imageGallery li {
display: inline-block;
margin: 20px;
list-style: none;
}

section #imageGallery li div {
width: 280px;
height: 290px;
color: black;
}

#imageGallery .one {
background-image: url(/Images1.jpg);
background-repeat: no-repeat;
background-size: cover;
background-color: #f9f8f5;
}
#imageGallery .two {
background-image: url(/Images2.jpg);
background-repeat: no-repeat;
background-size: cover;
background-color: #f9f8f5;
}
#imageGallery .three {
background-image: url(/Images3.jpg);
background-repeat: no-repeat;
background-size: cover;
background-color: #f9f8f5;
}
#imageGallery .four {
background-image: url(/Images4.jpg);
background-repeat: no-repeat;
background-size: cover;
background-color: #f9f8f5;
}
#imageGallery .five {
background-image: url(/Images5.jpg);
background-repeat: no-repeat;
background-size: cover;
background-color: #f9f8f5;
}
<section>
    <ul id="imageGallery">
        
        <li>
            <div class="Image one">
              
            </div>
        </li>
       <li>
            <div class="Image two">
              
            </div>
        </li>
       <li>
            <div class="Image three">
              
            </div>
        </li>
       <li>
            <div class="Image four">
              
            </div>
        </li>
        <li>
            <div class="Image five">
              
            </div>
        </li>
    </ul>
</section>

Give it a try and see how this new layout enhances the visual appeal of your website's image gallery.

Answer №2

To achieve the desired effect, apply the following CSS styles:

section.gallery {
    margin: 0 auto;
}
section.gallery img {
    padding: 2%;
    width: 20%;    
    display: inline-block;
    vertical-align: top;
}

Answer №3

The reason for this issue is due to the fact that you have applied floating to all images. Instead of using floats for image display, it is recommended to utilize inline-block. This will be sufficient for aligning images in a row.

If you prefer to continue using floating, make sure to include a clearfix after the last image in the line.

.clearfix:after {
  content: "";
  display: table;
  clear: both;
}

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

Ensure that the text panel is properly aligned directly under the logo

I need help achieving a layout similar to the image linked below: https://i.sstatic.net/GTOJF.jpg In my design, the red box represents my company logo with some text hidden. However, in my attempt shown in the second image here: https://i.sstatic.net/7xY ...

The bootstrap select dropdown seems to have a mind of its own and doesn't want to

While using the bootstrap-select picker to select an option, I encountered an issue where the drop-down structure with the top bar does not properly follow the parent element when the container is scrolled. If you want to see the issue in action, please c ...

Tips for implementing a "read more" feature for lengthy descriptions in Django?

In the Django platform using Python, I am working on displaying results in a template file with a large description. I am seeking guidance on how to implement a "see more" option for descriptions that exceed 4 lines. Similar to Facebook's long status ...

Apply a see-through overlay onto the YouTube player and prevent the use of the right-click function

.wrapper-noaction { position: absolute; margin-top: -558px; width: 100%; height: 100%; border: 1px solid red; } .video-stat { width: 94%; margin: 0 auto; } .player-control { background: rgba(0, 0, 0, 0.8); border: 1px ...

Glistening HTML Element along with DT::renderDataTable result$

My website is built using HTML and connected to Shiny through the use of matching IDs in HTML Elements. To display table data on the site, the code snippet below functions properly: server.R output$InfoTable <- renderTable({...}) index.html <div ...

Change the top board division

Is it possible to make a CSS-div resemble the board shown in this image ? What is this particular design style referred to as? I experimented with the skew property but couldn't quite achieve the desired effect. .board { width: 325px; backg ...

Collapse the borders of Angular's div layout container

I need help with collapsing the borders of div containers when generating a table using angular material's layout system. To see what I have done so far, please refer to my jsfiddle linked below: Jsfiddle Below is the HTML code snippet. Any guidance ...

Unveiling hidden HTML elements with BeautifulSoup: A step-by-step guide

Currently, I am attempting to extract video content from a specific website. Although I can locate the video link using Chrome DevTools, it remains hidden when utilizing BeautifulSoup for extraction. I am hoping for assistance in modifying the code below t ...

What is the best way to style an icon in CSS?

I am facing an issue with the following code snippet: <span class="stars">★★☆☆☆ </span> My objective is to style the empty stars differently, but I am unsure how to specifically target them. The following CSS rule does not produc ...

How to dynamically insert variables into a separate HTML file while creating a VS Code extension

Currently working on a vscode extension, I'm facing an issue with containing the html in a string (like this: https://github.com/microsoft/vscode-extension-samples/blob/main/webview-view-sample/src/extension.ts). It leads to a large file size and lack ...

Is it frowned upon to modify Jquery Validation for the purpose of achieving a customized style?

When it comes to adding an icon after an input field when a required field is not filled up, my friend and I have different approaches. My idea is to modify the highlight function in Jquery.Validation by adding a class to the parent element of the input ( ...

Having issues with the Vue.js documentation example not functioning properly in Codepen?

My goal is to replicate a checkbox example from Vue.js's documentation. However, when I import Vue into codepen.io and copy the code for multiple checkboxes into the JS field, then paste the HTML into the designated field, something isn't working ...

Trigger the opening of a bootstrap modal from an external source on the current page

One common question is how to load a modal from another page onto the current page, or how to open a modal on the current page when it loads. My idea is a little different: I want to click on an image hotspot (like a person in a team photo) on the /home p ...

CSS3 family tree tutorial: Incorporating a wife into the design

I came across a fascinating tutorial about creating a family tree using CSS3 only. However, I'm struggling to understand how to depict a marriage. To explain further: What the code currently accomplishes is this: what i aim to include is this: Alth ...

Font Awesome symbols using the class "fa-brands" are not functioning as expected

I have included a font awesome library in the header using the following code: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> However, when I try to display an ic ...

Utilizing partials in EJS for efficient HTML tag insertion

(1)home.ejs without using partials https://i.stack.imgur.com/3ozQQ.png (2)the output includes html tag, head tag and body tag https://i.stack.imgur.com/1o9jy.png (3)when utilizing header.ejs as a partial in home.ejs including opening html and body ta ...

The left column is stationary vertically, but can be scrolled horizontally

On a webpage, there are three columns: left, middle, and right. Only the left column is set to position:fixed, while the others are normal. When vertically scrolling, the left column should remain fixed while the other two scroll. However, when the brows ...

What is preventing me from adding a borderRadius to this particular React bootstrap tab?

I have been working on tabbed content and encountered an issue with applying border radius. Despite adding style={{borderRadius: "10px"}}, it seems to have no effect. This styling works perfectly everywhere else in my project, so I am puzzled as ...

Altering the background color of :after while :before is being hovered over

Is it possible to modify the :after section when hovering over the :before part? Take a look at this image for reference: I want to alter the small triangle shape when the large square is being hovered over. The square uses the :before pseudo-element and ...

Changing the default date display in Vue.js

Is there a way to automatically set today's date as the default date on the datepicker? Here is the code snippet: <template lang="html"> <input type="date" v-model="date"> </template> <script lang="js"> export default { nam ...