我将图像居中并使其具有特定的高度和宽度,但是当浏览器尺寸大小约为500px(宽度)时,我希望图像开始调整其大小以适合屏幕,因此无需滚动。我该怎么做?
我将包含整个网页的所有代码,以防万一。
@charset "utf-8";
/* CSS Document */
body {
background-color: white;
padding: 0px;
margin: 0px;
}
#menu {
font-size: 15px;
font-family: "Gadugi";
color: white;
}
span {
color: #989797;
}
#nav {
position: absolute;
top: 100px;
height: 45px;
width: 100%;
background-color: black;
z-index: -100;
text-align: center;
}
#menu ul {
height: auto;
padding: 8px 0px;
padding-top: 13px;
margin: 0px;
}
#menu li {
/*padding between words */
display: inline;
padding: 15px;
}
#logo {
display: block;
margin-left: auto;
margin-right: auto;
width: 33em;
padding-top: 2px;
z-index: -100;
padding-left: 4px;
}
#home {
color: #26C6E7;
}
.container {
height: 500px;
width: 850px;
overflow: hidden;
position: absolute;
margin-top: 80px;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
.photo {
position: absolute;
animation: round 16s infinite;
opacity: 0;
height: 500px;
width: 850px;
min-width: 500px;
}
#orange {
background-image: url(images/pacman.jpg);
width: 100%;
height: 100%;
padding-top: 80px;
position: absolute;
z-index: -99999999999999999999999999;
background-size: cover;
background-repeat: repeat-y;
}
@keyframes round {
25% {
opacity: 1;
}
40% {
opacity: 0;
}
}
img:nth-child(4) {
animation-delay: 0s;
}
img:nth-child(3) {
animation-delay: 4s;
}
img:nth-child(2) {
animation-delay: 8s;
}
img:nth-child(1) {
animation-delay: 12s;
}
a {
text-decoration: none;
color: white;
font-weight: bold;
z-index: 100;
}
a:hover {
color: #26C6E7;
}

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Home - CooperTimewell.com</title>
<meta name="description" content="This is where the description is suppose to be." />
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<link href="images/anime.ico" rel="icon" type="image/x-icon" />
</head>
<body>
<div id="nav">
<div id="menu">
<ul>
<li id="home"><a href="http://www.coopertimewell.com"><span>HOME</span></a>
</li>
<li><a href="http://www.coopertimewell.com/thecoopertimes">THE COOPER TIMES</a>
</li>
<li><a href="http://www.coopertimewell.com/about">ABOUT ME</a>
</li>
<li><a href="http://www.coopertimewell.com/contact">CONTACT</a>
</li>
<li><a href="http://www.coopertimewell.com/games">GAMES</a>
</li>
</ul>
</div>
</div>
<a href="http://www.coopertimewell.com">
<img id="logo" src="images/logo.png" />
</a>
<div id="orange"></div>
<div class="container">
<img class='photo' src="images/slide1test.png" alt="" />
<img class='photo' src="images/slide1test.png" alt="" />
<img class='photo' src="images/slide1test.png" alt="" />
<img class='photo' src="images/slide1test.png" alt="" />
</div>
</body>
</html>
&#13;
答案 0 :(得分:1)
您可以使用CSS media queries
执行此操作@media (max-width: 500px) {
.container, .photo {
width: 100%;
}
}