jQuery 或数学使用宽度百分比减去 div 的像素 - jSfiddle
http://jsfiddle.net/motocomdigital/7fyvn/1/
您好,这是一个问题我真的很难找到答案。
它不一定是 jQuery,它可能是一些简单的 css。
我在这里创建了jSfiddle,以便您可以自己进行实验。
我的情况是我有一个可变宽度容器,在小提琴中称为 div#container
。
在这个容器内,我有两列。列宽由百分比确定。
目前,我使用附加的 .left
& ,左侧宽度为 65%,右侧宽度为 35%。 .right
类。
即使我在 .column
类上使用 width: 50%
,我也会遇到同样的问题。
我的问题是,我的两列之间需要 10 像素的边距。目前我的列宽度总计为 100%,以填充整个白框。
如果我向左列添加 10px padding-right。然后布局就会中断,添加 margin-right 也会发生同样的情况。
我的问题是,如何使用 jQuery 或 javascript 从每个列宽度中减去 5px?同时仍然保留我的宽度百分比?
这在某种程度上是可能的还是我在做梦。 javascript数学可以吗?我可以设想,但我想不出从哪里开始,或者什么方法最安全、最轻便。
它将在手机浏览器上使用,因此当方向从横向翻转为纵向时,javascript 减法需要保持真实,同时允许调整百分比宽度。
希望这是有道理的,请随时向我询问更多信息。
更新解决方案
请参阅此处仅使用 css 和额外的 div 解决的小提琴... http:// /jsfiddle.net/7fyvn/4/
您可以调整窗口大小,装订线始终保持不变,距左栏 -20px。请参阅类 .new-div
和 .text-padding
http://jsfiddle.net/motocomdigital/7fyvn/1/
Hello, this is a question I'm really struggling to find an answer for.
It may not be necessarily jQuery, it my be a simple bit of css.
I have created jSfiddle here so you can experiment for yourself.
My circumstance is that I have a variable width container, called div#container
in fiddle.
And inside this container, I have 2 columns. The column widths are determined by percentage.
Currently I have the left width at 65% and right at 35%, using additional .left
& .right
classes.
I would have the same problem even if I was using width: 50%
on my .column
class.
My problem, is that I need a 10px margin between my 2 columns. Currently my column widths add up to a total of 100%, to fill the entire white box.
If I add 10px padding-right to my left column. Then the layout breaks, and the same happens with adding margin-right.
My question is, how can I subtract 5px from each of the column widths using jQuery or javascript? Whilst still keeping the percentage for my widths?
Is this possible in some way or am I dreaming. Is it possible with javascript math? I can envisage it, but I can't think where to start, or what method is the safest and lightest.
It will be used on phone browsers, so when the orientation flips from landscape to portrait, the javascript subtraction needs to stay true whilst allowing the percentage widths to adjust.
Hope this makes sense, don't hesitate to ask me for more info.
UPDATE SOLUTION
See solved fiddle here just using css and an extra div... http://jsfiddle.net/7fyvn/4/
You can adjust the window size and gutter always stays the same, -20px off the left column. See classes .new-div
and .text-padding
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能的方法是添加:
One possible way would be to add: