有没有办法在 CSS 中添加和减去值?
我有一个以负边距定位的 div,但我希望它一直延伸到其容器 div 的底部,这样我就可以使用不只是随机结束的边框。如果您查看 http://kineticaid.com/k/home.php 您就会明白什么我是说。我不能仅仅以像素为单位扩展其高度,因为容器 div 的高度会随页面动态变化。我想做的是这样的:
#rightcol {
float: right;
width: 225px;
height: 100% + 250px;
margin: -325px -25px 0 0;
}
基本上我问你是否可以在 CSS 中进行加法和减法。谢谢!
I have a div that I am positioning with a negative margin, but I'd like it to extend all the way down to the bottom of its container div so I can use a border that doesn't just end randomly. If you look at http://kineticaid.com/k/home.php you will understand what I mean. I can't just extend its height in pixels because the container div's height changes dynamically with pages. What I want to do is something like this:
#rightcol {
float: right;
width: 225px;
height: 100% + 250px;
margin: -325px -25px 0 0;
}
Basically I'm asking if you can add and subtract in CSS. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。 CSS3 具有 calc() 函数。这适用于大多数浏览器的当前版本 (http://caniuse.com/calc)。
演示:
HTML:
CSS:
输出:
Yes. CSS3 has the
calc()
function. This works in the current versions of most browsers (http://caniuse.com/calc).Demo:
HTML:
CSS:
Output:
Sass 和 less 也有你需要的类似功能,但我认为你所要求的必须用 javascript 或 jquery 来完成你的计算。
http://api.jquery.com/height/
Sass and less have similar such features too what you need, but I think what your asking for would have to be done with javascript or jquery to do your calculations.
http://api.jquery.com/height/
这个问题的解决方案是"Faux Columns",但是你需要稍微改变一下你的布局为了这。
The solution for this problem is "Faux Columns", but you need to change your layout a bit for this.