"일꾼이 일을 잘하려면 먼저 도구를 갈고 닦아야 한다." - 공자, 『논어』.
첫 장 > 프로그램 작성 > 图片在Chrome中为何仍有边框?`border: none;`无效解决方案

图片在Chrome中为何仍有边框?`border: none;`无效解决方案

2025-05-01에 게시되었습니다
검색:349

Why Does My Image Still Have a Border in Chrome, Even With `border: none;`?

Removing the Image Border in Chrome

One frequent issue encountered when working with images in Chrome and IE9 is the appearance of a persistent thin border around the image, despite specifying 'outline: none;' and 'border: none;' in the CSS. To resolve this issue, consider the following approaches:

Chrome Bug Circumvention

Chrome has a known bug that ignores the "border: none;" style. To work around this, use the following CSS id block to create a transparent area with the desired padding, effectively tricking Chrome into thinking there's no image:

#dlbutn {
    display: block;
    width: 0px;
    height: 0px;
    outline: none;
    padding: 43px 51px 43px 51px;
    margin: 0 auto 5px auto;
    background-image: url(/images/download-button-102x86.png);
    background-repeat: no-repeat;
}

Duplication of Styles

Another solution is to duplicate the border and outline removal styles, both in CSS and via jQuery's border=0 attribute. This redundant approach can sometimes force the browser to apply the styles correctly.

img, a img {
    outline: none;
    border: none;
}
$(document).ready(function(){
    $('img').attr('border', '0');
});

Additional Considerations

Ensure that the dimensions of the image file match the specified width and height in CSS. If there is a discrepancy, the browser may add a border to compensate.

By implementing these solutions, you can effectively remove the unwanted image border in Chrome and IE9, providing a consistent and visually pleasing appearance for your web pages.

최신 튜토리얼 더>

부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.

Copyright© 2022 湘ICP备2022001581号-3