【问题标题】:Scale div elements to window size将 div 元素缩放到窗口大小
【发布时间】:2012-07-25 21:34:20
【问题描述】:

我目前正在为一个新的 Web 应用程序开发 skeleton layout,但遇到了一些问题,最明显的是 CSS 布局和 DIV。

1) 框 1 和 2(第 1 列)不与 3(第 2 列)和 4(第​​ 3 列)对齐。我该如何解决这个问题?

2) 我真的很喜欢here 界面,它在最小化到一定大小时自动调整大小,并在窗口最大化时放大。我一直试图在我的布局中实现这一点,但不能。不幸的是,页脚“突出”。我希望所有内容都适合一页。如何在上述网站中实现这一目标?

非常感谢。

HTML:

<!--  
============================================
LOGO
============================================
-->

<div id="wrapper">
    <div class="logo">logo</div>

<!--   
============================================
NAVBAR
============================================
-->   

<div id="header">
    <a href="#">link 1</a>
    &nbsp;|&nbsp;
    <a href="#">link 2</a>
    &nbsp;|&nbsp;
    <a href="#">link 3</a>
    &nbsp;|&nbsp;
    <a href="#">link 4</a>
</div>

  <div style="clear: both;"></div>

<!--  
============================================
NAVIGATION & CONTACTS
============================================
-->

<div class="column" id="first-column">
    <div class="window" id="window-1">1</div>
    <div class="window" id="window-2">2</div>
</div>

<!--   
============================================
MAIN CONTENT
============================================
-->

<div class="column" id="second-column">
    <div class="window" id="window-3">3</div>
</div>

<!--
============================================
CHAT
============================================
-->

<div class="column" id="third-column">
    <div class="window" id="window-4">4</div>
</div>

<!--  
============================================
FOOTER
============================================
-->

        <div style="clear: both;"></div>
        <div class="footer">footer</div>
</div>​

CSS:

/*
============================================
GENERAL
============================================
*/

body, html{
    font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
    height: 100%;
}

/*
============================================
LAYOUT SKELETON
============================================
*/

#wrapper {
    margin: 0 auto;
    max-width: 1212px;
    min-height: 540px;
    min-width: 784px;
    position: relative;
    height: 100%;
}

#header{
    text-align:right;
    padding:5px;
    font-size:10px;
    padding-right: 30px;
}

#first-column{
    width: 20%;
    padding-left: 5px;
    height: 100%;
}

#second-column{
    width: 50%;
    height: 100%;
}

#third-column{
    width: 25%;
}

.window{
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border:1px solid #CECECE;
    width:100%;
}

#window-1{
    height:50%;
}

#window-2{
    margin-top:10px;
    height:50%;
}

#window-3{
    height: 100%;
}

#window-4{
    height:100%;
}

.column{
    float:left;
    margin: 5px;
    height: 100%;
}

.logo {
    font-family: arial;
    font-size: 12px;
    float: left;
    padding-left: 10px;
}

.footer {
    margin-top: 10px;
    padding-left: 10px;
}

【问题讨论】:

  • 链接可能会过时,请在问题中也包含代码。

标签: css html


【解决方案1】:

1) 您在第 1 列中有 2 个 div,高度为 50%,因此有 2 组边距。您在第 2 列中有 1 个 div,因此只有 1 组边距,因此第 1 列自然会比您使用的边距更长。我能提供的最好的解决方法是在底部添加 10px 的填充。这应该赶上第一列的边距。

2) 添加最小和最大宽度,然后将宽度设置为 %。说最小 100 像素,最大 300 像素和 50% 宽度。只要屏幕是 200px 到 600px 宽,它将是 50%,否则它将处于指定的限制

【讨论】:

  • 感谢您的回复。你能在我的代码中包含一个例子吗? jsfiddle.net/methuselah/zRrxf
  • 我在工作,所以没有足够的时间为您修复 no2,也许稍后再说。但是对于数字 1,只需将 padding-bottom: 12px; 添加到 #window-3
  • 谢谢,我自己现在要去上班了。希望以后能赶上你。有空的时候我会等你的修改:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-30
  • 1970-01-01
相关资源
最近更新 更多