0

When we include an image in a web page with the following code

<html><body>
<img src="http://www.example.com/abc.jpg">
</body></html>

The browsers render it so that there is a margin of few pixels to the left and the top. I want the image to stick to the the left and top borders.

Help needed with that.

Thanks

4

3 回答 3

4

你有几个选择:

  1. 使用CSS 重置。简单的例子:

    * { padding: 0; margin: 0; }
    
  2. 用于“强制”将图像放置在您想要的任何位置(position: absolute;可以使用topright和.bottomleft

于 2012-12-07T09:05:26.780 回答
2

这些是身体的边缘。我总是在我的 css 文件中使用这种样式:

html, body { margin: 0px; padding: 0px; border: none; }

或者您可以在您的情况下内联编写它:

<body style="margin:0px; padding:0px;">

于 2012-12-07T09:25:24.367 回答
0

用 CSS 试试这个

<img src="http://www.example.com/abc.jpg" class="left-image">

html, body, img{
padding:0px;
margin:0px;
}

img.left-image{
 float:left; /* it may require if you have more elements in same container, not always */
 }

或者您可以随时定位,例如,如果您想要顶部 10px 和左侧 10px

img.left-image{
 position:absolute;
 left:10px;
 top:10px;
 }
于 2012-12-07T09:05:24.090 回答