简体   繁体   English

图像 html 右侧的空白区域

[英]White space to the right of an image html

Why is there white space to the right of my image?为什么我的图像右侧有空白?

HTML file: HTML文件:

...
<body>
    <div class="image">
        <img src="image.jpg" alt="Picture here" id="image" align="middle"></img>
    </div>
</body>

Here's what it looks like:这是它的样子:

在此处输入图片说明

The image should just be the giraffe.图像应该只是长颈鹿。 Where is this white space coming from?这个空白从哪里来?

Not sure if you want the image full width or if the white bg color bothers you...不确定您是想要全宽图像还是白色背景色让您感到困扰...

Make sure your image div has a blue background确保您的图像 div 具有蓝色背景

.image {
    background-color: #4099FF;
}

or the parent that wraps your content and image.或包装您的内容和图像的父级。 in this case your body在这种情况下你的身体

body {
    background-color: #4099FF;
}

Its because your not filling the whole page your image is to small and you div is not full width这是因为你没有填满整个页面,你的图片很小,你的 div 不是全宽

div{
    width: 100%; // full width
}
img{
    height: auto;
    width: 100%
}

this will stretch to fill the whitespace这将拉伸以填充空白

Depends on what you are trying to do, if you want the image to stretch the full width, you could set width:100%, but this would likely result in a very badely pixelated image and I dont recommend this取决于您要尝试做什么,如果您希望图像拉伸整个宽度,您可以设置宽度:100%,但这可能会导致图像像素化非常严重,我不建议这样做

You may be better placing the image in a full width div, setting that div,s background color to blue and centering the image, or positioning it where you want it to be您可能最好将图像放在全宽 div 中,将该 div 的背景颜色设置为蓝色并使图像居中,或将其定位在您想要的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM