参考资料

  1. CSS 阴影效果设置
  2. display: flex/inline-flex示例
  3. CSS 阴影设置
  4. 使用CSS Grid和Flexbox两种现代布局方式实现4列12个产品布局的方法
  5. css3中设置阴影的属性是
  6. 伪元素选择器详细说明以及案例
  7. CSS网格详细说明以及案例
  8. 如何用Flex布局制作响应式布局?

CSS居中方法

  1. 水平居中

div {
  margin: 0 auto;
  width: 200px;
}
  1. Flexbox居中

.container {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center;    /* 垂直居中 */
  height: 100vh;
}
  1. Grid居中

.container {
  display: grid;
  place-items: center;
  height: 100vh;
}
  1. 绝对定位居中

div {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

完整示例

<!DOCTYPE html>
<html>
<head>
<style>
.center-div {
  width: 200px;
  height: 100px;
  background: #ccc;
  
  /* 方法1 */
  margin: 0 auto;
  
  /* 方法2 */
  display: flex;
  justify-content: center;
  align-items: center;
  
  /* 方法3 */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>
</head>
<body>

<div class="center-div">居中内容</div>

</body>
</html>