设置边框半径时,边框颜色会渐变淡,看起来有点问题。如何解决?

huangapple go评论86阅读模式
英文:

When I set the border radius, the color of the border is fade out, its looks buggy. How to solve this?

问题

我使用边框半径50%创建了简单的圆圈,但边框的颜色渐变,意味着颜色扩散开来。如何解决这个问题?我尝试使用::after来创建边框,但没有起作用。

这是我的代码:

.category-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.category-item {
  margin-bottom: 10px;
  padding: 15px;
}

.image-box {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: table;
  position: relative;
  margin: 0 auto 24px;
  background: #FBF4F3;
  border: 1px solid #AF3D78;
}

.category-title {
  text-align: center;
}
<div class="category-row">
  <div class="category-item">
    <div class="image-box"></div>
    <div class="category-title">Fragrance</div>
  </div>
  <!-- 其他类似结构 -->
</div>

这是我的问题。我想要一个平滑的边框颜色。

英文:

I have created simple circles using border radius 50% but the color of border is fading means color is spread out. How to Solve this ?, I have tried to create border using ::after but that doesn't work.

Here is my code:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.category-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.category-item {
  margin-bottom: 10px;
  padding: 15px;
}

.image-box {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: table;
  position: relative;
  margin: 0 auto 24px;
  background: #FBF4F3;
  border: 1px solid #AF3D78;
}

.category-title {
  text-align: center;
}

<!-- language: lang-html -->

&lt;div class=&quot;category-row&quot;&gt;
  &lt;div class=&quot;category-item&quot;&gt;
    &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;category-item&quot;&gt;
    &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;category-item&quot;&gt;
    &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;category-item&quot;&gt;
    &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;category-item&quot;&gt;
    &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
  &lt;/div&gt;

<!-- end snippet -->

Here is my problem:

<a href="https://i.stack.imgur.com/bZteO.png"><img src="https://i.stack.imgur.com/bZteO.png"></a>

I want a smooth border color.

答案1

得分: 1

你在圆形边缘的抗锯齿上遇到了问题。通过混合边框和背景颜色创建渐变效果,抗锯齿是一种软化锯齿状边缘的技术。这有时会导致边框颜色看起来淡或分散。

使用 outline 属性而不是 border 属性来创建圆形边框是修复此问题的一种技术。在不改变元素或其周围内容的布局的情况下,outline属性在元素的边框边缘之外绘制一条线。

CSS 代码:

.image-box {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: table;
  position: relative;
  margin: 0 auto 24px;
  background: #FBF4F3;
  outline: 1px solid #AF3D78;
}
英文:

You seem to be having problems with anti-aliasing on the circle's border. By creating a gradient effect by blending the border and background colors, anti-aliasing is a technique used to soften jagged edges. This occasionally results in the border colour looking faded or dispersed.

Creating the circle border using the outline property rather than the border property is one technique to fix this. Without changing the layout of the element or the content around it, the outline property draws a line outside the element's border edge.

CSS code:

  .image-box {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: table;
  position: relative;
  margin: 0 auto 24px;
  background: #FBF4F3;
  outline: 1px solid #AF3D78;
}

答案2

得分: 0

请在移动设备上打开您的jsfiddle链接并进行缩放。它没有淡出效果。外观可能会因分辨率和屏幕大小而有所不同。
否则,您可以尝试将边框宽度增加到2像素:

.category-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
}

.category-item {
    margin-bottom: 10px;
    padding: 15px;
}

.image-box {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    display: table;
    position: relative;
    margin: 0 auto 24px;
    background: #FBF4F3;
    border: 2px solid #AF3D78;
}

.category-title {
    text-align: center;
}
<div class="category-row">
    <div class="category-item">
        <div class="image-box"></div>
        <div class="category-title">Fragrance</div>
    </div>
    <div class="category-item">
        <div class="image-box"></div>
        <div class="category-title">Fragrance</div>
    </div>
    <div class="category-item">
        <div class="image-box"></div>
        <div class="category-title">Fragrance</div>
    </div>
    <div class="category-item">
        <div class="image-box"></div>
        <div class="category-title">Fragrance</div>
    </div>
    <div class="category-item">
        <div class="image-box"></div>
        <div class="category-title">Fragrance</div>
    </div>
</div>
英文:

Please open your jsfiddle link on a mobile device and zoom it. It is not fading out. The appearance may be different depending on the resolution and screen size.
Otherwise, you can try increasing the border-width to 2px:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.category-row {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .category-item {
        margin-bottom: 10px;
        padding: 15px;
    }

    .image-box {
        width: 140px;
        height: 140px;
        border-radius: 50%;
        display: table;
        position: relative;
        margin: 0 auto 24px;
        background: #FBF4F3;
        border: 2px solid #AF3D78;
    }

    .category-title {
        text-align: center;
    }

<!-- language: lang-html -->

&lt;div class=&quot;category-row&quot;&gt;
    &lt;div class=&quot;category-item&quot;&gt;
        &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;category-item&quot;&gt;
        &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;category-item&quot;&gt;
        &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;category-item&quot;&gt;
        &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;category-item&quot;&gt;
        &lt;div class=&quot;image-box&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;category-title&quot;&gt;Fragrance&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月18日 17:17:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75492327.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定