开发者

Making webpage fit to screen resolution

开发者 https://www.devze.com 2023-03-06 16:24 出处:网络
I have a web page with the following content.. <div id=\"container\"> <div id=\"header\"></div>

I have a web page with the following content..

<div id="container">
  <div id="header"></div>
  <div id="lsidebar"> 
  </div>
  <div id="content">
  </div>
  <div id="rsidebar">
  </div>
</div>

i need a container to be centered always on the screen.

Making webpage fit to screen resolution

the container width would be the half of the screen.i use margin-left for centering the container.But it is different for different browser.

Another problem:i am adding float:left for lbar,content,rbar.but the rbar is moving to next line like this...

Making webpage fit to screen resolution

Here is my css

#container
{
        position:absolute;
    width:75%;
    left:15%;



}
#header{width:100%;height:430px;}
#content开发者_StackOverflow社区{position:relative;top:0px;width:60%;}
#rsidebar{border:2px solid black;width:100px;height:200px;float:left;}
#footer{position:relative;top:10px;width:100%;}

how to solve this issue...


the container width would be the half of the screen.i use margin-left for centering the container.

Sorry?

If the container is half of the screen, you'll have a width:50%. If you want to center it, you'll have margin:0 auto;.

There are only two appropriate techniques to center items on a page: text-align:center; for content, margin:0 auto; for blocks. You may be tempted to do something like margin-left:25%;width:50%;, but it will probably not give the expected results in all browsers and cause too many problems, so try to stick with the techniques that everybody uses for years, unless you can prove that your technique is much better.

Another problem:i am adding float:left for lbar,content,rbar.but the rbar is moving to next line

Probably the outer width of three panels is bigger than the width of the container. Note that we're talking about the outer width, not the width itself. For example if the container element is 1067 pixels width and contains two panels of 200 pixels and one panel of 600 pixels, with 50 pixels margin between, the actual width of three panels will be 200×2 + 600 = 1000, but the outer width will be 1000 + 50×2 = 1100, i.e. greater than 1067 pixels.

To avoid problems with the widths of the panels, especially in the case where your container has a variable width depending on the size of the window, you can float-left the left panel, float-right the right one and keep the central panel to fill the remaining space. This may not always be possible depending on your layout and design. If this is a case, it would be great to see the actual source code in your question to be able to give a more specific answer.


Seing your source code, I don't understand why are you using position:absolute and position:relative for nearly every element. What's the point?

1. Aligning the container

To align the container, you have to specify not only the width, but also the margins.

div#container{margin:0 auto;width:50%;}

2. Float-lefting the panels

Now that you have your container filling the half of the space and centered, let's position the panels.

Your right panel has a width of 100 pixels. I suppose that your left panel has the same width.

div#lbar,
div#rbar{width:100px;}

Let's float-left and float-right them:

div#lbar,
div#rbar{width:100px;float:left;} /* Apply this style to both side panels */
div#rbar{float:right;} /* Override the float:left of the preceding line */

Now, we want the central panel to avoid filling the space already filled by two other panels:

div#content{margin:0 100px;}

That's pretty all you need to do.


I may also suggest you to read some books about HTML/CSS. Looking at your code, I might suppose that you're not very familiar with it, and that some reading may improve both your understanding of both languages and your skills.


first: give the container a width and

margin-left auto; margin-right:auto;

do you use a meyerweb reset stylesheet?


The combined width of you lbar + content + rbar + margins+ padding is probably more than the space in your container; therefore your rbar moves to the bottom.

ALso use the container solution of Daniel


You can use margin: auto to center container horizontally. About sidebars you probably want lbar, rbar, content in markup and float: left, float: right for lbar and rbar respectively. Remember to put clear: both on footer just in case.


You can also use HTML5 or something like http://lessframework.com to specify conditions for different screen sizes.

0

精彩评论

暂无评论...
验证码 换一张
取 消