如何为轮廓属性创建半径。

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

how to make radius for outline property

问题

<!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->

<!-- 语言:lang-css -->

    .myElement {
      width: 200px;
      height: 100px;
      border: 3px solid #0064d2;
      outline: solid red;
      border-radius: 30px;
    }

<!-- 语言:lang-html -->

    <div class="myElement"></div>

<!-- 结束代码片段 -->

我想创建一个带有矩形红色轮廓的圆角蓝色边框,但border-radius影响了轮廓并使其变成圆形
英文:

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

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

.myElement {
  width: 200px;
  height: 100px;
  border: 3px solid #0064d2;
  outline: solid red;
  border-radius: 30px;
}

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

&lt;div class=&quot;myElement&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

I want to create a rounded blue border with rectangular red outline but border-radius impacts on outline and makes it round

答案1

得分: 2

你可以使用::after来将轮廓与边框分开:

你可以通过修改百分比来改变大小,我以父元素的80%作为示例。

要使元素居中,使用剩余空间的一半进行transform translate

.myElement {
    width: 200px;
    height: 100px;
    outline: solid red;
    padding: 10px;
    position: relative;
}

.myElement::after {
    content: "";
    border: 3px solid #0064d2;
    border-radius: 30px;
    display: inline-block;
    width: 80%;
    height: 80%;
    transform: translate(10%, 10%);
}
<div class="myElement"></div>
英文:

You can use an ::after to separate the outline from the border:

You can change the size by altering the percentage, i've used 80% of the parent as example.

To center the element, use transform translate of half of the remaining space

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

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

.myElement {
    width: 200px;
    height: 100px;
    outline: solid red;
    padding: 10px;
    position: relative;
}

.myElement::after {
    content: &quot;&quot;;
    border: 3px solid #0064d2;
    border-radius: 30px;
    display: inline-block;
    width: 80%;
    height: 80%;
    transform: translate(10%,10%);
}

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

&lt;div class=&quot;myElement&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月15日 00:01:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76475497.html
匿名

发表评论

匿名网友

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

确定