html - CSS 使 div 在顶部和底部 flex 但在左侧和右侧笔直

标签 html css curve

嘿伙计们,我一直在想是否可以这样做,我试过使用 border-radius 但它显然只会向左侧和右侧形成曲线...

这是我需要的:

enter image description here

这将是工作 div:

#mainbox {
  width: 115px;
  height: 24px;
  background-color: gray;
  border: 1px solid #000000;
  text-align: center;
}
<div id="mainbox">
  <div id="secondbox">test</div>
</div>

有什么可能的想法吗?

最佳答案

这样的事情是可以实现的,但是比较麻烦。 SVG 对此会更好。

引用自this关于 SO 的问题。

body {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mainbox {
  width: 200px;
  height: 130px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#mainbox::before,
#mainbox::after {
  content: "";
  display: block;
  position: absolute;
  height: 100px;
  /* equal to inner curvedbox */
  border-left: 5px solid black;
  bottom: 0;
  z-index: 1;
}

#mainbox::before {
  left: 0;
}

#mainbox::after {
  right: 0;
}

#curvedbox {
  position: relative;
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#curvedbox::before,
#curvedbox::after {
  display: block;
  content: "";
  width: 140%;
  height: 200%;
  border: solid 5px #000;
  border-color: #000 transparent transparent transparent;
  border-radius: 100%;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

#curvedbox::before {
  top: -30%;
}

#curvedbox::after {
  top: 69%;
}

#secondbox {
  transform: translateY(-140%);
}
<div id="mainbox">
  <div id="curvedbox">
    <div id="secondbox">test</div>
  </div>
</div>

关于html - CSS 使 div 在顶部和底部 flex 但在左侧和右侧笔直,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43970610/

上一篇:HTML 使页脚坚实

下一篇:HTML Flexbox 画廊

相关文章:

html - 在 Windows 中安装 OTRS 3.2

html - 使用 Overflow :Scroll through parent with overflow:hidden 限制 div 高度

html - 与 Telerik 控件的内置 javascript 函数相关的问题

java - 画曲线,有什么建议

javascript - 使用 Javascript 将一个类中的所有图像替换为另一个图像

html - 通过将鼠标悬停在另一个元素上来更改元素样式

php - 生成随机曲线

sql - 检测时间序列中的趋势

javascript - 网页优化

jquery - 如何将无序列表转换为表格?