当前位置: 首页 > 知识库问答 >
问题:

我的网站无法正确缩小到手机和平板电脑尺寸,我该如何解决这个问题?

淳于升
2023-03-14

我正在尝试创建我的第一个网站,并在其中添加了内容,但是当屏幕变小到平板电脑或移动屏幕尺寸时,它无法正常缩小,使一切变得杂乱无章。我没有使用CSS网格,我不确定这是否导致了问题。我也一直在为桌面开发网站,我看到许多人正在为移动开发,然后调整更大屏幕的尺寸。任何帮助都将不胜感激!谢谢!

/* MOBILE AND GLOBAL STYLES */

/* applies to screens smaller than 500px (first breakpoint) */
/* and above unless overwritten below */

body {
background: grey;
margin: 0;
font-family: Arial;
}


header {
grid-area: header;
background: darkblue;
color: white;
margin: 0;
font-family: rockwell;
font-size: 450%;
text-align: center;
height: 100%;
}

main{
color: black;
font-family: rockwell;
font-size: 150%;
margin-left: 50px;
margin-right: 50px;
}

p{
margin-left: 35px;
}

h1{
text-decoration: underline;
text-align: center;
}

h2{
text-decoration: underline;
text-align: center;
}

h3{
text-align: center;
text-decoration: underline;
}

nav {
grid-area: menu;
display: none;
clear: both;
justify-content: center;
background: black;
flex-direction: column;
}

nav a {
padding: 1.25em 1.5em;
color: black;
background: #A09C9C;
text-decoration: none;
transition: all 1.5s;
width: 100%;
text-align: center;
font-size: 130%;
font-family: fantasy;
border-right: 1px solid white;
border-top: 5px solid white;
border-bottom: 5px solid white;
}

.devs{
text-align: center;
}

nav a:hover {
color: white;
background: grey;
}

.menu {
background: #555;
text-align: center;
color: grey;
line-height: 2em;
}

.menu-toggle {
display: flex;
}

.fa {
padding: 20px;
font-size: 30px;
width: 70px;
text-align: center;
text-decoration: none;
margin: 8px 8px;
border-radius: 50%;
transition: .6s
}

.fa:hover {
opacity: 0.7;
}

.fa-facebook {
background: #3B5998;
color: white;
}

.fa-twitter {
background: #55ACEE;
color: white;
}

.fa-youtube {
background: #dd4b39;
color: white;
}

.fa-instagram {
background: #007bb5;
color: white;
}

.media{
position: sticky;
}

.image{
position: sticky;
}

.apibox {
background-color: lightgrey;
width: 800px;
border: 5px solid black;
padding: 25px;
margin-left: 30%;
margin-top: 3%;
}

.vance {
border: 0;
width: 560px;
height: 315px;
align: left;
margin-left: 15%;
margin-bottom: 2%;
}

.vancevideo {
width: 560px;
height: 315px;
margin-left: 7%;
align: left;
margin-bottom: 2%;
}

.superbowl {
border: 0;
width: 560px;
height: 315px;
align: left;
margin-left: 15%;
margin-bottom: 2%;
}

.superbowlvid{
width: 560px;
height: 315px;
margin-left: 7%;
align: left;
margin-bottom: 2%;
}

.news1 {
background-color: lightgrey;
width: 1250px;
border: 5px solid black;
padding: 25px;
margin-left: 15%;
margin-top: 3%;
}

.animation {
position: absolute;
/* comment out 'top' and 'left' and see what happens */
top: 176px;
left: 550px;
box-sizing: border-box;
width: 105px;
height: 62px;
padding: 0 1em;
background-color: #e5e5e5;
animation-name: movingBox;
animation-duration: 30s;
animation-iteration-count: infinite; /* infinite */
animation-direction: alternate;
animation-timing-function: ease-in-out;
font-size: 100%;
text-align: center;
}

.animation2 {
position: absolute;
/* comment out 'top' and 'left' and see what happens */
top: 176px;
left: 550px;
box-sizing: border-box;
width: 87px;
height: 62px;
padding: 0 1em;
background-color: #e5e5e5;
animation-name: movingBox;
animation-duration: 30s;
animation-iteration-count: infinite; /* infinite */
animation-direction: alternate;
animation-timing-function: ease-in-out;
font-size: 100%;
text-align: center;
}

.animation3 {
position: absolute;
/* comment out 'top' and 'left' and see what happens */
top: 176px;
left: 550px;
box-sizing: border-box;
width: 87px;
height: 70px;
padding: 0 1em;
background-color: #e5e5e5;
animation-name: movingBox;
animation-duration: 30s;
animation-iteration-count: infinite; /* infinite */
animation-direction: alternate;
animation-timing-function: ease-in-out;
font-size: 110%;
text-align: center;
}

