詳解img[src=""] img無路徑情況下,灰色邊框去除解決方案

來源:互聯網
上載者:User
img[src=""] img標籤無路徑情況下,灰色邊框去除解決方案

1.Js解決辦法

<html>    <head>        <meta charset="UTF-8">        <title></title>    </head>    <body>    <img src="error.jpg" onerror="whenError(this)">    </body>    <script>    function whenError(a){        a.onerror=null;        a.src='path_default.jpg';        console.log('圖片出錯的時候調用預設的圖片');    }    </script></html>

2.絕對位置聚焦解決方案

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>absolute聚焦解決方案</title>    </head>    <body>        <p class="container-img">            <img class="common-icon login-icon" src="" width="38" height="38">        </p>    </body>    <style type="text/css">        .container-img {            position: relative;            display: inline-block;            width: 36px;            height: 36px;            overflow: hidden;                    }        .container-img img {            position: absolute;            top: -1px;            right: -1px;            background: url(img/common-icon.png) no-repeat;            background-position: 0px 1px;        }    </style></html>

3.margin聚焦解決辦法

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>margin聚焦解決方案</title>    </head>    <body>        <p class="container-img">            <img class="common-icon login-icon"  src="" width="38" height="38">        </p>    </body>    <style type="text/css">        .container-img {            display: inline-block;            width: 36px;            height: 36px;            overflow: hidden;        }        .common-icon {            display: inline-block;            background: url(img/common-icon.png) no-repeat;            background-position: 0px 1px;            margin: -1px;        }    </style></html>

4.css隱藏

img[src=""]{opacity: 0;}
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.