gpt4 book ai didi

html - 为什么我的图像不响应大小调整但其他所有内容都响应?

转载 作者:行者123 更新时间:2023-11-28 14:19:50 25 4
gpt4 key购买 nike

https://imgur.com/a/b667X1Y

我正在为我的 IT 类(class)做一个元素。我无法让网站响应。我的 Logo 和导航栏似乎都有响应,但是房子的图像似乎没有响应。 (上面的链接是90%放大)

我曾尝试编辑宽度和高度的大小,但由于我对它很陌生,所以我正在努力解决这个问题。

我希望顶部图片具有响应性。我该怎么做?

@charset "utf-8";
/* CSS Document */
body {
margin: 0px;
}
/*This is the container css*/
.container {
margin-left: 200px;
margin-right: 200px;
margin-top: 0;
box-sizing: border-box;
}

.logo {
position: relative;
display: inline-block;
}

.logo h1 {
margin-top: 20px;
margin-bottom: 0;
color: #232323;
font-family:Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", "monospace";
}

.navbar {
float: right;
top: 0;
padding: 10px;
}

.navbar ul a:hover {
padding: 5px;
margin: 0;
background-color: lightblue;
}

.navbar li {
display: inline-block;
text-decoration: none;
padding: 10px;
color: black;
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", "monospace";
}

/*This is the top image css*/
#top-img {
background-image: url("images/top-img.jpg");
background-position: center;
min-width: 100%;
height: 500px;
position: relative;
background-repeat: no-repeat;
border-bottom: solid #3E3E3E 3px;
}

/*This is the @media i am trying to make the top image responsive*/
@media screen and (min-width: 40em) {
#top-img {
max-width: 50em;
}
}

@media screen and (min-width: 64em) {
#top-img {
max-width: 70em;
}

}
<html>
<head>
<meta charset="utf-8">
<title>Plantscape</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>

<body>
<div id="top-img">
<div class="container">
<header>
<div class="logo">
<h1>Plantscape</h1>
</div>
<div class="navbar">
<ul>
<a href="portfolio.html"><li>Folio</li></a>
<a href="services.html"><li>Services</li></a>
<a href="about.html"><li>About Us</li></a>
<a href="contact.html"><li>Contact Us</li></a>
</ul>
</div>
</header>
</div>
</div>
</body>
</html>

最佳答案

您使用图像作为背景而不是 HTML 元素。您已经告诉您的 #top-img 元素响应,但您还没有告诉背景响应。尝试将以下声明添加到您的 CSS:

 #top-img {
...
background-size: cover;
}

关于html - 为什么我的图像不响应大小调整但其他所有内容都响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55369367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com