gpt4 book ai didi

html - 如何使按钮看起来好像具有透明边框/描边?

转载 作者:搜寻专家 更新时间:2023-10-31 08:41:01 28 4
gpt4 key购买 nike

我有一个带边框的动态宽度/高度 div。里面是一个绝对定位的按钮,位于底部的中心,与父 div 的边框重叠。我想让它看起来像边框在重叠按钮之前停止几个像素。一项要求是保持一切动态,例如,如果按钮的宽度增加或框的增加不会破坏样式。

enter image description here

这是我到目前为止尝试过的:

*,
*:before,
*:after {
box-sizing: border-box;
}

html,
body {
height: 100%;
margin: 0;
}

body {
background: url(https://static.pexels.com/photos/415949/pexels-photo-415949.jpeg) no-repeat top center/cover;
font: normal 100% arial, sans-serif;
color: #fff;
}

.box {
max-width: 500px;
margin: 0 auto;
border: 6px solid #fff;
text-align: center;
position: relative;
padding: 25px;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}

.link {
display: inline-block;
background: #000;
padding: 10px 25px;
position: absolute;
top: 100%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: #fff;
text-decoration: none;
}

h1 {
margin-top: 0;
}

.box {
border-bottom: 0;
}

.box:before,
.box:after {
content: '';
position: absolute;
left: 0;
bottom: 1px;
height: 6px;
background: #fff;
right: 75%;
}

.box:after {
right: 0;
left: 75%;
}
<div class="box">
<h1>Some Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et.</p>
<a class="link" href="#">A Link</a>
</div>

最佳答案

使用带有 before 和 after 的 flexbox 作为底部边框。这样当按钮变大时,边框会变小:

*,
*:before,
*:after {
box-sizing: border-box;
}

html,
body {
height: 100%;
margin: 0;
}

body {
background: url(https://static.pexels.com/photos/415949/pexels-photo-415949.jpeg) no-repeat top center/cover;
font: normal 100% arial, sans-serif;
color: #fff;
}

.box {
max-width: 500px;
margin: 0 auto;
border: 6px solid #fff;
border-bottom: none;
text-align: center;
position: relative;
padding: 25px;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}

.buttonWrapper {
position: absolute;
display: flex;
bottom: 0;
right: 0;
left: 0;
align-items: flex-end;
}

.buttonWrapper:before, .buttonWrapper:after {
display: block;
flex: 1;
height: 6px;
background: #fff;
content: '';
}

.link {
display: inline-block;
background: #000;
padding: 10px 25px;
margin: 0 5px;
color: #fff;
text-decoration: none;
transform: translateY(50%);
align-item: middle;
}

h1 {
margin-top: 0;
}
<div class="box">
<h1>Some Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et.</p>
<div class="buttonWrapper">
<a class="link" href="#">A very long Link</a>
</div>
</div>

关于html - 如何使按钮看起来好像具有透明边框/描边?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44648640/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com