CSS:给一个div一个数字的倍数的高度?
div 具有可平铺的背景。该 div 的高度取决于其内容。我需要将 div 拉伸背景图像大小的倍数。
例如,背景是 64x64 图像。 因此,如果要增加 div 的高度,我想以 64px 为步长进行增加。
这可以用 CSS 实现吗?我还没有使用谷歌找到线索。感谢您抽出时间!
A div has a tilable background. The height of this div will depend on its content. I need the div to stretch by a multiple of the background image's size.
For instance, the background is a 64x64 image.
So, if the div's height is to increase, I want to do so by steps of 64px.
Is this possible with CSS? I've not found leads using google. Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种解决方案(取决于您的具体情况)可能是使用新的
background-size
CSS 属性。为了清楚起见,我将声明分开:然后,无论
div
的大小如何,您的图像都会完美平铺而不会被切断。较旧的浏览器只会获取平铺图像,这可能是也可能不是问题。One solution (depending on your specific case) could be to use the new
background-size
CSS property. I've left the declarations separate for clarity:Then, whatever the size of you
div
, your image will tile perfectly without being cut off. Older browsers will just get the tiled image, which may or may not be an issue.据我所知,这不能在 CSS 中完成,但你可能可以用一些 javascript 来解决它。如果您有权访问 jQuery:
To my knowledge this cannot be done in CSS, but you could probably solve it with some javascript. If you have access to jQuery:
div的内容是什么?听起来不像将 div 的大小设置为正确的值,而是需要注意内容 - 这篇文章详细介绍了一些非常简单的技术来实现垂直节奏,这应该有效(即通过使用 64px 的行高)
What is the content of the div? It sounds like rather than setting the size of the div to the correct value, you need to pay attention to the content - this post details some pretty simple techniques to implement vertical rhythm, which should work (ie. by using a line height of 64px)