[英]Remove Image Height and width, when use “clip:rect” in CSS : HTML
我在html中使用clip:rect()来重新调整大小的图像,但是当我调整图像大小并检查它时,它显示其原始高度和宽度。 我还描述了我想做的事情。
我还会粘贴该图片的屏幕截图。
图像(屏幕宽度= 1024)
图像(屏幕宽度= 768)旋转768 * 1024
但是当我检查图像@ width = 768时,它会显示它的原始高度和宽度
所以我无法完美地放置我的其他代码。
这是我的代码。
HTML
<!DOCTYPE html>
<html>
<head>
<style>
@media screen and (max-width: 1024px){
img
{
position:absolute;
clip:rect(0px,600px,450px,0px);
}
}
@media screen and (max-width: 768px){
img
{
position:absolute;
clip:rect(80px,400px,400px,190px);
}
}
</style>
</head>
<body>
<img src="sunset-splash-canada_63712_600x450.jpg"/>
</body>
</html>
使用@BASarat代码后
如果您使用剪辑和位置绝对,最好的方法是在裁剪后重新定位具有负顶部和左侧值的图像。
下面介绍了如何操作: http : //css-tricks.com/css-sprites-with-inline-images/
它将继续以检查方式显示。 最好的办法是设置图像宽度/高度以及剪裁。
您可以使用jquery或直接css:
@media screen and (max-width: 1024px){
img
{
position:absolute;
width: 600px; /* what ever height / width you want */
height:450px;
clip:rect(0px,600px,450px,0px);
}
}
@media screen and (max-width: 768px){
img
{
position:absolute;
width: 320px; /* what ever height / width you want */
height: 210px;
clip:rect(80px,400px,400px,190px);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.