Removing the image border in Chrome/IE9

后端 未结 18 1859
长情又很酷
长情又很酷 2020-11-27 04:28

I am trying to get rid of the thin border that appears for every image in Chrome & IE9. I have this CSS:

outline: none;
border: none;

U

相关标签:
18条回答
  • 2020-11-27 05:18

    That happens because you are using an img tag with no src attribute. The solution is puting the image into a div. Something like that:

    <style>
             div#uno{
                display:block;
                width: 351px;
                height: 500px;
                background: url(especificaciones1.png) no-repeat;
    
             }
             div#dos{
                display:block;
                width: 612px;
                height: 500px;
                background: url(especificaciones2.png) no-repeat;
             }
    
    </style>
    <div class="especificaciones">
       <div id="uno" class="imag1"></div>
       <div id="dos" class="imag2"></div>
    </div>
    
    0 讨论(0)
  • 2020-11-27 05:20

    the solution is to set the outline style to none (i.e.) outline:none, it's work with Me

    0 讨论(0)
  • 2020-11-27 05:23

    For anyone who wants to get rid of the border when the src is empty or there is no src just use this style:

    IMG[src=''], IMG:not([src])      {opacity:0;}
    

    It will hide the IMG tag completely until you add a src

    0 讨论(0)
  • 2020-11-27 05:24

    It's a Chrome bug, ignoring the "border:none;" style.

    Let's say you have an image "download-button-102x86.png" which is 102x86 pixels in size. In most browsers, you would reserve that size for its width and height, but Chrome just paints a border there, no matter what you do.

    So you trick Chrome into thinking that there is nothing there - size of 0px by 0px, but with exactly the right amount of "padding" to allow for the button. Here is a CSS id block that I am using to accomplish this...

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

    Voila! Works everywhere and gets rid of the outline/border in Chrome.

    0 讨论(0)
  • 2020-11-27 05:24

    I had a similar problem when displaying a .png-image in a div-tag. A thin (1 px I think) black line was rendered on the side of the image. To fix it, I had to add the following CSS style: box-shadow: none;

    0 讨论(0)
  • 2020-11-27 05:26

    same as what @aaron-coding and @randy-king had - but just a more generic one to hide image border before they are loaded (i.e. with lazy-load.js or something

    (apparently I can't do a code block in my original comment)

    .lazy-load-borderFix {
      display: block;
      width: 1px !important;
      height: 1px !important;
      outline: none;
      padding: 0px;
      margin: -4px;
      background-image:none !important;
      background-repeat:no-repeat;
    }
    
    0 讨论(0)
提交回复
热议问题