gpt4 book ai didi

html - CSS - 调整浏览器窗口大小时固定边框宽度变化

转载 作者:太空宇宙 更新时间:2023-11-04 06:49:20 26 4
gpt4 key购买 nike

我制作了 2 个简单的链接按钮,它们位于 2 个 div 标签内。

这是我试过的 csshtml 代码:

.lang-box {
position: absolute;
bottom: 60px;
left: 2%;
z-index: 3;
}

.flex-container {
display: flex;
}

.flex-direction-column {
flex-direction: column;
}

.border-gold {
border: 2px solid #ac8b45;
}

.text-gold {
color: #ac8b45;
}

.background-gold {
background-color: #ac8b45;
}

.text-black {
color: #000;
}

.no-background {
background-color: transparent;
}

.lang-a-button {
text-decoration: none;
outline: 0;
display: block;
font-size: 20px;
padding-bottom: 6px;
padding-top: 10px;
padding-left: 6px;
padding-right: 6px;
height: auto;
text-align: center;
}

.lang-a-button:hover {
text-decoration: none;
opacity: .7;
}
<div class="lang-box">
<div class="flex-container flex-direction-column border-gold">
<a href="/en" target="_self" class="lang-a-button no-background text-gold" title="Change to English">EN</a>
<a href="/" target="_self" class="active_lang lang-a-button text-black background-gold" title="Cambia in Italiano">IT</a>
</div>
</div>

这是最终结果:

this is the final result

问题是当我调整浏览器屏幕大小时,.border-gold 的右边框粗细发生变化:

Problem with border 1 Problem with border 2

我不明白为什么会这样。我尝试使用 this但没有任何变化。

我使用 Google Chrome v69 进行测试。

我需要添加什么吗?

最佳答案

尝试添加链接 flex-grow:0; flex-shrink:0; 和固定宽度,像这样:

* {
box-sizing: border-box;
}

.lang-box {
position: absolute;
top: 60px;
left: 2%;
z-index: 3;

width: 42px;
}

.flex-container{
display: flex;
width: 100%;
}

.flex-direction-column{
flex-direction: column;
}

.border-gold{
border: 2px solid #ac8b45;
}

.text-gold{
color: #ac8b45;
}

.background-gold{
background-color: #ac8b45;
}

.text-black{
color: #000;
}

.no-background{
background-color: transparent;
}

.lang-a-button{
text-decoration: none;
outline: 0;
display: block;
font-size: 20px;
padding-bottom: 6px;
padding-top: 10px;
/* padding-left: 6px;
padding-right: 6px; */
height: auto;
text-align: center;

width: 100%;
flex-grow:0;
flex-shrink:0;
width: 40px;
}

.lang-a-button:hover{
text-decoration: none;
opacity: .7;
}
<div class="lang-box">
<div class="flex-container flex-direction-column border-gold">
<a href="/en" target="_self" class="lang-a-button no-background text-gold" title="Change to English">EN</a>
<a href="/" target="_self" class="active_lang lang-a-button text-black background-gold" title="Cambia in Italiano">IT</a>
</div>
</div>

我没有确切的答案,但我认为这是因为 flexflex-direction: column 的特殊性。即使我们在 flex block 中设置元素的固定宽度,它也并不总是考虑到它。因此,对于固定宽度的 block ,需要额外指定flex-grow: 0; flex 收缩:0;

所以 ... flex-direction: column ... 为换行和内部链接添加固定宽度。

关于html - CSS - 调整浏览器窗口大小时固定边框宽度变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52993589/

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