removing img border












7















I have a problem with the img border. I am using the following code for all my images, but the border is not going away. Can someone tell me the correct way to remove the img border?



   <div class="mosaic-overlay">
<img class="cover1"></div>

.cover1 {width:300px;height:185px;
float:left;background: url('/img/cover.jpg') 0px 0px;
border:0;}


Many thanks.



Erik










share|improve this question




















  • 2





    this might be a silly question, but why are you using an img tag with a background image instead of a source? If you used a div tag you wouldn't have the border issue is all

    – lnrbob
    Jun 27 '11 at 19:44













  • make sure you close the img tag with />

    – joakimdahlstrom
    Jun 27 '11 at 20:13











  • @joakim: Closing the img tag is unnecessary (even forbidden) in HTML 4, and in fact can cause rendering issues in older browsers. Only close img tags if you're writing XHTML...and frankly, you shouldn't be writing XHTML either -- it usually ends up as tag soup, because hardly anyone actually gets it right.

    – cHao
    Jun 27 '11 at 23:29


















7















I have a problem with the img border. I am using the following code for all my images, but the border is not going away. Can someone tell me the correct way to remove the img border?



   <div class="mosaic-overlay">
<img class="cover1"></div>

.cover1 {width:300px;height:185px;
float:left;background: url('/img/cover.jpg') 0px 0px;
border:0;}


Many thanks.



Erik










share|improve this question




















  • 2





    this might be a silly question, but why are you using an img tag with a background image instead of a source? If you used a div tag you wouldn't have the border issue is all

    – lnrbob
    Jun 27 '11 at 19:44













  • make sure you close the img tag with />

    – joakimdahlstrom
    Jun 27 '11 at 20:13











  • @joakim: Closing the img tag is unnecessary (even forbidden) in HTML 4, and in fact can cause rendering issues in older browsers. Only close img tags if you're writing XHTML...and frankly, you shouldn't be writing XHTML either -- it usually ends up as tag soup, because hardly anyone actually gets it right.

    – cHao
    Jun 27 '11 at 23:29
















7












7








7


1






I have a problem with the img border. I am using the following code for all my images, but the border is not going away. Can someone tell me the correct way to remove the img border?



   <div class="mosaic-overlay">
<img class="cover1"></div>

.cover1 {width:300px;height:185px;
float:left;background: url('/img/cover.jpg') 0px 0px;
border:0;}


Many thanks.



Erik










share|improve this question
















I have a problem with the img border. I am using the following code for all my images, but the border is not going away. Can someone tell me the correct way to remove the img border?



   <div class="mosaic-overlay">
<img class="cover1"></div>

.cover1 {width:300px;height:185px;
float:left;background: url('/img/cover.jpg') 0px 0px;
border:0;}


Many thanks.



Erik







css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 27 '11 at 19:38









skaffman

340k85736723




340k85736723










asked Jun 27 '11 at 19:37









ErikErik

2,6472357102




2,6472357102








  • 2





    this might be a silly question, but why are you using an img tag with a background image instead of a source? If you used a div tag you wouldn't have the border issue is all

    – lnrbob
    Jun 27 '11 at 19:44













  • make sure you close the img tag with />

    – joakimdahlstrom
    Jun 27 '11 at 20:13











  • @joakim: Closing the img tag is unnecessary (even forbidden) in HTML 4, and in fact can cause rendering issues in older browsers. Only close img tags if you're writing XHTML...and frankly, you shouldn't be writing XHTML either -- it usually ends up as tag soup, because hardly anyone actually gets it right.

    – cHao
    Jun 27 '11 at 23:29
















  • 2





    this might be a silly question, but why are you using an img tag with a background image instead of a source? If you used a div tag you wouldn't have the border issue is all

    – lnrbob
    Jun 27 '11 at 19:44













  • make sure you close the img tag with />

    – joakimdahlstrom
    Jun 27 '11 at 20:13











  • @joakim: Closing the img tag is unnecessary (even forbidden) in HTML 4, and in fact can cause rendering issues in older browsers. Only close img tags if you're writing XHTML...and frankly, you shouldn't be writing XHTML either -- it usually ends up as tag soup, because hardly anyone actually gets it right.

    – cHao
    Jun 27 '11 at 23:29










2




2





this might be a silly question, but why are you using an img tag with a background image instead of a source? If you used a div tag you wouldn't have the border issue is all

– lnrbob
Jun 27 '11 at 19:44







this might be a silly question, but why are you using an img tag with a background image instead of a source? If you used a div tag you wouldn't have the border issue is all

– lnrbob
Jun 27 '11 at 19:44















make sure you close the img tag with />

– joakimdahlstrom
Jun 27 '11 at 20:13





make sure you close the img tag with />

– joakimdahlstrom
Jun 27 '11 at 20:13













@joakim: Closing the img tag is unnecessary (even forbidden) in HTML 4, and in fact can cause rendering issues in older browsers. Only close img tags if you're writing XHTML...and frankly, you shouldn't be writing XHTML either -- it usually ends up as tag soup, because hardly anyone actually gets it right.

– cHao
Jun 27 '11 at 23:29







@joakim: Closing the img tag is unnecessary (even forbidden) in HTML 4, and in fact can cause rendering issues in older browsers. Only close img tags if you're writing XHTML...and frankly, you shouldn't be writing XHTML either -- it usually ends up as tag soup, because hardly anyone actually gets it right.

– cHao
Jun 27 '11 at 23:29














4 Answers
4






active

oldest

votes


















16














It's the default "special" border that appears in some browsers when an img element has no src attribute, or a src attribute pointing to an image that does not exist.



For example, look at this in IE9: http://jsfiddle.net/SdbNE/



A common workaround is to set the src to a blank.gif file:



<img class="cover1" src="blank.gif" />


Or, just use a div instead?



<div class="cover1"></div>





