简体   繁体   English

CSS的最大宽度不会调整图像大小

[英]css Max-Width won't resize image

I'm creating a flexible grid website and I ran into a snag. 我正在创建一个灵活的网格网站,但遇到了麻烦。 It doesn't appear that the CSS property max-width:100%; 似乎CSS属性max-width:100%; is working on my logo image. 正在处理我的徽标图像。 It's supposed to resize along with the flexible grid, but it's not. 它应该随着灵活的网格一起调整大小,但事实并非如此。 Maybe I'm not calling the image correctly or my syntax is incorrect? 也许我没有正确调用图像,或者语法不正确? The image is 200x67, and here's the relevant HTML: 图片为200x67,这是相关的HTML:

<header>
<img src="images/so_200.png" alt="Website.com" id="logo" />
</header>

and here's the CSS for that: 这是用于此的CSS:

header {
background-color:#ccc;
padding:1%;
}
img #logo {
display: block;
max-width:100%;
max-height:100%;
width: auto;
height: auto;
}

Any idea why it's not working? 知道为什么它不起作用吗? It shouldn't matter the image is a .png, right? 图像是.png没关系吧?

Remove space between img and #logo 删除img#logo之间的空间

img#logo {
    display: block;
    max-width:100%;
    max-height:100%;
    width: auto;
    height: auto;
}

Image file type(png) doesn't matter for css rules. 图像文件类型(png)对于CSS规则无关紧要。

You have a space between the id and element: id和element之间有一个空格:

img #logo => img#logo img #logo => img#logo

img#logo {
  display: block;
  max-width:100%;
  max-height:100%;
  width: auto;
  height: auto;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM