Home > Net >  Bottom border not disappearing even with border: 0 and padding: 0
Bottom border not disappearing even with border: 0 and padding: 0

Time:09-29

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 >
            <img src="img1.jpg" >
        </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.

CodePudding user response:

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 >
  <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYGfvQfjM-b4ucRoLFd2s072tjc_BRaSugpw&usqp=CAU" >
</div>

CodePudding user response:

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;
}

CodePudding user response:

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

}

  • Related