css - 图片的宽度发生变化而高度却没有相应变?
怪我咯
怪我咯 2017-04-17 14:43:32
[HTML讨论组]

图片高度没有出现相应的变化

HTML

  <h2 class="news__title">Latest news <a href="#" class="news__more">+ more</a></h2>
          <ul>
            <li class="snippet">
              <img class="snippet__thumbnail" src="images/dog.jpg" alt="picture of a girl with a large, stuffed dog toy">
              <h3 class="snippet__title"><a href="#">Gastropub distillery Marfa farm-to-table</a></h3>
              <p class="snippet__description">Gastropub distillery Marfa farm-to-table, Etsy Truffaut fingerstache.
              Squid lomo Kickstarter art party cronut scenester. Organic raw denim Vice keffiyeh four loko. Squid lomo Kickstarter art party cronut scenester. Organic raw denim Vice keffiyeh four loko.Vice keffiyeh four loko. Squid lomo Kickstarter art party cronut scenester. Organic raw denim Vice keffiyeh four loko.Vice keffiyeh four loko. Squid lomo Kickstarter art party cronut scenester. Organic raw denim Vice keffiyeh four loko.
              </p>
            </li>

CSS

.snippet__thumbnail > img {
    width: 100;
}

.snippet {
    display: flex;
    flex-wrap: wrap;
}

.snippet__thumbnail {
    order: 1;
    width: 30%;
}

.snippet__title {
    order: 0;
    width: 100%;
    margin: 0 0 0.5em;
}

.snippet__description {
    order: 2;
    max-width: 70%;
    margin: 0;
    padding: 0 0 0 1em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
}

疑惑

为什么图片的高度不会随着宽度一起变化?
理论效果应该如此:

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
怪我咯

1 > 是直接后代元素选择器(子选择器) 所以第一个样式是无效的;
2 正常情况下给图片设置宽度,高度会成比例调整;
3 这种问题最好借助http://codepen.io/ ,这样方便别人排查问题。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号