CSS-禁用宽度:自动 [英] CSS - disabling width: auto

查看:73
本文介绍了CSS-禁用宽度:自动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张尺寸为32 x 32(即width和height属性)的图像.但是,图像的大小默认为150 x 150.

I've got an image which is sized at 32 x 32 (i.e. the width and height attributes). However, the image remains sized at its default of 150 x 150.

看一下CSS,我可以看到父CSS文件中有一个 width:auto .当我关闭此功能时,图像将调整为32 x32.

Looking at the CSS I can see there's a width: auto in the parent CSS file. When I switch this off the image then resizes to 32 x 32.

我想在不更改父CSS文件的情况下覆盖它.我该怎么做?

I'd like to override this without altering the parent CSS file. How do I do this?

注意:我最初尝试了 width:none 这是无效的CSS.

Note: I initially tried width: none which is not valid CSS.

推荐答案

尝试将图片的最大宽度设置为不大于其父宽度.您可以将width/height设置为initial或继承,看看哪一种适合您.

Try setting the image's max-width to be no bigger than it's parent width. You can set the width/height to initial or inherit, see which one works for you.

初始:将此属性设置为其默认值.

Initial: Sets this property to its default value.

继承:从其父元素继承此属性.

Inherit: Inherits this property from its parent element.

.parent img {
   max-width: 100%;
   width: 32px;
   height: initial;
}

这篇关于CSS-禁用宽度:自动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