如何与CSS发出响应式网格
我想为这样的非营利组织制作网格 - image 。这是我的纯净 - html& CSS 。但是保证金填充并不相同,响应模式不行。另外,我认为我的代码不正确。我已经花了2天的时间制作一个完美的网格,例如 image 。
我如何解决布局,保证金填充,响应能力等? 该网格的右CSS 是什么?
谢谢。
body {
color: #000;
font-family: 'Source Sans Pro', sans-serif;
}
h1, h2, h3, h4, h5, h6, p {
font-family: 'Source Sans Pro', sans-serif;
}
.focus_area {
width: 100%;
display: inline-block;
}
.focus {
width: 33.33%;
float: left;
position: relative;
padding: 2px;
}
.focus:last-child {
margin-top: -118px;
}
.focus_text {
width: 66.66%;
margin-top: 248px;
height: 248px;
padding: 36px;
background: rgb(156, 166, 104);
color: #fff;
}
.focus_text h2 {
text-align: center;
text-transform: uppercase;
}
.focus img { }
.focus p {
position: absolute;
bottom: 0;
left: 20px;
color: #fff;
text-shadow: 0 0 black;
font-size: 22px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300;400;700&display=swap" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container py-5">
<div class="row">
<div class="col-md-12">
<h2 class="text-center">Some Title</h2>
</div>
</div>
</div>
<div class="container">
<div class="focus_area">
<div class="focus">
<img src="https://i.ibb.co/wdRy4Wv/cities-and-shelter.png" alt="" class="img-fluid" />
<p>Cities & Shelters</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/VCbRdbx/education-and-training.png" alt="" class="img-fluid" />
<p>Education & Training</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/3NSF6hj/food-and-water.png" alt="" class="img-fluid" />
<p>Food & Water</p>
</div>
<div class="focus_text">
<h2>Delivering Humanitarian Relief Throughout The World</h2>
</div>
<div class="focus">
<img src="https://i.ibb.co/0BT5vp5/energy-and-environment.png" alt="" class="img-fluid" />
<p>Energy & Environment</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/bWpystL/jobs-and-business.png" alt="" class="img-fluid" />
<p>Jobs & Business</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/XX9Y7yH/health-and-fitness.png" alt="" class="img-fluid" />
<p>Health & Fitness</p>
</div>
</div>
</div>
<div class="container py-5">
<div class="row">
<div class="col-md-12">
<h2 class="text-center">Some Title</h2>
</div>
</div>
</div>
</body>
</html>
I want to make a grid for a non-profit organization like this - image. Here is my pure - HTML & CSS. But margin padding isn't the same, and responsive mode isn't okay. Also, I think my code isn't right. I've spent already 2 days making a perfect grid like that image.
How I can fix layout, margin padding, responsiveness, etc?
What is the right CSS for this grid?
Thanks.
body {
color: #000;
font-family: 'Source Sans Pro', sans-serif;
}
h1, h2, h3, h4, h5, h6, p {
font-family: 'Source Sans Pro', sans-serif;
}
.focus_area {
width: 100%;
display: inline-block;
}
.focus {
width: 33.33%;
float: left;
position: relative;
padding: 2px;
}
.focus:last-child {
margin-top: -118px;
}
.focus_text {
width: 66.66%;
margin-top: 248px;
height: 248px;
padding: 36px;
background: rgb(156, 166, 104);
color: #fff;
}
.focus_text h2 {
text-align: center;
text-transform: uppercase;
}
.focus img { }
.focus p {
position: absolute;
bottom: 0;
left: 20px;
color: #fff;
text-shadow: 0 0 black;
font-size: 22px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300;400;700&display=swap" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container py-5">
<div class="row">
<div class="col-md-12">
<h2 class="text-center">Some Title</h2>
</div>
</div>
</div>
<div class="container">
<div class="focus_area">
<div class="focus">
<img src="https://i.ibb.co/wdRy4Wv/cities-and-shelter.png" alt="" class="img-fluid" />
<p>Cities & Shelters</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/VCbRdbx/education-and-training.png" alt="" class="img-fluid" />
<p>Education & Training</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/3NSF6hj/food-and-water.png" alt="" class="img-fluid" />
<p>Food & Water</p>
</div>
<div class="focus_text">
<h2>Delivering Humanitarian Relief Throughout The World</h2>
</div>
<div class="focus">
<img src="https://i.ibb.co/0BT5vp5/energy-and-environment.png" alt="" class="img-fluid" />
<p>Energy & Environment</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/bWpystL/jobs-and-business.png" alt="" class="img-fluid" />
<p>Jobs & Business</p>
</div>
<div class="focus">
<img src="https://i.ibb.co/XX9Y7yH/health-and-fitness.png" alt="" class="img-fluid" />
<p>Health & Fitness</p>
</div>
</div>
</div>
<div class="container py-5">
<div class="row">
<div class="col-md-12">
<h2 class="text-center">Some Title</h2>
</div>
</div>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用CSS网格轻松获得想要的东西:
you can easily get what you want by using CSS Grid :
这是一个开始,您必须自己添加数据和图像,但是可以轻松地更改它以满足您的确切需求。
Here is a start, you would have to add data and images yourself, but it can be easily changed to fit your exact needs.
您可以检查解决方案。使用的flexbox以及有关响应性,只有文本大小会影响,因此请相应地调整文本大小。还要注意,为了样式目的,我在标记中添加了一些更改。让我知道它是否回答了您的问题。
You can check out the solution. Used flexbox and as for the responsiveness, only the text size will affect, so adjust the text size accordingly. Also to note that I added some changes in the markup for the style purposes. Let me know if it answered your question.
我使用
网格
和flex
css属性做出了解决方案;这样,我设法实现了您要创建的布局。[编辑:我不知道发布链接不符合准则,对不起:(]
无论如何,我在此处发布了有关如何创建布局的代码:
I made a solution using
grid
andflex
css properties; that way I managed to realize the layout you wanted to create.[Edited: I didn't know posting links don't fit the guidelines, sorry :(]
Anyway, I post here a snippet code on how I managed to create the layout: