html - 使用 CSS 创建多个向外的边框半径

标签 html css responsive-design css-shapes

我想围绕一个矩形创建 4 个向外的边框半径。我想在红色圆圈中创建边框(但不仅是一个,而且在矩形周围总计 4,所以它看起来像一个“大写 I”)

Capital I with 4 outward border radi

当您更改窗口大小时,“capital I”应该适本地调整大小。因此,外边框应该“附加”到垂直矩形。

这些是我能想到的如何实现它的选项:

  1. 阴影框
  2. 元素之后/之前

但是这些解决方案的外边界不会一直附着在垂直矩形上。

这里是example for option 2 :

div {
  background-color: black;
  margin: 0 auto;
}
.one {
  height: 80vh;
  width: 300px;
}
.bar {
  height: 10vh;
  width: 450px;
}
.one:before {
  content: '';
  position: absolute;
  left: 115px;
  height: 50px;
  width: 50px;
  border-bottom-right-radius: 50px 50px;
  border-bottom: 1px solid #000;
  border-right: solid 1px #000;
  top: 81.3vh;
  background-color: white;
  box-shadow: 22px 22px 0 22px black;
}
<div class="bar top"></div>
<div class="one"></div>
<div class="bar bottom"></div>

更改窗口大小后,您会看到外边框已关闭。 (此外,使用选项 2 不可能创建超过 2 个的外边界。)

有没有仅使用 CSS 的解决方案,即使您更改了窗口大小,您也可以创建与垂直矩形相连的外边框?

最佳答案

我的第一个建议是只使用单个元素来表示字母,而不是将其分为三个部分(顶部栏、底部栏、中间栏)。从几何上讲,这使问题变得简单得多 - 无需在形状中添加四个“负”圆 Angular ,只需从中减去两个部分圆 Angular 的矩形即可。

我整理了您的 CSS,删除了栏元素并完成了 .one:before.one:after 的样式 block 。我还删除了 1px 边框 - 如果需要,您可以重新添加这些边框,但需要进行一些调整(在某些地方可能需要 calc())。否则,即使您不知道,您也非常接近解决方案:

div {
  background-color: black;
  margin: 0 auto 0 auto;
}
.one {
  height: 100vh;
  width: 450px;
  ;
  position: relative;
}
.one:before,
.one:after {
  content: '';
  position: absolute;
  height: 80vh;
  width: 75px;
  top: 10vh;
  background-color: white;
}
.one:before {
  left: 0;
  border-top-right-radius: 50px 50px;
  border-bottom-right-radius: 50px 50px;
}
.one:after {
  right: 0;
  border-top-left-radius: 50px 50px;
  border-bottom-left-radius: 50px 50px;
}
<div class="one"></div>

希望对您有所帮助!如果您有任何问题,请告诉我。

关于html - 使用 CSS 创建多个向外的边框半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37148168/

相关文章:

python - 如何将 CSS 添加到我的 Django 元素网站?

html - 使 Zurb 的基础 3 与 IE7 一起工作

javascript - 将事件添加到可折叠导航链接

iphone - iOS : parent's background visible around the edges 中的嵌套元素

javascript - 将 jquery 应用于加载到 div 的页面

html - 位置固定元素重叠到页脚中

css 响应式设计 - 在 div 外部流动的链接

javascript - x-editable 的成功回调不起作用

html - 响应式设计的自动填充

css - 带有响应式网站的粘性页脚