.animation4 {
position: absolute;
/* comment out 'top' and 'left' and see what happens */
top: 190px;
left: 550px;
box-sizing: border-box;
width: 87px;
height: 70px;
padding: 0 1em;
background-color: #e5e5e5;
animation-name: movingBox;
animation-duration: 30s;
animation-iteration-count: infinite; /* infinite */
animation-direction: alternate;
animation-timing-function: ease-in-out;
font-size: 110%;
text-align: center;
}

.mail {
width: 70px;
height: 70px;
}

.gamepass {
width: 150px;
height: 80px;
}

.footballamerica {
width: 150px;
height: 80px;
}

* {box-sizing:border-box}

/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}

/* Hide the images by default */
.mySlides {
display: none;
}

/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;
}

/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text {
color: white;
font-size: 30px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
font-family: Cooper Black;
text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;
}

/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}

/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: white;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}

.active, .dot:hover {
background-color: #717171;
}

/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}

@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}


@keyframes movingBox {
0%   { background-color:#e5e5e5; left: 523px; top: 190px;}
25%  { background-color:#e5e5e5; left: calc(78% - 200px); top: 190px;}
50%  { background-color:#e5e5e5; left: calc(38% - 200px); top: 190px; }
75%  { background-color:#e5e5e5; left: calc(78% - 200px); top: 190px; }
100% { background-color:#e5e5e5; left: 523px; top: 190px; }
}


/* comment in for CSS-only solution: */
.menu:hover + nav,
nav:hover {
display: flex;
}

.team-wiki {
text-align: center;
margin-left: 25%;
}

/* TABLET STYLES */
.menu{
color: white;
}
@media screen and (min-width: 500px) {

/* applies to screens wider than 499px */

body {
background: grey;
}
.menu {
display: none;
min-width:500px;
}
nav {
display: flex;
flex-direction: row;
}

nav a {
padding: 1.25em 0.5em;
color: white;
background: darkred;
text-decoration: none;
transition: all 1.5s;
}
/* just change the menu colours on hover above mobile widths */
nav a:hover {
color: white;
background: darkred;
opacity: 0.7;
}


}


/* DESKTOP STYLES */

@media screen and (min-width: 1000px) {

/* applies to screens wider than 999px */

body {
background: #e5e5e5;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NFL News</title>
<link rel="icon" type="image/png" href="nfl.png">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- 
awesome/4.7.0/css/font-awesome.min.css">
</head>
<header><img border="0" alt="NFL Logo" src="nfl.png" width="80" height="80" 
align="left">NFL FANSITE <img border="0" alt="NFL Logo" src="nfl.png" 
width="80" height="80" align="right"></header>
<body class="grid">
<div id="wrapper"></div>

<div class="menu" id="menu-toggle">MENU</div>
<nav id="menu-nav">
 <a href="index.html">HOME</a>
 <a href="news.html">NEWS</a>
 <a href="teamhistory.html">TEAM HISTORY</a>
 <a href="#">DISCUSSIONS</a>
 <a href="gallery.html">GALLERY</a>
</nav>

<div class="animation2">
<a href="https://www.footballamerica.co.uk/en/"><img 
class="footballamerica" src="footballamerica.jpg" alt="Link to the football 
america website"/></a>
</div>
<a href="https://www.facebook.com/NFL/" class="fa fa-facebook"</a>
<a href="https://twitter.com/NFL? 
ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor" class="fa fa- 
twitter"></a>
<a href="https://www.youtube.com/user/NFL" class="fa fa-youtube"></a>
<a href="https://www.instagram.com/nfl/?hl=en" class="fa fa-instagram"></a>



<main>
<h1>
NFL News
</h1>
<h3>
Vance Joseph Fired
</h3>
<img class="vance" alt="Picture of developers" src="Vance.jpg">
<iframe class="vancevideo" src="https://www.youtube.com/embed/nny6aUi4lg8" 
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in- 
picture" allowfullscreen></iframe>
</iframe>
<div class="news1">
John Elway has fired Vance Joseph after two consecutive season losses 
without any playoff chances. The 2017 season that Vance Joseph first coached 
ended in a 5-11 record for the Denver Broncos and the 2018 season ending 
with a 6-10 record. Before the period of Vance Joseph as head coach, Gary 
Kubiak had led the Broncos to a SuperBowl victory in 2015 against the 
Panthers. In an interview John Elway said "I spoke with Vance this morning 
and thanked him for all of his hard work as our head coach". Elway also said 
that "Vance made a lot of strides and deserves credit for how hard and 
competitively the team played this season". Many of the fans of the Broncos 
were very unhappy, especially towards the back-end of the 2018 season 
because of the downward spiral that happened after the first few weeks of 
the season and also because of the lack of competitiveness in important 
games. Vance Joseph still expressed how appriciative he was for his 
opportunity in Denver by saying "I want to thank John Elway, Joe Ellis and 
the organisation for the opportunity to serve as the head coach of the 
Denver Broncos" and "It's disappointing not being able to finish what we 
started, but I'm incredibly proud of the players and coaches for how they 
fought and worked every week".
</div>
<br>
<br>
<br>
<br>
<h3>
SuperBowl Odds
</h3>
<img class="superbowl" alt="superbowl image" src="SuperBowl.jpg">
<iframe class="superbowlvid" src="https://www.youtube.com/embed/sog0CFGH-_4" 
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in- 
picture" allowfullscreen>
</iframe>
<br>
Clearly with the NFL, anything can happen, however it is interesting to look 
at the predictions that people have made about the playoffs and who will 
ultimately win the SuperBowl. Many sources are labelling the New Orleans 
Saints as having the highest chance of winning the Super Bowl with 
PaddyPower, Bet365, WilliamHill and Betfair all posted 13/5 odds on this 
happening. Next, with no surprises, is the Kansas City Chiefs who have 9/2 
odds on Bet365, Ladbrokes, WilliamHill and Betfair. It is not surprising 
that these two teams are the top two in this situation due to how impressive 
their seasons have been so far this year. Closely matching or following the 
Chiefs are the Rams who have the same odds of 9/2 on Bet365, BetVictor and 
Boyle Sports, however they also have some 11/2 odds on betting sites such as 
SkyBet, WilliamHill and 10Bet which makes us think that their chances aren't 
just as great as the Chiefs. Finally in the 4th position is the New England 
Patriots who have 6/1's on the likes of WilliamHill, Betfair, PaddyPower and 
Betway to name a few. The New England Patriots are always great contenders 
in the playoffs and always seem to be a team that can clutch victories in 
important situations. The video displayed here, shows the NFL's predictions 
of the probability of some of the different teams chances of winning the 
Super Bowl. They go as follows: New Orleans Saints - 17.1% | Los Angeles 
Rams - 11.4% | Chicago Bears - 10.3% | Baltimore Ravens - 6.8% | Dallas 
Cowboys - 6.0%. Either way, this year in the NFL has been very unpredictable 
so any of the teams that have reached the playoffs are viable to be Super 
Bowl 2019 winners.
<br>
<br>
<br>
</main>

<script src="js/scripts.js"></script>
</body>
</html>

共有3个答案

任文乐
2023-03-14

让我印象深刻的第一件事是news1 div容器的固定宽度为1250px。

我想,用一个更相对的单位来代替它,比如90%或者任何看起来最好的单位,实际上可以避免你的问题。

赵英哲
2023-03-14

您需要使用媒体查询,也许这会有所帮助https://www.w3schools.com/css/css_rwd_mediaqueries.asp

长孙弘壮
2023-03-14

要在较小的设备上或实际上任何设备屏幕大小上修复样式,只需使用:

@media (min-width: 768px){
     >Your Code here
}

或者

@media (max-width: 1200px){
     >Your Code here
}

或者

 @media (min-width: 768px) and (max-width: 1200px){
      >Your Code here
 }

还有一个非常有用的库,称为Bootstrap,用于创建响应式网站,请查看:[url]

希望你觉得这有用

致以最诚挚的问候,哈立德。

 类似资料:
  • 我怎么能解决这个问题? 颤振并建立网络 具有良好零安全性的建筑物 目标dart2js失败:异常:警告:'dart2js'entrypoint脚本已弃用,请改用'dart compile js'。 /C:/用户/DELL/AppData/本地/发布/缓存/托管/pub.dartlang.org/flutter_screenutil-5.3.1/lib/screenutil_init.dart: 23

  • 启动错误 ApplicationContext.若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2019-10-17 15:44:43.968错误10460--[main]O.S.Boot.SpringApplication:应用程序运行失败 我的pom.xml:

  • 我有这个错误:值错误:检查输入时的错误:预期dense_1_input有形状(6,),但得到了形状(1,)数组,但我的keras模型的输入层model.add(密集(单位=5,kernel_initializer='统一',激活='relu',input_dim=6))所以(6,)维度和输入是输入=np.array([HeadX, HeadY, TailX, TailY, AppleX, Appl

  • 我想制作一个单独的模块,以便在项目之间共享它。该模块将具有android组件。因此,在创建新模块时,选项是电话

  • 对于我在Java中创建的GUI应用程序,我有以下内容: 一个JFrame,设置为最小大小为(300,200) 一个JSplitPane,其中包含: 在左侧,最小大小为(100,0)的JScrollPane(包含JTree)(我只想将宽度限制为200) 在右边,一个最小大小为(200,0)的JPanel 在以下情况下,尺寸不会给我带来任何问题: 向左调整JSplitPane的大小(到JScrollP

  • https://www.codechef.com/problems/maxgcd Chef有一个由N个整数组成的集合。如果子集有两个或更多的元素,则Chef将该集合的子集称为良好的。他把所有的好子集表示为S1,S2,S3,…,S2n-n-1。现在他把每个好子集Si的元素的GCD表示为Gi。厨师想要找到最大的GI。 输入 输入的第一行包含一个表示测试用例数量的整数T。测试用例的描述如下:“每个测试用