Home > Software design >  CSS Gaps between images when those are placed in Flexbox
CSS Gaps between images when those are placed in Flexbox

Time:06-05

I am trying to learn CSS. I want to write approximation of tesla.com website.

  1. I have placed all the images in the flexbox (each image is in separate div)
  2. I want to remove gaps between those images.
  3. I have checked multiple post here in stackoverflow.
  4. I have also googled the question but no relevant answer has come up.

Please advice if you can.

Code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Electric Cars, Solar & Clean Energy</title>
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="normalize.css">
    <style>
        body {
 
            margin: 0;
            border: 0;
            padding: 0;
        }
        p {
            text-decoration: underline;
            text-align: center;
            font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        }
        .container {
            display: flex;
            gap: 0%;
            margin-right:0 !important;
        }
        .item {
            flex-grow: 1;
            height: 100%;
            margin: 0;
            padding: 0;
            margin-right:0 !important;
        }
        .item img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <p div="impact_report">Read Tesla's 2021 Impact Report</p>
    <div >
        <div >
            <img src="M3-Homepage-Desktop-LHD.jpeg" />
        </div>
        <div >
            <img src="Desktop-ModelY.jpeg" />
        </div>
        <div >
            <img src="Homepage-Model-X-Desktop-LHD.jpeg" />
        </div>
        <div >
            <img src="_25-HP-SolarPanels-D.jpeg" />
        </div>
        <div >
            <img src="HP-SR-Design-D.jpeg" />
        </div>
        <div >
            <img src="dd739764-bcaa-4263-9488-8c73bc9fb046.jpeg" />
        </div>
    </div>
</body>
</html>

CodePudding user response:

You mean like this?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Electric Cars, Solar & Clean Energy</title>
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="normalize.css">
    <style>
        body {
 
            margin: 0;
            border: 0;
            padding: 0;
        }
        p {
            text-decoration: underline;
            text-align: center;
            font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        }
        .container {
            display: flex;
            margin-right:0 !important;
            grid-gap: 0;
        }
        .item {
            
            height: 100%;
            margin: 0;
            padding: 0;
            margin-right:0 !important;
        }
        .item img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <p div="impact_report">Read Tesla's 2021 Impact Report</p>
    <div >
        <div >
            <img src="M3-Homepage-Desktop-LHD.jpeg" />
        </div>
        <div >
            <img src="Desktop-ModelY.jpeg" />
        </div>
        <div >
            <img src="Homepage-Model-X-Desktop-LHD.jpeg" />
        </div>
        <div >
            <img src="_25-HP-SolarPanels-D.jpeg" />
        </div>
        <div >
            <img src="HP-SR-Design-D.jpeg" />
        </div>
        <div >
            <img src="dd739764-bcaa-4263-9488-8c73bc9fb046.jpeg" />
        </div>
    </div>
</body>
</html>

CodePudding user response:

You mean something like this?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Electric Cars, Solar & Clean Energy</title>
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="normalize.css">
    <style>
        body {
 
            margin: 0;
            border: 0;
            padding: 0;
        }
        p {
            text-decoration: underline;
            text-align: center;
            font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        }
        .container {
            display: flex;
            margin-right:0 !important;
            grid-gap: 0;
        }
        .item {
            
            height: 100%;
            margin: 0;
            padding: 0;
            margin-right:0 !important;
        }
        .item img {
            width: 100%;
            height: 100%;
            max-width:300px;
            max-height: 300px;
            object-fit: cover;
        }
    </style>
</head>
<body>
    <p div="impact_report">Read Tesla's 2021 Impact Report</p>
    <div >
        <div >
            <img src="https://www.cameraegg.org/wp-content/uploads/2013/02/Leica-M-Sample-Image.jpg" />
        </div>
        <div >
            <img src="https://www.cameraegg.org/wp-content/uploads/2013/02/Leica-M-Sample-Image.jpg" />
        </div>
        <div >
            <img src="https://www.cameraegg.org/wp-content/uploads/2013/02/Leica-M-Sample-Image.jpg" />
        </div>
        <div >
            <img src="https://www.cameraegg.org/wp-content/uploads/2013/02/Leica-M-Sample-Image.jpg" />
        </div>
        <div >
            <img src="https://www.cameraegg.org/wp-content/uploads/2013/02/Leica-M-Sample-Image.jpg" />
        </div>
        <div >
            <img src="https://www.cameraegg.org/wp-content/uploads/2013/02/Leica-M-Sample-Image.jpg" />
        </div>
    </div>
</body>
</html>

  • Related