在输入中使用标签标签时如何删除方形边框

问题描述 投票:0回答:1

我需要将个人资料图标与编辑图标一起放置以上传图像。我使用以下 html 和 css 来实现此目的,尝试将 border:none、outline:none 等内联样式添加到标签标签、输入标签、包含输入和标签标签的 div 标签,但边框仍然可见。

<div className="avatar-edit" >
 <input type='file' id="imageUpload"  accept=".png, .jpg, .jpeg" onChange={handleFileChange}/>
        <label htmlFor="imageUpload" ><img src={camera} /></label>
        
    </div>

  .avatar-upload .avatar-edit {
    position: absolute;
    right: 12px;
    z-index: 1;
    top: 10px;
  }
  .avatar-upload .avatar-edit input {
    display: none;
  }
  .avatar-upload .avatar-edit input + label {
    display: inline-block;
    width: 34px;
    height: 34px;
    margin-bottom: 0;
    border-radius: 100%;
    background: #FFFFFF;
    border: 1px solid transparent;
    box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    font-weight: normal;
    transition: all 0.2s ease-in-out;
  }
  .avatar-upload .avatar-edit input + label:hover {
    background: #f1f1f1;
    border-color: #d6d6d6;
  }
  .avatar-upload .avatar-edit input + label:after {
    content: "\f040";
    font-family: 'FontAwesome';
    color: #757575;
    position: absolute;
    top: 10px;
    left: 0;
    right: 0;
    text-align: center;
    margin: auto;
  }
  .avatar-upload .avatar-preview {
    width: 192px;
    height: 192px;
    position: relative;
    border-radius: 100%;
    border: 6px solid #F8F8F8;
    box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
  }
  .avatar-upload .avatar-preview > div {
    width: 100%;
    height: 100%;
    border-radius: 100%;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
  }
html css reactjs upload bootstrap-5
1个回答
0
投票

首先,我看不到你在哪里使用了 avatar-upload 类,所以我假设它是围绕你的代码块的外部 div,如下所示:

<div class="avatar-upload">
    <div class="avatar-edit">
        <input type='file' id="imageUpload" accept=".png, .jpg, .jpeg" 
               onChange={handleFileChange}/>
        
        <label htmlFor="imageUpload"><img src={camera} /></label>
    </div>
</div>

如果是,您尝试过以下造型吗?

.avatar-upload .avatar-edit input[type='file'] {
    border: none  !important;
    outline: none !important;
}

这可以确保如果

<input type='file'>
有浏览器应用的任何默认边框或轮廓样式,它们将被覆盖。

© www.soinside.com 2019 - 2024. All rights reserved.