【问题标题】:Relatively created button and image causes creating an additional frame for image. Html相对创建的按钮和图像会导致为图像创建额外的框架。 html
【发布时间】:2020-08-24 21:16:51
【问题描述】:

我无法移除边框。

这是我的代码:

<mat-grid-list cols="2" rowHeight="2:1">
   <mat-grid-tile>
     <button mat-raised-button>1</button>
     <img id="image-diamond"/>
   </mat-grid-tile>
</mat-grid-list>

还有css:

button{
width: 80%;
height: 70%; 
padding: 20px 40px;
font-size: 32px;
font-family: Arial, sans-serif;
display: inline-block;
background: linear-gradient(to right, #070600 0%, #f7d931f3 50%, #fae901f3 50%, #f7ef8bf3 100%);
background-size: 200% 100%;
background-position: 100% 0;
transition: background-position 0.3s;
opacity: 70%;
border: 1px solid #f00;
position: relative;
z-index: 1;
}

#image-diamond{
height: 20%;
width: 10%;
margin-top: 35%;
position: relative;
z-index: 2;
right: 5%;
overflow:hidden; 
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}

并且图像有额外的边框。设置背景透明或边框没有任何变化。在 0px 上设置粗 也没有改变任何东西,当创建边框时,第二个边框仍然可见,我可以看到 2 个边框。

当我设置border: 2px solid red; 时,我可以看到白色和红色边框。

【问题讨论】:

  • 可能是轮廓。尝试将大纲设置为无,如下所示:大纲:无;
  • @carlos.gmz 不幸的是,它没有帮助。
  • 如果需要去除黑红边框,那么看我的解决方案
  • 我自己测试过,没有白色边框。可能会改变测试条件,例如浏览器。

标签: html css


【解决方案1】:

您无法更改它,这是默认浏览器行为。

就像当图像具有 invalid src 并且浏览器显示“损坏的图像”图标时,如果图像具有 no src 浏览器显示显示图像位置的边框。有关详细信息,请参阅:

您似乎想要设置背景图片 - 为此,您不使用img 元素,您可以使用其他一些元素,例如div,例如

<div class="image-with-background"></div>

.image-background {
  height: 100px;
  width: 100px;
  background-image: url("https://lorempixel.com/output/technics-q-c-600-400-1.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

请看下面的例子:

.empty-img {
  height: 100px;
  width: 100px;
}

.image-background {
  height: 100px;
  width: 100px;
  overflow: hidden;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

.background-url {
  background-image: url("https://lorempixel.com/output/technics-q-c-600-400-1.jpg");
}
<p>A "broken image" img element with no src: </p>
<img class="empty-img" />

<p>A div element tag with no backgrouund image, but using your background CSS -> no border: </p>
<div class="image-background"></div>

<p>A div element tag with a background image: </p>
<div class="image-background background-url"></div>

【讨论】:

    【解决方案2】:

    试试这个

    img {
      text-indent: -999px;
    }
    

    【讨论】:

    • 不幸的是,它没有帮助。
    • 你用important试过了吗,我也遇到过类似的问题,我就是这样解决的
    • 还是没用。
    【解决方案3】:

    使用 border:none;

    都喜欢

       button{
    border:none;
    }
        
    #image-diamond{
    border:none;
    }
    

    【讨论】:

    • 我正在尝试所有有边框的东西。这不是边界。
    • 移除边框:1px solid #f00;来自按钮的 css 和边框:0;然后添加边框:无;它将删除您的按钮边框。 #image-diamond 也是如此
    • 这段代码在使用border:none时工作正常;你可以分享你的 html 文件问题将是你的 html 的另一面
    【解决方案4】:

    button标签中添加border: 0;outline: none; - (去除黑色边框)到css

    button{
    width: 80%;
    height: 70%; 
    padding: 20px 40px;
    font-size: 32px;
    font-family: Arial, sans-serif;
    display: inline-block;
    background: linear-gradient(to right, #070600 0%, #f7d931f3 50%, #fae901f3 50%, #f7ef8bf3 100%);
    background-size: 200% 100%;
    background-position: 100% 0;
    transition: background-position 0.3s;
    opacity: 70%;
    border: 1px solid #f00;
    position: relative;
    z-index: 1;
    border: 0;
    outline: none;
    }
    
    #image-diamond{
    height: 20%;
    width: 10%;
    margin-top: 35%;
    position: relative;
    z-index: 2;
    right: 5%;
    overflow:hidden; 
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    }
    <mat-grid-list cols="2" rowHeight="2:1">
       <mat-grid-tile>
         <button mat-raised-button>1</button>
         <img id="image-diamond"/>
       </mat-grid-tile>
    </mat-grid-list>

    【讨论】:

    • 我正在尝试从图像中删除白色边框。不是来自按钮。
    • 我把它熄灭了,看来-ibb.co/JBq3PJz!在黑色背景上。但是border: 0 帮我删除它!
    • 你知道为什么我将边框设置为 0 不会改变任何东西吗?
    • 我可以假设这是一种具有更高优先级的样式重叠。尝试输入border: 0!important。如果没有帮助,请在此处留下指向该网站的链接..
    • ...或者它可能是一个伪元素::before::after
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多