1

I'm trying to remove gray color outline of images. I saw that that outline means error because image tags don't have source properties. but if i add src="image.jpg", hovering doesn't work.

how to fix it? so confused....

this is my code

#item1 {
  background-image: url('cushion01.jpg');
  height: 300px;
  width: 300px;
  background-repeat: no-repeat;
  background-size: cover;
}
#item1:hover {
  background-image: url('cushion-01.jpeg');
  height: 300px;
  width: 300px;
}
<div class="secondary__item" style="width: 100%; height : 850px;">
  <ul class="item-images">
    <li class="item-image">
      <img class="item" id="item1"  src="image.jpg" />
    </li>
    <li class="item-image">
      <img class="item" id="item2" />
    </li>
  </ul>
  <ul class="item-images">
    <li class="item-image">
      <img class="item" id="item3" />
    </li>
    <li class="item-image">
      <img class="item" id="item4" />
    </li>
  </ul>
</div>
RJParikh
  • 4,096
  • 1
  • 19
  • 36
Yumin Hwang
  • 159
  • 2
  • 2
  • 14

6 Answers6

1

Strange thing is that you are trying to set background to <img> tag. If I were you I'd use <div> instead. Then It would be very simple:

HTML:

    <div class= "secondary__item" style="width: 100%; height : 850px;">
        <ul class="item-images">
        <li class="item-image"><div class="item"  id="item1" ></div></li>
            <li class="item-image"><div class="item"  id="item2" ></div></li>
        </ul>
        <ul class="item-images">
            <li class="item-image"><div class="item"  id="item3" ></div></li>
            <li class="item-image"><div class="item"  id="item4" ></div></li>
        </ul>
    </div>


CSS:

.item {
height:300px;
width :300px;
background-repeat: no-repeat;
background-size : cover;

/*you can remove it*/
border: 1px solid;
}
.item:hover {
background-image: url('http://shushi168.com/data/out/114/36276270-image.png');
height:300px;
width :300px;
}

Here is a Fiddle: https://jsfiddle.net/7kzu5qcy/2/

Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38
0

Have you tried instead of using IDs to use the main identifier?

like...

.item-image IMG {
 border:none;
}
  • Considering you're using this to set a background-image and no foreground image, why don't you simply change the IMG tags to DIVS instead, do the same job, and there's no placeholder border. – Danny Carrington Nov 17 '16 at 13:06
0

Place this in your image tag

alt=""
Thielicious
  • 4,122
  • 2
  • 25
  • 35
0

Try this:

item1:hover {
    border: none !important;
    display: block;
}
fourpastmidnight
  • 4,032
  • 1
  • 35
  • 48
Pravin Vavadiya
  • 3,195
  • 1
  • 17
  • 34
0

You can apply a simple hack using margin & overflow property of CSS.

Something like this:

/* Image Container (Parent) */
.item-image {
  width: 298px;
  height: 298px;
  overflow: hidden;
}

/* Image (Child) */    
.item-image img {
  margin: -1px;
  background: #eee; /* To show the area covered by image */
}

Have a look at the snippet below (I've applied background color to image to show the image area):

#item1 {
  background-image: url('cushion01.jpg');
  height: 300px;
  width: 300px;
  background-repeat: no-repeat;
  background-size: cover;
}
#item1:hover {
  background-image: url('cushion-01.jpeg');
  height: 300px;
  width: 300px;
}

.item-image {
  width: 298px;
  height: 298px;
  overflow: hidden;
}

.item-image img {
  margin: -1px;
  background: #eee;
}
<div class="secondary__item" style="width: 100%; height : 850px;">
  <ul class="item-images">
    <li class="item-image">
      <img class="item" id="item1"  src="image.jpg" />
    </li>
    <li class="item-image">
      <img class="item" id="item2" />
    </li>
  </ul>
  <ul class="item-images">
    <li class="item-image">
      <img class="item" id="item3" />
    </li>
    <li class="item-image">
      <img class="item" id="item4" />
    </li>
  </ul>
</div>

Hope this helps!

Saurav Rastogi
  • 9,575
  • 3
  • 29
  • 41
0

I see the answer to this is given in chrome/safari display border around image.

The reason cited is <img> tag does not have proper value in src attribute.
Community
  • 1
  • 1