-
Notifications
You must be signed in to change notification settings - Fork 3.3k
第 60 题:已知如下代码,如何修改才能让图片宽度为 300px ?注意下面代码不可修改。 #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
|
这种也可以 |
比较硬核的是再加个 |
|
来个有点局限的, 只适用于图片原始尺寸小于300的才行 <div style="display: flex;width:300px;height: 300px">
<img src="./down.png" style="width:480px !important" />
</div> |
获取当前dom元素,更改css样式。css属性按楼上发的改都可以。 |
一、
二、
|
|
|
max-width可以覆盖掉!important |
max-width: 300px; |
总结一下吧: |
用max-width去覆盖挺好的。 |
总结:
除了最后的一行不可以,因为内联样式的优先级比内部样式优先级高 |
1 max-width:300 |
1.使important样式不生效,display: inline,position: absolute,left...right...,或者max-width:300px; |
max-width:300px; |
来个奇淫技巧
|
来个奇淫技巧
利用CSS动画的样式优先级高于!important的特性 |
很简单啊 |
box-sizing: border-box |
document.querySelector('img').style.cssText='width:300px;' 为什么都没有用js的。。。 |
总结一下 |
Chrome可以,Firefox不支持 |
外面套个盒子 然后overflow: hidden? |
同时设置max-width和min-width为300px即可 |
<img src="1.jpg" style="width:480px!important;”> |
我只知道如果实际项目中如果发生了这种事,好的解决办法是把行内style改成class写法 |
|
父元素width: 300px; overflow:hidden; 可以吗哈哈 |
<style>
img {
width: 300px !important;
}
</style> 利用css优先级叠加原理 |
额 我测试了下 Chrome不可以。 |
good |
document.querySelector('img').style.width = '300px' |
4、给图片设置zoom: 0.625,这个我在vue的scss文件中写的,在Chrome浏览器没有生效。 |
补充一个:利用clip或clip-path进行裁剪。
|
|
img {
box-sizing: border-box;
padding-left: 180px;
} |
来点奇葩的 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img[style="width:480px!important;"] {
display: none;
}
</style>
</head>
<body>
<img src="1.jpg" style="width:480px!important;">
<img src="1.jpg" style="width:300px">
</body>
</html> |
The text was updated successfully, but these errors were encountered: