CSS - 修复了调整浏览器大小时边框宽度的变化 window

CSS - Fixed border width change when resizing browser window

我制作了 2 个简单的 link 按钮,它们位于 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>

这是最终结果:

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

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

我用GoogleChromev69来测试

我需要补充什么吗?

尝试添加链接 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>

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

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