使用 css 网格学习响应式设计。我已经为桌面设置了一些总体布局,效果很好,但我没有设法对手机进行更改。我想要做的是将所有图片相互设置。知道怎么做吗?我很感激任何帮助。您可以在下面找到片段。
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.general-area{
display: grid;
grid-template-columns:1fr 1fr 1fr;
margin:20px;
}
img[src$="jpg"] {
width: 100%;
height:250px;
object-fit: cover;
display: block;
}
.column1 {
margin: 20px;
position: relative;
height: 0%;
}
.column2 {
margin: 20px;
position: relative;
}
.text {
margin-right: 60%;
}
.text h1 {
font-family: muli, sans-serif;
font-size: 3.5rem;
font-weight: 100;
}
.column2 .cover,
.column1 .cover {
bottom: 0px;
position: absolute;
opacity: 0.8;
font-family: muli, sans-serif;
font-weight: 500;
width: 100%;
height: 50px;
display: flex;
justify-content: center;
align-items: center;
color: white;
}
.dark {
background-color: #0E4C92;
}
.light {
background-color: #00B5FD;
}
.icon {
position: absolute;
right: -30px;
top: 8%;
width: 60px;
height: 60px;
border-radius: 50%;
box-shadow: 0 0 2px 1px gray;
}
.box-3{
grid-column-start: 2;
grid-column-end: 3;
}
@media (max-width: 960px) {
.general-area{
grid-template-columns:1fr;
max-width:1200px;
}
.text h1 {
left: 0px;
}
img[src$="jpg"] {
width: 250px;
height: 250px;
display: block;
}
.text {
margin-right: 0%;
}
}
<!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">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://use.typekit.net/dsl6sbt.css">
</head>
<body>
<div class="container">
<div class="text">
<h1>Solutions for<br> medical<br> applications</h1>
</div>
<div class="general-area">
<div class="column2">
<img class="icon" src="Datový zdroj 2.svg" alt="My Happy SVG" />
<a href="https://www.resinex.co.uk/contacts.html"><img src="Fluids.jpg" alt=""></img>
</a>
<div class="cover dark">
<h2>Fluids</h2>
</div>
</div>
<div class="column2">
<img class="icon" src="Datový zdroj 5.svg" alt="My Happy SVG" />
<a href="https://www.resinex.co.uk/contacts.html"><img src="medical.jpg" alt=""></a>
<div class="cover dark">
<h2>Medical device</h2>
</div>
</div>
<div class="column2">
<img class="icon" src="Datový zdroj 6.svg" alt="My Happy SVG" />
<a href="https://www.resinex.co.uk/contacts.html"><img src="SurgicalTools.jpg" alt=""></a>
<div class="cover dark">
<h2>Surgical tools and instruments</h2>
</div>
</div>
<div class="column2">
<img class="icon" src="Datový zdroj 1.svg" alt="My Happy SVG" />
<a href="https://www.resinex.co.uk/contacts.html"><img src="DrugDevice.jpg" alt=""></a>
<div class="cover light">
<h2>Drug delivery device</h2>
</div>
</div>
<div class="column2">
<img class="icon" src="Datový zdroj 1.svg" alt="My Happy SVG" />
<a href="https://www.resinex.co.uk/contacts.html"><img src="Packaging.jpg" alt=""></a>
<div class="cover light">
<h2>Packaging</h2>
</div>
</div>
<div class="column2">
<img class="icon" src="Datový zdroj 3.svg" alt="My Happy SVG" />
<a href="https://www.resinex.co.uk/contacts.html"><img src="HomeCare.jpg" alt=""></a>
<div class="cover light">
<h2>Home care</h2>
</div>
</div>
<div class="column2 box-3">
<img class="icon" src="Datový zdroj 4.svg" alt="My Happy SVG" />
<a href="https://www.resinex.co.uk/contacts.html"><img src="Labware.jpg" alt=""></a>
<div class="cover dark">
<h2>Labware</h2>
</div>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
只需覆盖 display: grid
类上的 .general-area
@media (max-width: 720px){
.general-area{
display: block;
}
}