如何使用 CSS 创建电子邮件时事通讯?


一个表单包含订阅电子邮件时事通讯的详细信息,包括姓名和电子邮件地址输入字段。有了它,还可以为用户创建订阅每日时事通讯的复选框。此外,还可以看到订阅时事通讯的按钮。我们将在本文中介绍如何使用 HTML 和 CSS 设计电子邮件时事通讯表单。

创建一个表单并设置输入字段

使用 <form> 创建一个表单。姓名、电子邮件地址和复选框字段设置在表单中。此外,提交按钮也设置在表单内 −

<form>
   <h2>Subscribe to our Newsletter</h2>
   <p>Subscribe to our Newsletter to get latest update in the world of technology and web</p>
   <input type="text" placeholder="Name" name="name" required>
   <input type="text" placeholder="Email address" name="mail" required>
   <label>
      <input type="checkbox" checked="checked" name="subscribe"> Daily Newsletter
   </label>
   <input type="submit" value="Subscribe">
</form>

像这样设置表单样式。最大宽度使用 max-width 属性设置 −

form {
   border: 3px solid #f1f1f1;
   padding: 20px;
   background-color: #f3f3f3;
   max-width: 800px;
   margin:auto;
}

设置输入字段样式

输入字段文本和按钮的样式像这样设置。宽度设置为 100%,显示属性设置为行内块 −

input[type=text], input[type=submit] {
   width: 100%;
   padding: 12px;
   margin: 8px 0;
   display: inline-block;
   border: 1px solid #ccc;
   box-sizing: border-box;
   font-size: 30px;
}

复选框

用于每日时事通讯功能的复选框使用 input type checkbox 创建 −

<label>
   <input type="checkbox" checked="checked" name="subscribe"> Daily Newsletter
</label>

示例

以下是使用 CSS 创建电子邮件简报的代码 −

<!DOCTYPE html>
<html>
   <style>
      body {font-family: Arial, Helvetica, sans-serif;font-size: 20px;font-weight: bold;}
      h1{
         text-align: center;
      }
      form {
         border: 3px solid #f1f1f1;
         padding: 20px;
         background-color: #f3f3f3;
         max-width: 800px;
         margin:auto;
      }
      input[type=text], input[type=submit] {
         width: 100%;
         padding: 12px;
         margin: 8px 0;
         display: inline-block;
         border: 1px solid #ccc;
         box-sizing: border-box;
         font-size: 30px;
      }
      input[type=checkbox] {
         margin-top: 16px;
      }
      input[type=submit] {
         background-color: rgb(236, 255, 61);
         color: rgb(0, 0, 0);
         border: none;
         font-size: 25px;
         font-weight: bolder;
      }
      input[type=submit]:hover {
         background-color: rgb(255, 238, 0);
      }
   </style>
<body>
   <h1>Email Newsletter Example</h1>
   <form>
      <h2>Subscribe to our Newsletter</h2>
      <p>Subscribe to our Newsletter to get latest update in the world of technology and web</p>
      <input type="text" placeholder="Name" name="name" required>
      <input type="text" placeholder="Email address" name="mail" required>
      <label>
         <input type="checkbox" checked="checked" name="subscribe"> Daily Newsletter
      </label>
      <input type="submit" value="Subscribe">
   </form>
</body>
</html>

更新于: 14-12-2023

151 次浏览

开启您的 职业

通过完成课程获得认证

开始
广告
© . All rights reserved.