html - 响应图像

标签 html css

我不是在寻找关于图像的创造性解决方案,我已经阅读了大量关于加载图像等的内容。

我只是在做一些基本的响应式设计,想要加载大图像并在窗口变小时将其压缩。

我编写了以下 CSS:

@media (max-width:420px){
     #header #logo{
        width:60%;
        float:left;
        background:red;
    }

    #header #logo #image{
        margin:5%;
        width:20%;
        float:left;
        background:green;
    }

    #header #nav{
        width:40%;
        float:left;
        background:purple;
    }

    #header #nav #search{
        max-width:33%;
        float:left;
    }

    #header #nav #account{
        max-width:33%;
        float:left;
    }

    #header #nav #menu{
        max-width:33%;
        float:left;
    }
 }

以及与之配套的 HTML:

<div id="logo">
        <div id="image">
            s
        </div>
    </div>
    <div id="nav">
        <div id="search">
            <img src="assets/images/mobile-search.png"/> 
        </div>
        <div id="account">
            <img src="assets/images/mobile-account.png"/> 
        </div>
        <div id="menu">
            <img src="assets/images/mobile-menu.png"/> 
        </div>
    </div>

当我调整窗口大小时,图像没有调整大小。 实现此目的的正确 CSS 语法是什么?

谢谢:)

最佳答案

max-width 应用于您的图像。

img {
    max-width: 100%;
}

http://jsfiddle.net/VBHhD/

我也会使用无序列表进行导航,但那只是我。

关于html - 响应图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17762957/

相关文章:

html, body 高度 100%

html - 为什么 wordpress 小部件会在移动 View 中截断部分网站?

html - 如何在页面上水平滚动

html - 背景颜色问题

html - 在内容上方显示 flash

html - Twitter Bootstrap 的图标 <i ...> 是如何工作的?

javascript - flex 布局 : show first element when two child elements are in the same row

html - 如何在同一行对齐两列内容

html - 我可以使用不存在的 CSS 类吗?

javascript - 使用 setTimeout 更改不透明度