【发布时间】:2022-01-19 15:55:34
【问题描述】:
我正在尝试重新创建这个组件,该组件由最右上角的一个按钮和一个显示文件名的标签组成。
为了得到这个结果,我使用了按钮的绝对位置,但是你可以很容易地看出按钮是在它的父级内部而不是在它上面
HTML:
<div class="ctrl">
<div class="upload">
<label class="upload__file-name">Select a file</label>
<button type="button" class="upload__choose">
Browse
</button>
</div>
</div>
SCSS:
*,
*::after,
*::before {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html {
height: 100%;
font-size: 62.5%; //1 rem = 10px; 10px/16px = 62.5%
background-color: #562765;
}
body {
box-sizing: border-box;
height: 100%;
}
.file-input {
display: none;
}
.ctrl {
height: 4.8rem;
}
.upload {
height: 100%;
width: 100%;
background-color: rgba(#F0F0F0, 0.32);
border: 1px solid #fff;
box-sizing: border-box;
border-radius: 40px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 0 0 23px;
position: relative;
&__file-name {
display: inline-block;
font-size: 1.4rem;
font-weight: bold;
line-height: 120%;
color: rgba(#fff, 0.48);
}
&__choose {
top: 0;
right: 0;
position: absolute;
cursor: pointer;
border: 0;
height: 100%;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
padding: 12px 40px;
background: linear-gradient(
100.77deg,
rgba(222, 102, 251, 0.4) 0%,
rgba(222, 102, 251, 0) 53.8%
),
#7036e9;
box-shadow: 0px 1px 24px -1px rgba(13, 8, 70, 0.4);
backdrop-filter: blur(20px);
border-radius: 40px;
}
}
这是我用过的codepen with the HTML + CSS (Sass)。
有什么方法可以让按钮看起来像放在容器顶部一样?换句话说,如何将按钮的顶部、右侧和底部边框与其父容器对齐?
谢谢。
【问题讨论】:
-
你试过
z-index吗? -
需要指定与父元素匹配的内部元素的border-radius。