zoukankan      html  css  js  c++  java
  • 关于img标签浏览器自带的边框,清除边框的解决方式(即img[src=""] img无路径情况下,灰色边框去除解决方法)

    详解img[src=""] img无路径情况下,灰色边框去除解决方法

    1.Js解决办法

     1 <html>
     2     <head>
     3         <meta charset="UTF-8">
     4         <title></title>
     5     </head>
     6     <body>
     7     <img src="error.jpg" onerror="whenError(this)">
     8     </body>
     9     <script>
    10     function whenError(a){
    11         a.onerror=null;
    12         a.src='path_default.jpg';
    13         console.log('图片出错的时候调用默认的图片');
    14     }
    15     </script>
    16 </html>

    2.绝对定位聚焦解决方案

     1 <!DOCTYPE html>
     2 <html>
     3  
     4     <head>
     5         <meta charset="UTF-8">
     6         <title>absolute聚焦解决方案</title>
     7     </head>
     8  
     9     <body>
    10         <p class="container-img">
    11             <img class="common-icon login-icon" src="" width="38" height="38">
    12         </p>
    13  
    14     </body>
    15     <style type="text/css">
    16         .container-img {
    17             position: relative;
    18             display: inline-block;
    19             width: 36px;
    20             height: 36px;
    21             overflow: hidden;
    22              
    23         }
    24         .container-img img {
    25             position: absolute;
    26             top: -1px;
    27             right: -1px;
    28             background: url(img/common-icon.png) no-repeat;
    29             background-position: 0px 1px;
    30         }
    31     </style>
    32  
    33 </html>

    3.margin聚焦解决办法

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title>margin聚焦解决方案</title>
     6     </head>
     7  
     8     <body>
     9         <p class="container-img">
    10             <img class="common-icon login-icon"  src="" width="38" height="38">
    11         </p>
    12  
    13     </body>
    14     <style type="text/css">
    15         .container-img {
    16             display: inline-block;
    17             width: 36px;
    18             height: 36px;
    19             overflow: hidden;
    20         }
    21         .common-icon {
    22             display: inline-block;
    23             background: url(img/common-icon.png) no-repeat;
    24             background-position: 0px 1px;
    25             margin: -1px;
    26         }
    27     </style>
    28 </html>

    4.css隐藏

    1 img[src=""],img:not([src]){
    2     opacity: 0;
    3     border:none;
    4     visibility: hidden;
    5     max- none;
    6 }
  • 相关阅读:
    Linux下修改时间时区的方法介绍
    IIS启用GZip压缩的详细教程(图文)
    jquery定时器的简单代码
    IIS启用GZIP压缩js、css无效的原因及解决方法
    python批量导出导入MySQL用户的方法
    mysql执行计划介绍
    js+json用表格实现简单网站左侧导航
    React Native 二维码扫描组件
    mysql如何修改开启允许远程连接
    react native中的聊天气泡以及timer封装成的发送验证码倒计时
  • 原文地址:https://www.cnblogs.com/weixupeng/p/9627428.html
Copyright © 2011-2022 走看看