share|improve this answer































    11














    Set your <img> source to transparent.






    #img {
    width:150px;
    height:auto;
    background: url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvF4WdZJSA4MkWJXClae4eCvSdk87c5Ok63fgxBxVyR6aHB2Ju_A) no-repeat center;
    background-size: cover;
    }

    <img id="img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA" />





    Notice the img src is blank and has no border but CSS sets the background: url()




    transparent src: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA




    Credit CSS Tricks






    share|improve this answer

































      3














      it's the border of alt text, try






      img {
      text-indent: -999px;
      }








      share|improve this answer































        0














        I use that java script trick, I initialise all images sources with a blank image.



        onload=
        var myImagesList =
        document.getElementById("element where the images are").getElementsByTagName("img");

        for (i=1;i < myImagesList.length-1;i++)
        {
        myImagesList[i].src = ".../blank image";
        }





        share|improve this answer

























          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6497992%2fremoving-img-border%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          16














          It's the default "special" border that appears in some browsers when an img element has no src attribute, or a src attribute pointing to an image that does not exist.



          For example, look at this in IE9: http://jsfiddle.net/SdbNE/



          A common workaround is to set the src to a blank.gif file:



          <img class="cover1" src="blank.gif" />


          Or, just use a div instead?



          <div class="cover1"></div>





          share|improve this answer




























            16














            It's the default "special" border that appears in some browsers when an img element has no src attribute, or a src attribute pointing to an image that does not exist.



            For example, look at this in IE9: http://jsfiddle.net/SdbNE/



            A common workaround is to set the src to a blank.gif file:



            <img class="cover1" src="blank.gif" />


            Or, just use a div instead?



            <div class="cover1"></div>





            share|improve this answer


























              16












              16








              16







              It's the default "special" border that appears in some browsers when an img element has no src attribute, or a src attribute pointing to an image that does not exist.



              For example, look at this in IE9: http://jsfiddle.net/SdbNE/



              A common workaround is to set the src to a blank.gif file:



              <img class="cover1" src="blank.gif" />


              Or, just use a div instead?



              <div class="cover1"></div>





              share|improve this answer













              It's the default "special" border that appears in some browsers when an img element has no src attribute, or a src attribute pointing to an image that does not exist.



              For example, look at this in IE9: http://jsfiddle.net/SdbNE/



              A common workaround is to set the src to a blank.gif file:



              <img class="cover1" src="blank.gif" />


              Or, just use a div instead?



              <div class="cover1"></div>






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 27 '11 at 20:12









              thirtydotthirtydot

              186k38335316




              186k38335316

























                  11














                  Set your <img> source to transparent.






                  #img {
                  width:150px;
                  height:auto;
                  background: url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvF4WdZJSA4MkWJXClae4eCvSdk87c5Ok63fgxBxVyR6aHB2Ju_A) no-repeat center;
                  background-size: cover;
                  }

                  <img id="img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA" />





                  Notice the img src is blank and has no border but CSS sets the background: url()




                  transparent src: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA




                  Credit CSS Tricks






                  share|improve this answer






























                    11














                    Set your <img> source to transparent.






                    #img {
                    width:150px;
                    height:auto;
                    background: url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvF4WdZJSA4MkWJXClae4eCvSdk87c5Ok63fgxBxVyR6aHB2Ju_A) no-repeat center;
                    background-size: cover;
                    }

                    <img id="img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA" />





                    Notice the img src is blank and has no border but CSS sets the background: url()




                    transparent src: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA




                    Credit CSS Tricks






                    share|improve this answer




























                      11












                      11








                      11







                      Set your <img> source to transparent.






                      #img {
                      width:150px;
                      height:auto;
                      background: url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvF4WdZJSA4MkWJXClae4eCvSdk87c5Ok63fgxBxVyR6aHB2Ju_A) no-repeat center;
                      background-size: cover;
                      }

                      <img id="img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA" />





                      Notice the img src is blank and has no border but CSS sets the background: url()




                      transparent src: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA




                      Credit CSS Tricks






                      share|improve this answer















                      Set your <img> source to transparent.






                      #img {
                      width:150px;
                      height:auto;
                      background: url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvF4WdZJSA4MkWJXClae4eCvSdk87c5Ok63fgxBxVyR6aHB2Ju_A) no-repeat center;
                      background-size: cover;
                      }

                      <img id="img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA" />





                      Notice the img src is blank and has no border but CSS sets the background: url()




                      transparent src: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA




                      Credit CSS Tricks






                      #img {
                      width:150px;
                      height:auto;
                      background: url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvF4WdZJSA4MkWJXClae4eCvSdk87c5Ok63fgxBxVyR6aHB2Ju_A) no-repeat center;
                      background-size: cover;
                      }

                      <img id="img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA" />





                      #img {
                      width:150px;
                      height:auto;
                      background: url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvF4WdZJSA4MkWJXClae4eCvSdk87c5Ok63fgxBxVyR6aHB2Ju_A) no-repeat center;
                      background-size: cover;
                      }

                      <img id="img" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA" />






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jan 6 '16 at 20:38

























                      answered Jul 14 '15 at 23:05









                      neaumusicneaumusic

                      4,99122648




                      4,99122648























                          3














                          it's the border of alt text, try






                          img {
                          text-indent: -999px;
                          }








                          share|improve this answer




























                            3














                            it's the border of alt text, try






                            img {
                            text-indent: -999px;
                            }








                            share|improve this answer


























                              3












                              3








                              3







                              it's the border of alt text, try






                              img {
                              text-indent: -999px;
                              }








                              share|improve this answer













                              it's the border of alt text, try






                              img {
                              text-indent: -999px;
                              }








                              img {
                              text-indent: -999px;
                              }





                              img {
                              text-indent: -999px;
                              }






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Sep 22 '15 at 11:40









                              whatifwhatif

                              491




                              491























                                  0














                                  I use that java script trick, I initialise all images sources with a blank image.



                                  onload=
                                  var myImagesList =
                                  document.getElementById("element where the images are").getElementsByTagName("img");

                                  for (i=1;i < myImagesList.length-1;i++)
                                  {
                                  myImagesList[i].src = ".../blank image";
                                  }





                                  share|improve this answer






























                                    0














                                    I use that java script trick, I initialise all images sources with a blank image.



                                    onload=
                                    var myImagesList =
                                    document.getElementById("element where the images are").getElementsByTagName("img");

                                    for (i=1;i < myImagesList.length-1;i++)
                                    {
                                    myImagesList[i].src = ".../blank image";
                                    }





                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      I use that java script trick, I initialise all images sources with a blank image.



                                      onload=
                                      var myImagesList =
                                      document.getElementById("element where the images are").getElementsByTagName("img");

                                      for (i=1;i < myImagesList.length-1;i++)
                                      {
                                      myImagesList[i].src = ".../blank image";
                                      }





                                      share|improve this answer















                                      I use that java script trick, I initialise all images sources with a blank image.



                                      onload=
                                      var myImagesList =
                                      document.getElementById("element where the images are").getElementsByTagName("img");

                                      for (i=1;i < myImagesList.length-1;i++)
                                      {
                                      myImagesList[i].src = ".../blank image";
                                      }






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Jan 19 at 13:36









                                      Harsh Patel

                                      1,69111229




                                      1,69111229










                                      answered Jan 19 at 13:07









                                      Adel Ben ahmedAdel Ben ahmed

                                      13




                                      13






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6497992%2fremoving-img-border%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Homophylophilia

                                          Updating UILabel text programmatically using a function

                                          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage