2012-11-16 35 views
1

我正在尝试学习响应式设计。我正在建立一个网站,其中一个网页是一个投资组合。我建立了以下如何布置此页面的模型。这当然是一个非常简洁的版本。我似乎无法应用正确的查询,因此这种格式在宽屏桌面,ipad上可以显示,并且可以说一部手机。我开始了第一个查询,但它当然不工作,也知道这是否是常见宽屏桌面的最佳尺寸。卡住此布局上媒体查询的最佳方法

任何人都可以让我开始如何应用这个页面?我将继续教程,但需要在这里启动一个开始。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<meta name="viewport" content="width=device-width; initial-scale=1.0"> 
<style type="text/css"> 
@media screen and (max-width:1080px) { 
    #main { 
     width: 960px; 
    } 
} 
body { 
    background-color: #FFF; 
    margin:0; 
} 

#main { 
    width: 1080px; 
    margin-right: auto; 
    margin-left: auto; 
    height: 860px; 
    margin-top: 20px; 
    margin-bottom: 20px; 
} 
.box { 
    background-color: #CCC; 
    height: 200px; 
    width: 200px; 
    margin-right: 20px; 
    float: left; 
    margin-bottom: 20px; 
} 
.box_last { 
    background-color: #CCC; 
    height: 200px; 
    width: 200px; 
    float: left; 
    margin-bottom:20px; 
} 
.box_bottom { 
    background-color: #CCC; 
    height: 200px; 
    width: 200px; 
    margin-right: 20px; 
    float: left; 

} 
.box_last_bottom { 
     background-color: #CCC; 
    height: 200px; 
    width: 200px; 
    float: left; 

} 
</style> 
</head> 

<body> 
<div id="main"> 
    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box_last"></div> 

    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box_last"></div> 

    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box"></div> 
    <div class="box_last"></div> 

    <div class="box_bottom"></div> 
    <div class="box_bottom"></div> 
    <div class="box_bottom"></div> 
    <div class="box_bottom"></div> 
    <div class="box_last_bottom"></div> 
</div> 
</body> 
</html> 
+0

我觉得共同在外面使用负利润最DIV,使内div可以有正边距(让它们之间有间距),但是没有空间用于第一个/最后一个元素。如果你愿意,我可以更好地解释。 – Kubee

回答

1

在您当前的代码中,来自媒体查询块的#main正在被覆盖。你必须把你的媒体查询你的CSS

#main { 
    width: 1080px; 
    ... 
} 

@media screen and (max-width:1080px) { 
    #main { 
     width: 960px; 
    } 

    .box { 
     width: 200px; 
     ... 
    } 
} 

的最底部,然后一个小屏幕

@media screen and (max-width: 480px) { 
    #main { 
     width: 100%; 
    } 

    .box { 
     width: 50%; 
     ... 
    } 
} 
+0

非常感谢您的答复。我已经应用了代码但仍然没有任何反应? – DC1

+0

我已经设置了一个快速小提琴 - http://jsfiddle.net/Aw2yG/只是调整渲染的输出窗口,看看如何更改框 –

+0

谢谢sooo多!我真的很感谢你的帮助。看起来我错过了在样式下移动媒体查询的一步。嘿,我只是在你的个人资料中看到你的网站我将通过电子邮件通知您可能的开发工作。再次感谢! – DC1