css - 如何创建css凹/凸形状

标签 css sass css-shapes

我想创建两个 div,背景为白色,如下所示。如您所见,它基本上是一个矩形和一个被切出的椭圆形。它应该能够产生一个盒子阴影。

有没有办法只用 css 实现这个?

Concave shapes

最佳答案

我使用了 2 个带有 box-shadow 的 div 我添加了 border 以便理解

body {
  background:url(https://placeimg.com/640/480/any);
}

.out {
  width: 455px;
  height: 275px;
  border: 1px solid red;
  position: relative;
  overflow: hidden;
  margin: 20px;
}

.in {
  width: 550px;
  height: 550px;
  border: 1px solid green;
  position: absolute;
  left: 200px;
  border-radius: 50%;
  box-shadow: 0 0 0 500px white; /* this is the white background */
}

.bottom .in {
  bottom: 0;
  left: 200px;
}
<div class="out">
  <div class="in">

  </div>
</div>

<div class="out bottom">
  <div class="in">

  </div>
</div>

关于css - 如何创建css凹/凸形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37921356/

相关文章:

javascript - 删除不同 ID 的列表按钮

HTML/CSS - 我怎样才能让我的表格列永远不会比我指定的宽度更宽

html - 需要 border-right 不是整个 div 的长度

css - 媒体查询问题仅恰好在 978px

html - 你如何只用 css 制作这个 dogeared 形状

html - 使用 flexbox 将特定元素居中

javascript - 单击任何元素并在存在时读取特定 HTML-5 自定义属性的监听器?

ruby-on-rails-4 - Rails 上的 Livereload 未显示 SCSS 更改

CSS/Form 下拉箭头定位

html - 我如何使用 CSS 在菱形内创建标题?