头闻号

佛山市宽裕不锈钢有限公司

方矩管|不锈钢材

首页 > 新闻中心 > 科技常识:CSS 实现的图片宽高自适应固定边框
科技常识:CSS 实现的图片宽高自适应固定边框
发布时间:2023-02-01 10:46:30        浏览次数:5        返回列表

今天小编跟大家讲解下有关CSS 实现的图片宽高自适应固定边框 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了有关CSS 实现的图片宽高自适应固定边框 的相关资料,希望小伙伴们看了有所帮助。

关键在于:max-width:780px;以及下面那行。

固定像素适应:

以下是引用片段:<style type="text/css"> <!-- body { font-size: 12px; text-align: center; margin: 0px; padding: 0px; } #pic{ margin:0 auto; width:800px; padding:0; border:1px solid #333; } #pic img{ max-width:780px; width:expression(document.body.clientWidth > 780? "780px": "auto" );border:1px dashed #000; } --&gt; </style> </head> <body> <div id="pic"> <img src=http://xyrl.com/skin/7ke/image/nopic.gif </div> </body> </html>

百分比适应:以下是引用片段:<style type="text/css"> <!-- body { font-size: 12px; text-align: center; margin: 0px; padding: 0px; } #pic{ margin:0 auto; width:800px; padding:0; border:1px solid #333; } #pic img{ max-width:780px; width:expression(document.body.clientWidth>document.getElementById("pic").scrollWidth*9/10? "780px": "auto" ); border:1px dashed #000; } --&gt; </style> </head> <body> <div id="pic"> <img src=http://xyrl.com/skin/7ke/image/nopic.gif </div> </body> </html>

来源:爱蒂网