2017-04-15 124 views
0

这是我第一次来这里。一位朋友认为这是一个很好的知识来源,我迫切需要这一点!我在哪里出错了这个流体网格布局?

我正在尝试使用视口,媒体查询和流体网格编写HTML和CSS,以创建一个从桌面(desktop example)到移动(mobile example)的缩放页面。

我试图在w3c网站的帮助下将它拼凑在一起,但是没有特别帮助的人说我在那里有bootstrap(我不打算使用它,并且希望它被取出但我有不知道它是什么)。

我设法实现的是让手机尺寸工作,但由于某些原因,应该是桌面行宽度的50%和25%的框的颜色区域不会拉伸为他们应该。

我做错了什么?帮助将是最多,最感谢!

这是我写的HTML:

And this is the CSS: @charset "utf-8"; 
 

 
/* CSS Document */ 
 

 
* { 
 
    box-sizing: border-box; 
 
} 
 

 
.row::after { 
 
    content: ""; 
 
    clear: both; 
 
    display: table; 
 
} 
 

 
[class*="col-"] { 
 
    float: left; 
 
    padding: 8px; 
 
    border: thin rgba(0, 0, 0, 1.00); 
 
} 
 

 
.col-1 { 
 
    width: 8.33%; 
 
} 
 

 
.col-2 { 
 
    width: 16.66%; 
 
} 
 

 
.col-3 { 
 
    width: 25%; 
 
} 
 

 
.col-4 { 
 
    width: 33.33%; 
 
} 
 

 
.col-5 { 
 
    width: 41.66%; 
 
} 
 

 
.col-6 { 
 
    width: 50%; 
 
} 
 

 
.col-7 { 
 
    width: 58.33%; 
 
} 
 

 
.col-8 { 
 
    width: 66.66%; 
 
} 
 

 
.col-9 { 
 
    width: 75%; 
 
} 
 

 
.col-10 { 
 
    width: 83.33%; 
 
} 
 

 
.col-11 { 
 
    width: 91.66%; 
 
} 
 

 
.col-12 { 
 
    width: 100%; 
 
} 
 

 
html { 
 
    font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, "serif"; 
 
} 
 

 
.navspot { 
 
    width: 100%; 
 
    max-width: 100%; 
 
    padding: 10px; 
 
    height: auto; 
 
    vertical-align: middle; 
 
    background: #d9cf91; 
 
    text-align: right; 
 
} 
 

 
.maincontent { 
 
    /*properties for cell*/ 
 
    /*Nothing is required here 
 
    because we can use default styles*/ 
 
    background: #30332c; 
 
    color: #FFFFFF; 
 
    padding: 10px; 
 
} 
 

 
.box1 { 
 
    background-color: #dfcf91; 
 
    color: #FFFFFF; 
 
    padding: 10px; 
 
    text-align: left; 
 
    float: left; 
 
} 
 

 
.box2 { 
 
    background-color: rgba(107, 35, 36, 1.00); 
 
    color: #FFFFFF; 
 
    text-align: center; 
 
    padding: 10px; 
 
    float: left; 
 
} 
 

 
.box3 { 
 
    background-color: #8D9981; 
 
    text-align: center; 
 
    padding: 10px; 
 
    float: left; 
 
} 
 

 
.box4 { 
 
    background-color: #606956; 
 
    text-align: center; 
 
    padding: 10px; 
 
    float: left; 
 
} 
 

 
.box5 { 
 
    background-color: #8D9981; 
 
    text-align: center; 
 
    padding: 10px; 
 
    float: left; 
 
} 
 

 
.box6 { 
 
    background-color: #606956; 
 
    text-align: center; 
 
    padding: 10px; 
 
    float: left; 
 
} 
 

 
.footer { 
 
    /*properties for cell*/ 
 
    /*Nothing is required here because we can use default styles*/ 
 
    /*background: #d9cf91;*/ 
 
    padding: 10px; 
 
} 
 

 

 
/*for phone*/ 
 

 
@media only screen and (max-width: 768px) { 
 
    [class*="col-"] { 
 
    width: 100%; 
 
    } 
 
}
<div class="row"> 
 
    <div class="col"> 
 
    <div class="navspot">Navigation Spot 
 
    </div> 
 
    </div> 
 
</div> 
 

 
<div class="row"> 
 
    <div class="col"> 
 
    <div class="maincontent">Main Content Spot 
 
    </div> 
 
    </div> 
 
</div> 
 

 
<div class="row"> 
 
    <div class="col-6"> 
 
    <div class="box1">Box 1 
 
    </div> 
 
    </div> 
 
    <div class="col-6"> 
 
    <div class="box2">Box 2 
 
    </div> 
 
    </div> 
 
</div> 
 

 
<div class="row"> 
 
    <div class="col-3"> 
 
    <div class="box3">Box 3 
 
    </div> 
 
    </div> 
 

 
    <div class="col-3"> 
 
    <div class="box4">Box 4 
 
    </div> 
 
    </div> 
 

 
    <div class="col-3"> 
 
    <div class="box5">Box 5 
 
    </div> 
 
    </div> 
 

 
    <div class="col-3"> 
 
    <div class="box6">Box 6 
 
    </div> 
 
    </div> 
 

 
    <div class="row"> 
 
    <div class="col"> 
 
     <div class="footer">Footer Area 
 
     </div> 
 
    </div> 
 
    </div>

很抱歉,如果我是一个傻瓜。真正与CSS和流动性的概念斗争。提前致谢!

+0

您搞砸了Code Snippet。 –

+1

你想要框填充列吗?从盒子类中移除浮动属性 – sol

+0

彩色区域(.boxX)不能是全宽,由于float:left,它会很小,这就是为什么你不能“看见”可见列。列布局似乎很好。 –

回答

0

修复1:彩色内容框未拉伸

做的 ovokuro说,并从ALL你的 “.box的” 类float:left;线。

修复2:列行为和包裹在网格

在网格一些的div元素不继承border-box模型,如你预期。为了解决这个问题对于所有浏览器添加:

html { 
    box-sizing: border-box; 
    } 
*, *:before, *:after { 
    box-sizing: inherit; 
    } 

有关详情请参阅 Box Sizing > Universal Box Sizing with Inheritance

修复3:指南

当你正在学习一些导游添加到您的网格,以便您可以更轻松看看你在做什么,以及事情的关系。例如:

/* temporary orange column guides */ 

    [class*="col-"] { 
    border: 1px dotted orange; 
    } 
+0

和ovokuro,这些评论是非常有帮助的。有用!我很高兴。非常感谢! – DMB66