[英]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.