如何在不必为每个屏幕大小添加媒体查询的情况下提高网页的响应能力



我的网页为小型手机(320像素宽(设计得很好,每当屏幕尺寸超过平板电脑尺寸(768像素宽(时,我都会进行媒体查询。每当屏幕处于这两种尺寸之间时,一切都会中断。有没有一种方法可以让它工作起来,看起来很漂亮,而不必为每个屏幕大小添加查询?我还担心我没有使用能够很容易响应的代码,但这就是我如何让一切按照我喜欢的方式工作的方法

底部还有一个图像,我无法将其居中。

<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Stangler Electronics</title>
<meta name="author" content="Spencer Kooyman">
<meta name="description" content="A basic webpage layout for future projects.">
<meta charset="UTF-8" name="viewport" content="width=device-width, 
initial-scale=1.0">
<link rel="stylesheet" href="https://use.typekit.net/nsb6sac.css">
<link rel="stylesheet" href="Test-About.css" type="text/css">
<link rel="icon" href="Images/GreenPower.jpg" type="image/x-icon">  
</head>

<body>
<header>
<nav>
<a href="Test.html" class="navbutton">Home</a>
<a href="Test-About.html" class="active">About</a>
<a href="Test-Contact.html" class="navbutton">Contact</a>
<a href="Test-Stock.html" class="navbutton">Stock</a>
</nav>
<div class="parallax1">
<h1>Stangler Electronics</h1>
</div>
</header>
<main>
<div class="imgandtext">
<p class="rightoftext">Boyd purchased the business from Stevens Electronics in 2021. He f*cks with Wu-Tang MFn Killa Bees son.</p>
<img src="Images/Pops.jpg" alt="" class="img-pops">
</div>
<div class="imgandtext2">
<img src="Images/HistoricStCharles.jpg" alt="" class="img-store">
<p class="topoftext">The store is hella old, it's been around for since like beginning times I bet.</p>
</div>
<div class="parallax1"></div>
</main>
</body>
* { box-sizing: border-box;
margin: 0;
padding: 0;}
:root {
min-height: 100vh;  
min-width: 320px;
max-width: 1440px;
}
html {
font-size: 23px;
font-family: dolce, sans-serif;
font-weight: 400;
font-style: normal;
color: rgba(254, 176, 42, 1);
overflow-x: hidden;
}
body {
width: 100%;
min-height: 100vh;
background-color: rgba(51,51,51,1);
position: relative;
}
header {
margin-top: 46px;
}
nav {
background-color: rgba(254, 176, 42, 1);
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-evenly;
position: fixed;
top: 0;
z-index: 3;
border-bottom: 1px solid rgba(51, 51, 51, 1);
}
a:hover {
color: rgba(91, 121, 168, 1)
}
a.navbutton {
font-size: 23px;
font-weight: 700;
color: rgba(51, 51, 51, 1);
text-decoration: none;
padding-top: 13px;
padding-bottom: 13px;
}
nav a.active {
font-size: 23px;
font-weight: 700;
color: rgba(91, 121, 168, 1);
text-decoration: none;
padding-top: 13px;
padding-bottom: 13px;
}
div.parallax1 {
background-image: url(Images/YellowtoBlue.jpeg);
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
width: 100%;
height: 77px;
}
h1 {
color: rgba(0, 0, 0, .7);
text-shadow: 2px 2px 8px rgba(254, 176, 42, 1);
font-size: 37px;
font-family: storefront-pro, sans-serif;
font-style: normal;
font-weight: 400;
text-align: center;
padding-top: 13px;
}
main {
width: 100vw;
}
.h2-1 {
width: 100%;
height: 100px;
}
h2 {
color: rgba(254, 176, 42, 1);
text-align: center;
font-size: 23px;
padding: 23px 13px;
}
.parallax2 {
background-image: url(Images/YellowtoBlue.jpeg);
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
width: 100%;
height: 25vh;
}
.imgandtext  {
min-height: 288px;
width: 100%;
display: flex;
}
.img-pops {
width: 45%;
height: auto;
margin: 13px 13px;
position: absolute;
left: 0;
border: 3px solid rgba(37,37,37,1);
}
.rightoftext {
position: absolute;
width: 45%;
text-align: left;
right: 13px;
padding-left: 13px;
padding-top: 13px;
}
.imgandtext2  {
min-height: 200px;
width: 100%;
display: flex;
flex-direction: column;
position: relative;
top: -366px;
}
.img-store {
width: 91%;
height: auto;
margin: 13px 13px;
position: absolute;
top: 375px;
border: 3px solid rgba(37,37,37,1);
}
.topoftext {
position: absolute;
width: 100%;
text-align: center;
top: 313px;
padding-left: 13px;
padding-right: 13px;
padding-top: 13px;
}
button {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}

@media screen and (min-width: 768px) {
html {
font-size: 33px;
}
header {
margin-top: 1px;
}

nav {
background-color: rgba(254, 176, 42, 1);
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-evenly;
position: fixed;
top: 0;
z-index: 3;
border-bottom: 1px solid rgba(51, 51, 51, 1);
}

a:hover {
color: rgba(91, 121, 168, 1)
}

a.navbutton {
font-size: 33px;
font-weight: 700;
color: rgba(51, 51, 51, 1);
text-decoration: none;
padding-top: 13px;
padding-bottom: 13px;
}

nav a.active {
font-size: 33px;
font-weight: 700;
color: rgba(91, 121, 168, 1);
text-decoration: none;
padding-top: 13px;
padding-bottom: 13px;
}
h1 {
font-size: 88px;
margin-top: 88px;
}
div.parallax1 {
height: 170px;
}
.imgandtext  {
top: 33px;
min-height: 600px;
width: 100%;
display: flex;
position: relative;
}

.img-pops {
width: 45%;
height: auto;
margin: 13px 13px;
position: absolute;
left: 0;
border: 3px solid rgba(37,37,37,1);
}

.rightoftext {
position: absolute;
width: 45%;
text-align: left;
right: 13px;
padding-left: 13px;
padding-top: 13px;
}

.imgandtext2  {
min-height: 200px;
width: 100%;
display: flex;
flex-direction: column;
position: absolute;
top: 650px;
}

.img-store {
width: 91%;
height: auto;
margin: 13px 13px;
position: absolute;
top: 375px;
border: 3px solid rgba(37,37,37,1);
}

.topoftext {
position: absolute;
width: 100%;
text-align: center;
top: 313px;
padding-left: 13px;
padding-right: 13px;
padding-top: 13px;
}
}

也许您应该使用一个框架。。。你可以使用bootstrap来制作一个自动调整的网格系统。。。

关于如何使用网格系统的文档

相关内容

最新更新