当前位置:首页 > CSS

css制作春联

2026-01-08 21:24:06CSS

使用CSS制作春联的方法

基础布局与样式

春联通常由一对垂直排列的红色对联和顶部的横批组成。使用CSS的flexbox布局可以轻松实现这种结构。创建一个父容器,内部包含三个子元素:横批、上联和下联。

<div class="couplet-container">
  <div class="horizontal-title">福星高照</div>
  <div class="vertical-couplet left">上联内容</div>
  <div class="vertical-couplet right">下联内容</div>
</div>
.couplet-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #f8f8f8;
  padding: 20px;
}

.horizontal-title {
  width: 200px;
  height: 60px;
  background-color: #e60000;
  color: gold;
  font-size: 24px;
  text-align: center;
  line-height: 60px;
  margin-bottom: 20px;
}

.vertical-couplet {
  width: 60px;
  height: 300px;
  background-color: #e60000;
  color: gold;
  font-size: 20px;
  padding: 10px;
  writing-mode: vertical-rl;
  text-align: center;
  line-height: 60px;
}

.left {
  margin-right: 10px;
}

.right {
  margin-left: 10px;
}

装饰效果增强

为春联添加传统装饰元素,如金色边框和阴影效果,使其更具节日氛围。

css制作春联

.horizontal-title, .vertical-couplet {
  border: 2px solid gold;
  box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.3);
  font-family: "楷体", "STKaiti", serif;
  font-weight: bold;
}

.horizontal-title {
  border-radius: 5px;
}

.vertical-couplet {
  border-top: 4px solid gold;
  border-bottom: 4px solid gold;
}

响应式设计

确保春联在不同设备上都能正常显示,通过媒体查询调整尺寸和布局。

css制作春联

@media (max-width: 600px) {
  .horizontal-title {
    width: 150px;
    height: 50px;
    font-size: 18px;
  }

  .vertical-couplet {
    width: 50px;
    height: 250px;
    font-size: 16px;
  }
}

动画效果

添加简单的动画效果,如悬停时放大,增强交互体验。

.vertical-couplet:hover {
  transform: scale(1.05);
  transition: transform 0.3s ease;
}

完整示例代码

结合以上所有元素,创建一个完整的春联CSS实现。

<!DOCTYPE html>
<html>
<head>
  <style>
    .couplet-container {
      display: flex;
      flex-direction: column;
      align-items: center;
      background-color: #f8f8f8;
      padding: 20px;
    }

    .horizontal-title {
      width: 200px;
      height: 60px;
      background-color: #e60000;
      color: gold;
      font-size: 24px;
      text-align: center;
      line-height: 60px;
      margin-bottom: 20px;
      border: 2px solid gold;
      box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.3);
      font-family: "楷体", "STKaiti", serif;
      font-weight: bold;
      border-radius: 5px;
    }

    .vertical-couplet {
      width: 60px;
      height: 300px;
      background-color: #e60000;
      color: gold;
      font-size: 20px;
      padding: 10px;
      writing-mode: vertical-rl;
      text-align: center;
      line-height: 60px;
      border: 2px solid gold;
      border-top: 4px solid gold;
      border-bottom: 4px solid gold;
      box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.3);
      font-family: "楷体", "STKaiti", serif;
      font-weight: bold;
    }

    .left {
      margin-right: 10px;
    }

    .right {
      margin-left: 10px;
    }

    .vertical-couplet:hover {
      transform: scale(1.05);
      transition: transform 0.3s ease;
    }

    @media (max-width: 600px) {
      .horizontal-title {
        width: 150px;
        height: 50px;
        font-size: 18px;
      }

      .vertical-couplet {
        width: 50px;
        height: 250px;
        font-size: 16px;
      }
    }
  </style>
</head>
<body>
  <div class="couplet-container">
    <div class="horizontal-title">喜迎新春</div>
    <div class="vertical-couplet left">春满人间百花吐艳</div>
    <div class="vertical-couplet right">福临小院四季常安</div>
  </div>
</body>
</html>

通过以上方法,可以创建一个具有传统风格的春联效果,同时保持现代网页设计的响应性和交互性。

标签: 春联css
分享给朋友:

相关文章

css制作

css制作

CSS 基础语法 CSS(层叠样式表)用于控制网页的样式和布局。其基本语法由选择器和声明块组成。选择器指定要样式化的HTML元素,声明块包含一个或多个属性-值对,用花括号 {} 包裹。 select…

css制作三角形

css制作三角形

使用 border 属性创建三角形 通过设置元素的 border 属性可以实现三角形效果。原理是利用边框的交界处形成的斜边。 .triangle { width: 0; height: 0;…

网页制作css

网页制作css

CSS 基础语法 CSS(层叠样式表)用于控制网页的样式和布局。基本语法由选择器和声明块组成: 选择器 { 属性: 值; 属性: 值; } 例如: p { color: b…

css如何制作圆

css如何制作圆

使用 border-radius 属性制作圆 通过设置 border-radius 属性为元素添加圆角效果。当 border-radius 的值等于元素宽度和高度的一半时,元素会呈现圆形。 .cir…

制作css

制作css

CSS基础语法 CSS规则由选择器和声明块组成。选择器指向需要设置样式的HTML元素,声明块包含一个或多个用分号分隔的声明。每个声明由属性和值组成,用冒号分隔。 选择器 { 属性: 值;…

网页制作 css

网页制作 css

CSS 基础语法 CSS(层叠样式表)用于控制网页的样式和布局。基本语法由选择器和声明块组成: 选择器 { 属性: 值; } 例如设置段落文字颜色为红色: p { color: red…