css - 如何在CSS中创建这种卡片布局

标签 css

/image/moO6l.png

我想创建这种卡片布局,如何在卡片的两面都显示蓝色。 我唯一想知道的是如何在卡片的左侧和右侧获得蓝色。

.card {
height: 300px;
width: 400px;
background: #f1f1f1;
}
<div class="card">
<h2>Title</h2>
</div>

最佳答案

你需要用两个 child 的容器包装卡片。

1- 然后添加具有绝对定位的overlay div(这将是蓝色的一面)

2- 卡片(白色 div)

N.P:我已经将 flex 添加到 body 中只是为了让卡片居中,不需要它。

示例:

body {
  background-color: gray;
  display: flex;
}

.card-container {
  position: relative;
  height: 300px;
  width: 400px;
  margin: auto;
}

.overlay {
  position: absolute;
  top: 5%;
  left: 0;
  width: 100%;
  height: 90%;
  background: linear-gradient(#4180B9, #42BDBB);
  border-radius: 5px;
}

.card {
  z-index: 2;
  position: relative;
  width: 90%;
  height: 100%;
  margin: auto;
  background-color: #fff;
  border-radius: 5px;
}
<div class="card-container">
  <div class="overlay"></div>
  <div class="card">
  </div>

关于css - 如何在CSS中创建这种卡片布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57456959/

相关文章:

html - 使文本在 div 中保持相对

android - 无法在 Android 上的绝对定位 HTML 输入中键入非拉丁符号(PhoneGap)

css - Internet Explorer 框模型 - 什么是偏移量?

javascript - 无法实现 60fps 动画

html - 如何在 Bootstrap CSS 文件中找到确切的类/ID 选择器以在自定义 CSS 文件中覆盖

jquery - 创建一个随着窗口缩小但隐藏左侧内容的面包屑

html - css first-of-type 在其他类下

html - Sprite 和文字大小

css - 如何根据页面内容改变背景图片高度

css - 水平滚动低于 1000 宽度