0

I have the following HTML code

<!DOCTYPE html>
<html>

    <head>
        <title> Test page </title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
    </head>

    <body>
        <header>
        </header>

        <div class="container">
            <img src="img1.jpg" class="thumb">
        </div>        
    
    </body>

</html>

And this is my CSS

* {
padding: 0;
margin: 0;
border:0;
vertical-align: baseline;
list-style: none;
box-sizing: border-box;
}

body {
    background-color: grey;
}

header{
    background-color: white;
    height: 60px;
    width: 100%;
}

.container{
    background-color: red;
    margin-left: 90px;
    margin-right: 90px;
}

.thumb{
    width: 400px;
}

My problem is that I can't understand why that little 2px border remains below the image, even with border: 0 and padding: 0.

border under the image

Sorry if this is on a very basic level for the forum, I'm starting the html course at my school and I can't solve this at all so I thought this would be the best place to ask someone.

3 Answers3

1

What you see is not a border, it's part of the background of container of the image. Image elements normally have display: inline-block, thus making it have extra spacing. To solve this, just add display: block to the image element.

* {
  padding: 0;
  margin: 0;
  border: 0;
  vertical-align: baseline;
  list-style: none;
  box-sizing: border-box;
}

body {
  background-color: grey;
}

header {
  background-color: white;
  height: 60px;
  width: 100%;
}

.container {
  background-color: red;
  margin-left: 90px;
  margin-right: 90px;
}

.thumb {
  width: 400px;
  display: block;
}
<header>
</header>

<div class="container">
  <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYGfvQfjM-b4ucRoLFd2s072tjc_BRaSugpw&usqp=CAU" class="thumb">
</div>
Damzaky
  • 6,073
  • 2
  • 11
  • 16
-1

I was able to add a set height to the .container of 400px, any fixed height should work. That seemed to fix it.

.container{
    height: 400px;
    background-color: red;
    margin-left: 90px;
    margin-right: 90px;
}

.thumb{
    width: 400px;
}
-1
.container {
background-color: red;
height: 192px;
margin-left: 90px;
margin-right: 90px;
}
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
  • But the height of .container cannot be fixed. In addition to knowing how to fix it, I wanted to know why this happens. – HtmlBeginner Sep 29 '22 at 04:11