>  기사  >  웹 프론트엔드  >  img[src=""] img에 경로가 없을 때 회색 테두리를 제거하는 방법에 대한 자세한 설명

img[src=""] img에 경로가 없을 때 회색 테두리를 제거하는 방법에 대한 자세한 설명

高洛峰
高洛峰원래의
2017-03-28 10:25:224511검색

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.마진집중 솔루션

<!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;
}

위 내용은 img[src=""] img에 경로가 없을 때 회색 테두리를 제거하는 방법에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.