简体   繁体   English

无法删除图像上的边框-CSS

[英]Cannot remove borders on images - css

I'm making a simple game for my coding course and have been stumped by this strange outline around my images. 我正在为我的编码课程制作一个简单的游戏,但被图像周围这个奇怪的轮廓所困扰。 At first I thought it was Bootstrap 3, but when I plugged the bare bones into a jsfiddle I've got the same outline. 起初我以为是Bootstrap 3,但是当我将裸露的骨头插入jsfiddle时,我得到了相同的轮廓。 Note that this is not the thumbnail border that gets set in thumbnail images. 请注意,这不是在缩略图图像中设置的缩略图边框。 I've thought about overwriting some border @ rule but haven't a clue as to what to try. 我曾考虑过覆盖一些边界@规则,但不知道该怎么做。

I've redone the images thinking this might be some artifact of Inkscape, but nope. 我已经重做了图像,以为这可能是Inkscape的某些伪像,但没有。 Any help in either removing the border or making it transparent would be appreciated. 删除边框或使其透明的任何帮助将不胜感激。

css, note the commented out attempts: CSS,请注意已注释掉的尝试:

#tommy img {        
    background: url(http://s32.postimg.org/4fdqh7dxh/tommy200.png); 
    height: 200px;
    width: 200px;      
  /*
  border: transparent !important;
  background: transparent;
  border-width: 0 !important;
  border: none !important;
  border: none;
  border: 0px;
  border-color: #7A45D2 !important; attempt to at least affect the darn thing.
  */
  }

and the bit of html: 和HTML的一点:

<div id="tommy" class= "theGroup player-up">
<p>Tommy</p><img>
</div>

the jsfiddle is here: fiddle jsfiddle在这里: 小提琴

HTML: HTML:

<div id="tommy" class= "theGroup player-up">
<p>Tommy</p><img src="http://s32.postimg.org/4fdqh7dxh/tommy200.png">
</div>

CSS: CSS:

#tommy img {        
    height: 200px;
    width: 200px;
  }

The border is coming from you using an img tag without a src specified and the background set as an image. 边框是使用img标签来自您的,而img标签未指定src且背景设置为图像。 There are two ways you could fix this: 有两种方法可以解决此问题:

1) Keep setting the image via the background url, but use a different element (probably a div). 1)继续通过背景网址设置图片,但使用其他元素(可能是div)。

HTML: HTML:

<div id="tommy" class= "theGroup player-up">
  <p>Tommy</p>
  <div/>
</div>

CSS: CSS:

#tommy div {        
  background: url(http://s32.postimg.org/4fdqh7dxh/tommy200.png);   
  height: 200px;
  width: 200px;
}

2) Keep using an img tag, but set the image via the src attribute instead of the background. 2)继续使用img标签,但通过src属性而不是背景设置图像。

HTML: HTML:

<div id="tommy" class= "theGroup player-up">
  <p>Tommy</p>
  <img src="http://s32.postimg.org/4fdqh7dxh/tommy200.png"/>
</div>

CSS: CSS:

#tommy img {        
  height: 200px;
  width: 200px;
}

Create a transparent gif and save it in your img folder. 创建一个透明的gif并将其保存在您的img文件夹中。 Then use this code. 然后使用此代码。 Works like a charm, gone are the ugly borders. 作品像魅力,丑陋的边界消失了。

<div>
    <img src="img/transparent.gif" id="tommy" class="theGroup player-up">
    <p>Tommy</p>
</div>

#tommy {
    background: url(http://s32.postimg.org/4fdqh7dxh/tommy200.png);
    height: 200px;
    width: 200px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM