-2

i want the text be right under the image without white space .. i also tried 0 margin and 0 padding but didn't work .. should i make a another div for the span ? i also tried the overflow hidden :(

also there's no padding in the body tag and the (*) i wonder if its caused by the display:block or display flex ..

* {
    outline: 0px;
    box-sizing: border-box;
    position: relative;
    padding: 0;
    margin: 0;
}
body {
    background-color: #1b191b;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #232223;
    width: 100%;
    height: 65px;
    z-index: 9999;
    box-shadow: 0 0 20px #00000094;
}

.header-links ul li a {
    text-decoration: none;
}

.header-links ul li {
    display: inline;
    margin-right: 50px;
}

.header-logo {
    padding: 20px;
    margin-left: 50px;
}

.search-bar {
    padding: 20px;
    margin-right: 50px;
} 

.container {
    width: 93%;
    max-width: 1600px;
    margin: 0 auto;
}

div.item {
    vertical-align: top;
    display: inline-block;
    text-align: center;
    width: 270px;
    margin: 0 12px 30px;
}
img {
    padding: 0;
    width: 100%;
    height: 100%;
    border-top-left-radius: 3%;
    border-top-right-radius: 3%;
}
.caption {
    padding: 0;
    display: block;
    background-color: #232223;
    border-bottom-left-radius: 10%;
    border-bottom-right-radius: 10%;
}
<!DOCTYPE html>
<html dir="rtl" lang="ar">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Header</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <header>
            <div class="header-logo">ON ANIME</div>
            <div class="header-links">
                <ul>
                    <li><a href="#">url</a></li>
                    <li><a href="#">url</a></li>
                    <li><a href="#">url</a></li>
                </ul>
            </div>
            <div class="search-bar"><button>Buy now</button></div>
        </header>

        <div class="container">
            <div class="item">
                <img src="https://fr.techtribune.net/wp-content/uploads/2021/01/boruto-chapter-55.jpg"/>
                <span class="caption">Text below the image</span>
            </div>
        </div>
        
          
        
        <script src="" async defer></script>
    </body>
</html>
ZUPPA LOL
  • 3
  • 2

1 Answers1

1

By default, images are inline elements. As such they follow the inline baseline rule and also have a decender (space for letters like g, j, y, p). To remove the inline decender space you have to set it as a block level element:

img { display: block; }:

This will remove the inline decender space and as such the enxt element will attach to it right below it.

* {
  outline: 0px;
  box-sizing: border-box;
  position: relative;
  padding: 0;
  margin: 0;
}

body {
  background-color: #1b191b;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #232223;
  width: 100%;
  height: 65px;
  z-index: 9999;
  box-shadow: 0 0 20px #00000094;
}

.header-links ul li a {
  text-decoration: none;
}

.header-links ul li {
  display: inline;
  margin-right: 50px;
}

.header-logo {
  padding: 20px;
  margin-left: 50px;
}

.search-bar {
  padding: 20px;
  margin-right: 50px;
}

.container {
  width: 93%;
  max-width: 1600px;
  margin: 0 auto;
}

div.item {
  vertical-align: top;
  display: inline-block;
  text-align: center;
  width: 270px;
  margin: 0 12px 30px;
}

img {
  display: block;
  width: 100%;
  height: 100%;
  border-top-left-radius: 3%;
  border-top-right-radius: 3%;
}

.caption {
  padding: 0;
  display: block;
  background-color: #232223;
  border-bottom-left-radius: 10%;
  border-bottom-right-radius: 10%;
}
<!DOCTYPE html>
<html dir="rtl" lang="ar">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Header</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <header>
    <div class="header-logo">ON ANIME</div>
    <div class="header-links">
      <ul>
        <li><a href="#">url</a></li>
        <li><a href="#">url</a></li>
        <li><a href="#">url</a></li>
      </ul>
    </div>
    <div class="search-bar"><button>Buy now</button></div>
  </header>

  <div class="container">
    <div class="item">
      <img src="https://fr.techtribune.net/wp-content/uploads/2021/01/boruto-chapter-55.jpg" />
      <span class="caption">Text below the image</span>
    </div>
  </div>



  <script src="" async defer></script>
</body>

</html>
tacoshy
  • 10,642
  • 5
  • 17
  • 34