简体   繁体   English

div填充整个屏幕-像素数

[英]div to fill the whole screen - number of pixels

I am currently working on a new website and I want to have a div ID to fit 100% of the screen, however I want to have something as a width of 250px to the right of this div. 我目前正在一个新的网站上工作,我想有一个div ID以适合屏幕的100%,但是我想在此div的右边设置250px的宽度。 I am trying to do width: 100% - 120px but doesn't seem to make any difference. 我试图做宽度:100%-120px,但似乎没有任何区别。 How can I do this. 我怎样才能做到这一点。

Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

If you want a div with 250px to the right, then you don't want the first div to be 100% of the screen. 如果您要在右侧使用250px的div,则不希望第一个div是屏幕的100%。 Set the second div width to 250px and the first div width to auto and it should fill the remaining space. 将第二个div宽度设置为250px,将第一个div宽度设置为auto,它将填充剩余的空间。

You can't subtract pixels from percentages, this isn't your answer, but I suggest learning the basics of css first, otherwise you will have no idea why things work the way they do. 您不能从百分比中减去像素,这不是您的答案,但是我建议您首先学习CSS的基础知识,否则您将不知道为什么事情会如此运作。

Here is a good website with a lot of layout examples and tutorials: http://www.maxdesign.com.au/articles/css-layouts/ 这是一个不错的网站,其中包含许多布局示例和教程: http : //www.maxdesign.com.au/articles/css-layouts/

And http://www.w3schools.com/ for css standards. 以及http://www.w3schools.com/以了解CSS标准。

As far as your particular situation is concerned, you are taking the wrong approach. 就您的特定情况而言,您使用的方法是错误的。 If you want to be able to subtract width from 100% you can use javascript to accomplish this goal. 如果您希望能够从100%中减去宽度,则可以使用javascript来实现此目标。 with jquery you can do something like this: 使用jQuery,您可以执行以下操作:

$("#div").width($(window).width() - 125);

This will not work once the window resizes however. 但是,一旦调整窗口大小,此功能将无法使用。 You can add resize events to resize your div when the window resizes but this is cumbersome and can seem laggy. 您可以添加调整大小事件以在窗口调整大小时调整div的大小,但这很麻烦并且看起来很麻烦。 Your best bet is to use a css implementation, your question is quite vague though, you seem to be describing a two column layout with a side panel, but I could be wrong. 最好的选择是使用css实现,但是您的问题很模糊,您似乎正在描述带有侧面板的两列布局,但是我可能错了。 Just for a two column layout there are different options such as whether you want your main content to be liquid or static. 仅对于两列布局,就有不同的选择,例如您希望主要内容是液态还是静态。

I'm assuming liquid because it is more useful. 我假设液体是因为它更有用。

I would like to recommend jquery layout for creating layouts. 我想推荐用于创建布局的jquery布局。 Uses javascript and it's very easy to use to make quick layouts. 使用javascript,非常易于使用,可以快速进行布局。 http://layout.jquery-dev.net/ http://layout.jquery-dev.net/

Here is your solution: http://jsfiddle.net/Z3nfv/1/ 这是您的解决方案: http : //jsfiddle.net/Z3nfv/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM