Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

How to remove gaps?

shunels

New Coder
Hello guys,

i`m very new to html and css and i`m trying to create a website, but i cannot figure out how to remove the gaps between 1st and second row picture. I plan to have different type of picture sizes like in the example, but I would like them to "HUG" eachother.

Is there anyone who could help me with this?

I`m adding screenshot of what I mean, my html and css files. If anyone has any better solutions to that what i`m doing right now, please let me know, I will appreciate every help!

Thank you,
Raitis

Remove gaps.jpg
HTML

Code:
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Website Layout</title>
    <link rel="stylesheet" href="h3c.css">
</head>
<body>

<header>
    <div class="logo">Logo</div>
    <nav>
        <ul>
            <li><a href="#">Button 1</a></li>
            <li><a href="#">Button 2</a></li>
            <li><a href="#">Button 3</a></li>
        </ul>
    </nav>
    <div class="social-icons">
        <a href="#"><img src="twitter-icon.png" alt="Twitter"></a>
        <a href="#"><img src="facebook-icon.png" alt="Facebook"></a>
        <a href="#"><img src="instagram-icon.png" alt="Instagram"></a>
    </div>
</header>

<section class="strip">
    <div class="strip-content">
        <div>Text</div>
        <div>Text</div>
        <div>Text</div>
    </div>
</section>

<section class="image-gallery">
    <div class="image">
        <img src="https://via.placeholder.com/120x120" alt="Image 1">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/140x180" alt="Image 2">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/120x200" alt="Image 3">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x200" alt="Image 4">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/100x200" alt="Image 5">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x100" alt="Image 6">
    </div>
    <!-- Add more images with different sizes as needed -->
    <div class="image">
        <img src="https://via.placeholder.com/150x150" alt="Image 7">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/180x120" alt="Image 8">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/160x220" alt="Image 9">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/180x180" alt="Image 10">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/130x170" alt="Image 11">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/170x130" alt="Image 12">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/190x160" alt="Image 13">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/140x140" alt="Image 14">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x180" alt="Image 15">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/180x200" alt="Image 16">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/150x190" alt="Image 17">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/170x150" alt="Image 18">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/160x130" alt="Image 19">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x160" alt="Image 20">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/190x170" alt="Image 21">
    </div>
</section>

<footer>
    Footer text
</footer>

</body>
</html>





CSS

Code:
/* Reset default browser styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    line-height: 1.6;
}

header {
    background-color: #333;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
}

nav ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    display: flex;
}

nav ul li {
    margin-right: 10px;
}

nav ul li a {
    color: white;
    text-decoration: none;
    padding: 8px 12px;
    transition: background 0.3s;
}

nav ul li a:hover {
    background-color: #555;
}

.social-icons {
    display: flex;
}

.social-icons a {
    margin-left: 10px;
}

.strip {
    background-color: #ddd;
    padding: 20px 0;
    text-align: center;
}

.strip-content {
    display: flex;
    justify-content: space-around;
}

.image-gallery {
    max-width: 1200px;
    margin: 20px auto;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 10px;
}

.image-gallery img {
    width: 100%;
    display: block;
    border-radius: 5px;
}

footer {
    background-color: #333;
    color: white;
    text-align: center;
    padding: 20px 0;
}
 
Last edited:
Your grid setup is wrong.

grid-auto-rows: 1fr

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Website Layout</title>
    <link rel="stylesheet" href="h3c.css">
</head>
<body>

<header>
    <div class="logo">Logo</div>
    <nav>
        <ul>
            <li><a href="#">Button 1</a></li>
            <li><a href="#">Button 2</a></li>
            <li><a href="#">Button 3</a></li>
        </ul>
    </nav>
    <div class="social-icons">
        <a href="#"><img src="twitter-icon.png" alt="Twitter"></a>
        <a href="#"><img src="facebook-icon.png" alt="Facebook"></a>
        <a href="#"><img src="instagram-icon.png" alt="Instagram"></a>
    </div>
</header>

<section class="strip">
    <div class="strip-content">
        <div>Text</div>
        <div>Text</div>
        <div>Text</div>
    </div>
</section>

<section class="image-gallery">
    <div class="image">
        <img src="https://via.placeholder.com/120x120" alt="Image 1">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/140x180" alt="Image 2">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/120x200" alt="Image 3">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x200" alt="Image 4">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/100x200" alt="Image 5">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x100" alt="Image 6">
    </div>
    <!-- Add more images with different sizes as needed -->
    <div class="image">
        <img src="https://via.placeholder.com/150x150" alt="Image 7">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/180x120" alt="Image 8">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/160x220" alt="Image 9">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/180x180" alt="Image 10">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/130x170" alt="Image 11">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/170x130" alt="Image 12">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/190x160" alt="Image 13">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/140x140" alt="Image 14">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x180" alt="Image 15">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/180x200" alt="Image 16">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/150x190" alt="Image 17">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/170x150" alt="Image 18">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/160x130" alt="Image 19">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/200x160" alt="Image 20">
    </div>
    <div class="image">
        <img src="https://via.placeholder.com/190x170" alt="Image 21">
    </div>
</section>

<footer>
    Footer text
</footer>

</body>
</html>

CSS:
/* Reset default browser styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    line-height: 1.6;
}

header {
    background-color: #333;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
}

nav ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    display: flex;
}

nav ul li {
    margin-right: 10px;
}

nav ul li a {
    color: white;
    text-decoration: none;
    padding: 8px 12px;
    transition: background 0.3s;
}

nav ul li a:hover {
    background-color: #555;
}

.social-icons {
    display: flex;
}

.social-icons a {
    margin-left: 10px;
}

.strip {
    background-color: #ddd;
    padding: 20px 0;
    text-align: center;
}

.strip-content {
    display: flex;
    justify-content: space-around;
}
/* Edit grid code */
.image-gallery {
    max-width: 1200px;
    margin: 20px auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    grid-auto-rows: 1fr;
    gap: 0;
}

.image {
    overflow: hidden;
}

.image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 0;
}

footer {
    background-color: #333;
    color: white;
    text-align: center;
    padding: 20px 0;
}
 
Thank you for your reply,

Now I have this

Untitled.jpg

Which is also not what I was imagining. Let me try to share what I have in my mind.

So basically I want to have 7 pictures in a row and lets say 4 columns, but the pictures will have different sizes, I want them to be like a mixed (hugging), like in the picture below.

Do you know a way to do it?

likethis.jpg
 
Try this:

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mixed Size Image Gallery</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="gallery">
        <img src="image1.jpg" alt="Image 1" class="large">
        <img src="image2.jpg" alt="Image 2" class="medium">
        <img src="image3.jpg" alt="Image 3" class="small">
        <img src="image4.jpg" alt="Image 4" class="large">
        <img src="image5.jpg" alt="Image 5" class="medium">
        <img src="image6.jpg" alt="Image 6" class="small">
        <img src="image7.jpg" alt="Image 7" class="large">
    </div>
</body>
</html>

CSS:
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 10px;
    padding: 10px;
}

.gallery img {
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 5px;
}

.gallery img.large {
    grid-column: span 2;
    grid-row: span 2;
}

.gallery img.medium {
    grid-column: span 2;
    grid-row: span 1;
}

.gallery img.small {
    grid-column: span 1;
    grid-row: span 1;
}

As for the images their different sizes:

HTML:
<img src="https://via.placeholder.com/400" alt="Image 1" class="large">
<img src="https://via.placeholder.com/200" alt="Image 2" class="medium">
<img src="https://via.placeholder.com/100" alt="Image 3" class="small">

Let me know if that worked.
 
You can try incorporating one of the following:

grid-auto-flow: dense;
grid-auto-flow: row dense;
grid-auto-flow: column dense;

HOWEVER, tab order will be wrong visually, if that matters in your case.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom