Stretch an image to fill width of browser window

前端 未结 5 2058
谎友^
谎友^ 2021-02-08 12:11

I have an image, and I want the width to fill up the browser window, no matter the size of the window.

How do I do this in HTML and CSS?

5条回答
  •  半阙折子戏
    2021-02-08 12:35

    The margin of the body element is set to a default of 8px, which is the space you are seeing which prevent the image to stretch the full width and height of the screen.

    You can include

    body {margin: 0px;}
    

    to prevent this behavior, which I guess was put in place to prevent unstyled pages to present the content pushing to the edge of the page. It was discussed here.

提交回复
热议问题