简体   繁体   English

更好的CSS div对齐(3列,中大)

[英]A better css div align (3 columns, middle large)

I want the main text of the html (div.main) to be near standard paper size (8.5inch - 1in margin on both = 6.5) 我希望html(div.main)的主要文本接近标准纸张尺寸(8.5inch-1in margin on both 6.5)

I want my sidebar menu to be outside of this. 我希望我的侧边栏菜单不在此范围内。 So i figured out how to lock the page to near 1024 res (i use 996px so i have room for the vertical scroll bar) 所以我想出了如何将页面锁定到接近1024分辨率(我使用996px,所以我有足够的空间容纳垂直滚动条)

This looks fairly good at 1024 and 1280 width resolution but i am not sure about higher. 这在1024和1280宽度分辨率下看起来相当不错,但我不确定更高的分辨率。 Also maybe you guys have a suggestion how to better align this (keeping the 6.5in in the center) 另外也许你们有个建议如何更好地对齐它(将6.5英寸保持在中心)

index.html index.html

<div>
    <div class="menu">
    <ul>
    <li><a href="">Home</a></li>
    <li>Test</li>
    <li>Test 2</li>
    <li>Contact</li>
    </ul>
    </div>
</div>

<div class="row">
<div class="dummy">&nbsp;</div>

<div class="main">
lots of textlots of textlots of textlots of textlots of textlots of textlots of textlots of text
...
lots of textlots of textlots of textlots of textlots of textlots of textlots of textlots of text
</div>

<div class="sidebar">
Some links here</br>
<br>Some links here</br>
<br>Some links here</br>
<br>Some links here</br>
<br>Some links here</br>
</div>
</div>


</body>
</html>

my.css: my.css:

div.row
{
    width: 996px;
    margin-left: auto;
    margin-right: auto;
}

div.dummy {
    float: left;
    padding-right: 148px;
}

div.sidebar {
    float: left;
    padding-left: 32px;
}

div.main
{
    width: 6.5in;
    float: left;
}

.menu    { padding-bottom: 60px; }
.menu ul { margin:0px auto; }
.menu li {
    width: 22%;
    text-align:center;
    display:block;
    float:left;
    }
.menu a  { display:block; }

Pixels are variable width, completely dependent on the viewing device. 像素的宽度可变,完全取决于查看设备。 At extremes, for example, an iPhone is about 2 inches wide with 380px width. 例如,在极端情况下,iPhone的宽度约为2英寸,宽度为380px。 A typical 15" monitor is about 8 inches wide with 800px width. So an iPhone is about 4 times the resolution. 典型的15英寸显示器宽约8英寸,宽度为800px。因此,iPhone的分辨率约为4倍。

Furthermore, if you change the resolution of the same monitor - from 800x600 to 1024x768 - you now have more pixels in the same physical space. 此外,如果您将同一台显示器的分辨率从800x600更改为1024x768,现在在同一物理空间中将有更多像素。 This means that what showed as 7 inches before may now show as about 5 inches. 这意味着之前显示为7英寸的内容现在可能显示为大约5英寸。

The only way to get around that is to use pt s instead of px s. 解决该问题的唯一方法是使用pt而不是px 72pts is roughly 1 inch. 72点大约是1英寸。 I personally never use pt s, but have heard browsers are very inconsistent in their treatment of CSS that uses them. 我个人从未使用过pt ,但是听说浏览器在处理使用它们的CSS方面非常不一致。

To answer your specific question, therefore, you would need to use a fixed size overall on the page that is enough to contain your sidebar and your #main div. 因此,要回答您的特定问题,您将需要在页面上整体使用固定大小,该大小足以容纳侧边栏和#main div。 Float one to the left, and the other to the right. 一只漂浮在左边,另一只漂浮在右边。

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

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