gpt4 book ai didi

html - 响应式 CSS 布局,想要使一列的宽度与其他列不同

转载 作者:太空宇宙 更新时间:2023-11-04 09:41:22 25 4
gpt4 key购买 nike

我被困在家庭作业问题的一部分上。

我们正在为一个由 3 个框组成的简单网站生成 3 种响应式布局(我称它们为 lg、md、xs)。

我们不允许为此使用 Bootstrap 。到目前为止,您可以在这里看到我的实现:https://jennlhay.github.io/coursera-test/assn1/index.html

在适用于平板设备的中等尺寸布局上(您可以通过调整框的大小来查看),3 框布局环绕。

我想弄清楚如何让第三个框占据一整行。就像,占据与其上方的 2 个框不同的网格区域。

我已经尝试了很多不同的方法来做到这一点(将容器 div 更改为单独的 id,为 col-md 等向 css 添加一些额外的列定义)但无法弄清楚。 HTML和CSS如下:

HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Assignment Solution for Module 2</title>
</head>
<body>
<h1>Our Menu</h1>
<div class="row">
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="left">Chicken</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div>
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="middle">Meat</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div>
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="right">Eggs</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div></div>
</div>
</html>

CSS

* {
box-sizing: border-box;
}

body {
font-family: Arial, Helvetia, sans-serif;
}

h1 {
text-align: center;
font-size: 175%;
margin-bottom: 30px;
}

h2 {
position: relative;
float: right;
border: 1px solid black;
margin: 0;
padding: 10px;
font-size: 125%;
}

#left {
background-color: white;
}

#middle {
background-color: blue;
}

#right {
background-color: gray;
}

.container {
border: 1px solid black;
background-color: yellow;
width: 90%;
margin-right: auto;
margin-left: auto;
margin-bottom: 10%;
overflow: hidden;
}

p {
padding-top: 15px;
font-size: 100%;
clear: right;
}

.row {
width: 100%;
}

@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: 74.99%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}

@media (min-width: 768px) and (max-width: 991px) {
.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
.col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
float: left;
}
.col-md-1 {
width: 8.33%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33.33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
}
.col-md-7 {
width: 58.33%;
}
.col-md-8 {
width: 66.66%;
}
.col-md-9 {
width: 74.99%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
}

@media (max-width: 767px) {
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
}
.col-xs-1 {
width: 8.33%;
}
.col-xs-2 {
width: 16.66%;
}
.col-xs-3 {
width: 25%;
}
.col-xs-4 {
width: 33.33%;
}
.col-xs-5 {
width: 41.66%;
}
.col-xs-6 {
width: 50%;
}
.col-xs-7 {
width: 58.33%;
}
.col-xs-8 {
width: 66.66%;
}
.col-xs-9 {
width: 74.99%;
}
.col-xs-10 {
width: 83.33%;
}
.col-xs-11 {
width: 91.66%;
}
.col-xs-12 {
width: 100%;
}
}

最佳答案

您是否试图在中等尺寸的屏幕上使第三行全宽?如果是这样,您只需将 col-md 类更改为:

        <div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="right">Eggs</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div></div>

到:

        <div class="col-lg-4 col-md-12 col-xs-12"><div class="container"><h2 id="right">Eggs</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div></div>

关于html - 响应式 CSS 布局,想要使一列的宽度与其他列不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39879742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com