购买网站开发服务费入账,重庆万州网站建设公司电话,手机app页面设计,salutation wordpress我有body {background: url(images/background.svg);}期望的效果是该背景图像的宽度等于页面的宽度#xff0c;高度变化以保持比例。 例如 如果原始图像恰好是100 * 200(任何单位)且正文宽度为600px#xff0c;则背景图像最终应为1200px高。 如果调整窗口大小#xff0c;高度…我有body {background: url(images/background.svg);}期望的效果是该背景图像的宽度等于页面的宽度高度变化以保持比例。 例如 如果原始图像恰好是100 * 200(任何单位)且正文宽度为600px则背景图像最终应为1200px高。 如果调整窗口大小高度应自动更改。 这可能吗目前Firefox看起来正在调整高度然后调整宽度。 这可能是因为高度是最长的尺寸而且它试图避免裁剪 我想垂直裁剪然后滚动没有水平重复。此外即使明确指定background-repeat:repeatChrome也会将图像置于中心位置不会重复无论如何都是默认值。html, body { height: 100%; }有帮助吗 还有咳嗽。这有一个CSS3属性即background-size(兼容性检查)。虽然可以设置长度值但它通常与特殊值contain和cover一起使用。在您的特定情况下您应该使用coverbody {background-image: url(images/background.svg);background-size: cover; /* background-repeat: no-repeat;background-position: center center; /* optional, center the image */}eggplanation为contain和cover对不起的双关语感到抱歉但我将使用Biswarup Ganguly当天的照片进行演示。让我们说这是你的屏幕灰色区域在你的可见屏幕之外。为了演示我将假设一个16x9的比例。我们想用上面提到的图片作为背景。但是出于某种原因我们将图像裁剪为4x3。我们可以将background-size属性设置为某个固定长度但我们将关注contain和cover。请注意我还假设我们没有破坏body的宽度和/或高度。containcontainScale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.这样可以确保背景图像始终完全包含在背景定位区域中但是在这种情况下可能会有一些空白空间填充background-colorcovercoverScale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.这可以确保背景图像覆盖所有内容。没有可见的background-color但是根据屏幕的比例图像的很大一部分可能会被切断用实际代码演示div div {background-image: url(http://i.stack.imgur.com/r5CAq.jpg);background-repeat: no-repeat;background-position: center center;background-color: #ccc;border: 1px solid;width: 20em;height: 10em;}div.contain {background-size: contain;}div.cover {background-size: cover;}/********************************************Additional styles for the explanation boxes*********************************************/div div {margin: 0 1ex 1ex 0;float: left;}div div {clear: both;border-top: 1px dashed silver;padding-top:1ex;}div div::after {background-color: #000;color: #fefefe;margin: 1ex;padding: 1ex;opacity: 0.8;display: block;width: 10ex;font-size: 0.7em;content: attr(class);}Note the grey background. The image does not cover the whole region, but its fully contained.Note the ducks/geese at the bottom of the image. Most of the water is cut, as well as a part of the sky. You dont see the complete image anymore, but neither do you see any background color; the image covers all of the .这正是我想要的谢谢。它似乎不适用于Chrome(或至少Chromium) - 有任何好主意吗根据quirksmode.org/css/contents.html#t44它应该在Chrome中工作没有任何前缀。但是您尝试过-webkit-前缀吗Yauhen的答案(在本页底部)实际上是我在寻找的background-size: containDannyBeckett虽然这是可能的但它不是OP想要的我想垂直裁剪然后滚动没有水平重复。DannyBeckett新版本现在应涵盖所有相关问题。毕竟我之前的回答是相当微小的。contain就像缩放适合。 cover就像缩放填充。 contain调整图像大小以匹配宽度和高度之间的较大尺寸。 cover调整图像大小以匹配宽度和高度之间的较小尺寸。Zeta抱歉我的错误我混淆了两个边框蓝色和红色边框。基于来自https://developer.mozilla.org/en-US/docs/CSS/background-size的提示我最终得到了以下对我有用的配方body {overflow-y: hidden ! important;overflow-x: hidden ! important;background-color: #f8f8f8;background-image: url(index.png);/*background-size: cover;*/background-size: contain;background-repeat: no-repeat;background-position: right;}虽然我使用background-position: center;但这对我来说比backgound-size: cover;更好。我可以知道为什么我们需要overflow-y: hidden部分吗我不确定你到底在寻找什么但是你真的应该看看Chris Coyier写的CSS-Tricks的这些优秀博客文章阅读每篇文章的描述看看它们是否符合您的要求。第一个回答了以下问题Is there a way to make a background image resizeable? As in, fill the background of a web page edge-to-edge with an image, no matter the size of the browser window. Also, have it resize larger or smaller as the browser window changes. Also, make sure it retains its ratio (doesnt stretch weird). Also, doesnt cause scrollbars, just cuts off vertically if it needs to. Also, comes in on the page as an inline tag.第二篇文章的目标是获得以下内容网站上的背景图像始终覆盖整个浏览器窗口。希望这可以帮助。试试这个element.style {background: rgba(0, 0, 0, 0) url(img/shopping_bgImg.jpg) no-repeat scroll center center / cover;}背景图像不是设置完美然后他的CSS是问题创建所以他的CSS文件更改为下面的代码html {background-image: url(example.png);background-repeat: no-repeat;background-position: 0% 0%;background-size: 100% 100%;}; background-size100100;只需添加以下一行.your-class {height: 100vh;}vh是视口高度。这将自动缩放以适合设备的浏览器窗口。在这里查看更多使div为浏览器窗口的100高度body{background-image: url(../url/imageName.jpg);background-attachment: fixed;background-size: auto 100%;background-position: center;}描述问题究竟是什么以及如何解决它请不要在没有解释的情况下粘贴一堆代码。我遇到了同样的问题在调整浏览器尺寸时无法调整图像大小。坏代码html {background-color: white;background-image: url(example.png);background-repeat: no-repeat;background-attachment: scroll;background-position: 0% 0%;}好代码html {background-color: white;background-image: url(example.png);background-repeat: no-repeat;background-attachment: scroll;background-position: 0% 0%;background-size: contain;}这里的关键是添加这个元素 - background-sizecontains;这对我有用background-size: auto 100%;设置背景大小没有帮助以下解决方案对我有用.class {background-image: url(blablabla.jpg);/* Add this */height: auto;}它基本上会裁剪图像并使其适合background-size: contain/cover仍然不适合。