HTML Remove Img Padding (display: block not working)

148 views Asked by At

How can I remove the padding from an . The style "display: block" (mentioned in many other solutions) doesn't seem to solve the problem.

<!DOCTYPE html>
<html>
<head>
    <style>
        img {
            display: block;
            width: 100%;
        }
    </style>
</head>
<body>
    <img src="https://imgur.com/CahbpxJ.jpg" width="100%">
</body>
</html>
2

There are 2 answers

2
Frank On BEST ANSWER

Answer from CBroe's comment. The body tag has its own default margin. To fix the problem add this in the style tag:

body {
    margin: 0;
}
1
batgerel.e On
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

*::after, *::before {
  box-sizing: inherit;
}