有没有办法在 CSS 中添加和减去值?

发布于 2024-12-22 18:52:35 字数 380 浏览 6 评论 0原文

我有一个以负边距定位的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无边思念无边月 2024-12-29 18:52:35

是的。 CSS3 具有 calc() 函数。这适用于大多数浏览器的当前版本 (http://caniuse.com/calc)。

height: calc( 100% + 250px );

演示: jsFiddle

HTML:

<div id="one"></div>
<div id="two"></div>

CSS:

div {
    border: 1px solid red;
    height: 100px;
}

#one {
    width: calc(50% + 20px);
}

#two {
    width: 50%;
}

输出:

在此处输入图像描述

Yes. CSS3 has the calc() function. This works in the current versions of most browsers (http://caniuse.com/calc).

height: calc( 100% + 250px );

Demo: jsFiddle

HTML:

<div id="one"></div>
<div id="two"></div>

CSS:

div {
    border: 1px solid red;
    height: 100px;
}

#one {
    width: calc(50% + 20px);
}

#two {
    width: 50%;
}

Output:

enter image description here

调妓 2024-12-29 18:52:35

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/

匿名的好友 2024-12-29 18:52:35

这个问题的解决方案是"Faux Columns",但是你需要稍微改变一下你的布局为了这。

The solution for this problem is "Faux Columns", but you need to change your layout a bit for this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文