CSS响应迅速布局帮助:DIV不在同一条线上
我开始教自己如何编码和进行作业创建一个响应网站,但无法使用Twitter Bootstrap或任何新的网格属性等框架。问题是我试图使3个Divs以992px的最小宽度和最小宽度为768px的设备,最大宽度为991px,我正在尝试在两者中获得两个,最高宽度为991px的设备。一个在底部。有了我当前的代码,我可以在顶部获得3个,但是当我去平板电脑设备时,我垂直铺设了所有3个,并占据了50%的屏幕。
我尝试调整宽度属性,删除填充和边距,并与“容器”,边框框,卸下和添加浮点属性的类别添加一个总体div。
这是我当前的CSS代码和预期的图像。
*{
box-sizing: border-box;
}
body {
background-color: white;
margin: 0px;
}
h1 {
color: black;
text-align: center;
}
.container {
width: 100%;
}
section {
background-color: gray;
border: 1px solid black;
margin: 5px;
}
p#description {
/*text-align: left;*/
/*font-weight:100;*/
padding-top: 20px;
padding-left: 20px;
padding-right: 20px;
/*padding-bottom: 0px;*/
height: 250px;
}
p#suboptions {
float: right;
border-left: 1px solid black;
border-bottom: 1px solid black;
}
p.chick {
background-color: lightpink;
color:black;
text-align: center;
font-size: large;
font-weight: bold;
font-family: 'Times New Roman', Times, serif;
width: 25%;
margin-top: 0px;
padding: 5px;
}
p.beef {
background-color:maroon;
color: white;
text-align: center;
font-size: large;
font-weight: bold;
font-family: 'Times New Roman', Times, serif;
width: 25%;
margin-top: 0px;
padding: 5px;
}
p.sushi {
background-color: blanchedalmond;
color:black;
text-align: center;
font-size: large;
font-weight: bold;
font-family: 'Times New Roman', Times, serif;
width: 25%;
margin-top: 0px;
padding: 5px;
}
@media (min-width: 768px) and (max-width: 991px) {
/*tablets*/
.col-s-1 {width: 8.33%;}
.col-s-2 {width: 16.66%;}
.col-s-3 {width: 25%;}
.col-s-4 {width: 33.33%;}
.col-s-5 {width: 41.66%;}
.col-s-6 {width: 50%;}
.col-s-7 {width: 58.33%;}
.col-s-8 {width: 66.66%;}
.col-s-9 {width: 75%;}
.col-s-10 {width: 83.33%;}
.col-s-11 {width: 91.66%;}
.col-s-12 {width: 100%;}
section {
float: left;
margin: 5px;
}
p#description {
height: 170px;
}
}
@media (min-width: 992px) {
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;}
.col-lg-1 {width: 8.33%;}
.col-lg-2 {width: 16.66%;}
.col-lg-3 {width: 25%;}
.col-lg-4 {width: 33.33%;}
.col-lg-5 {width: 41.66%;}
.col-lg-6 {width: 50%;}
.col-lg-7 {width: 58.33%;}
.col-lg-8 {width: 66.66%;}
.col-lg-9 {width: 75%;}
.col-lg-10 {width: 83.33%;}
.col-lg-11 {width: 91.66%;}
.col-lg-12 {width: 100%;}
}
I'm in the beginnings of teaching myself how to code and working on an assignment to create a responsive site but can't use frameworks like Twitter bootstrap or any of the new grid properties. The problem is I'm trying to get 3 divs to align for devices with a min-width of 992px and for devices with a min-width of 768px and a max-width of 991px, I'm trying to get two across the two and one at the bottom. With my current code, I can get 3 across the top but when I go to tablet devices I'm getting all 3 laid vertically and taking 50% of the screen.
I've tried adjusting the width property, removing padding and margins, adding an overarching div with the class of "container", border box, removing and adding the float property.
Here's my current CSS code and image of what's expected.
*{
box-sizing: border-box;
}
body {
background-color: white;
margin: 0px;
}
h1 {
color: black;
text-align: center;
}
.container {
width: 100%;
}
section {
background-color: gray;
border: 1px solid black;
margin: 5px;
}
p#description {
/*text-align: left;*/
/*font-weight:100;*/
padding-top: 20px;
padding-left: 20px;
padding-right: 20px;
/*padding-bottom: 0px;*/
height: 250px;
}
p#suboptions {
float: right;
border-left: 1px solid black;
border-bottom: 1px solid black;
}
p.chick {
background-color: lightpink;
color:black;
text-align: center;
font-size: large;
font-weight: bold;
font-family: 'Times New Roman', Times, serif;
width: 25%;
margin-top: 0px;
padding: 5px;
}
p.beef {
background-color:maroon;
color: white;
text-align: center;
font-size: large;
font-weight: bold;
font-family: 'Times New Roman', Times, serif;
width: 25%;
margin-top: 0px;
padding: 5px;
}
p.sushi {
background-color: blanchedalmond;
color:black;
text-align: center;
font-size: large;
font-weight: bold;
font-family: 'Times New Roman', Times, serif;
width: 25%;
margin-top: 0px;
padding: 5px;
}
@media (min-width: 768px) and (max-width: 991px) {
/*tablets*/
.col-s-1 {width: 8.33%;}
.col-s-2 {width: 16.66%;}
.col-s-3 {width: 25%;}
.col-s-4 {width: 33.33%;}
.col-s-5 {width: 41.66%;}
.col-s-6 {width: 50%;}
.col-s-7 {width: 58.33%;}
.col-s-8 {width: 66.66%;}
.col-s-9 {width: 75%;}
.col-s-10 {width: 83.33%;}
.col-s-11 {width: 91.66%;}
.col-s-12 {width: 100%;}
section {
float: left;
margin: 5px;
}
p#description {
height: 170px;
}
}
@media (min-width: 992px) {
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;}
.col-lg-1 {width: 8.33%;}
.col-lg-2 {width: 16.66%;}
.col-lg-3 {width: 25%;}
.col-lg-4 {width: 33.33%;}
.col-lg-5 {width: 41.66%;}
.col-lg-6 {width: 50%;}
.col-lg-7 {width: 58.33%;}
.col-lg-8 {width: 66.66%;}
.col-lg-9 {width: 75%;}
.col-lg-10 {width: 83.33%;}
.col-lg-11 {width: 91.66%;}
.col-lg-12 {width: 100%;}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,在 992px 之后,您可以使用 FlexBox 将所有项目水平对齐在一行中。
在 768px 和 992 之间,您可以使用 CSS 网格创建 2x2 网格,第三个框将跨越第二行。
So after 992px you can use FlexBox to align all items horizontally in a row.
Between 768px and 992 you can use CSS Grid to create 2x2 grid and third box will span in 2nd row.