如何使用 CSS 建立網站的關於/關於我們頁面?


網站的關於頁面包含團隊詳細資訊,包括姓名、職位、聯絡方式、聯絡按鈕等。首先,為關於頁面設定一個容器。在容器內,為列、卡片、個人資料等設定子容器。個人資料包括姓名、職位和一個聯絡按鈕。讓我們看看如何使用 HTML 和 CSS 建立網站的關於我們頁面。

建立一個 div 容器

容器用於關於頁面的團隊詳細資訊。容器中的團隊卡片包含其他子容器 -

<div class="teamColumn">
   <div class="teamCard">
      <img
         src="https://images.pexels.com/photos/839011/pexels-photo-839011.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
      />
      <div class="personContainer">
         <h3>Jane Doe</h3>
         <p class="Designation">CTO</p>
         <p><button class="contact">Contact</button></p>
      </div>
   </div>
</div>

為個人資料建立子容器

在父 div 內,我們將為人員詳細資訊建立一個子 div -

<div class="personContainer">
   <h3>Jane Doe</h3>
   <p class="Designation">CTO</p>
   <p><button class="contact">Contact</button></p>
</div>

團隊成員的列

我們為團隊三名成員的詳細資訊建立了三列 -

.teamColumn {
   display: inline-block;
   width: 300px;
   height: 400px;
   margin-bottom: 16px;
   padding: 0 8px;
}

團隊卡片

團隊卡片的樣式如下 -

.teamCard {
   background-color: rgb(162, 162, 255);
   text-align: center;
   font-size: 20px;
}

帶有人員容器的個人資料詳細資訊

在團隊卡片 div 內,我們有人員容器。團隊成員的職位也在這裡設定樣式 -

.personContainer {
   padding: 0 16px;
}
.Designation {
   color: rgb(15, 0, 100);
   font-weight: bolder;
   font-size: 20px;
}

聯絡按鈕

這裡設定了聯絡團隊成員的按鈕樣式。cursor 屬性設定為 pointer,使按鈕看起來可點選 -

.contact {
   border: none;
   outline: 0;
   display: inline-block;
   padding: 12px;
   color: white;
   font-weight: bolder;
   background-color: rgb(78, 0, 102);
   text-align: center;
   cursor: pointer;
   width: 100%;
}

示例

要建立關於頁面,程式碼如下 -

<!DOCTYPE html>
<html>
<head>
   <style>
      html {
         box-sizing: border-box;
      }
      body {
         font-family: monospace, serif, sans-serif;
         margin: 0px;
         padding: 0px;
      }
      h1 {
         text-align: center;
         background-color: rgb(108, 18, 131);
         color: white;
         padding-top: 40px;
         padding-bottom: 40px;
         margin-top: 0px;
      }
      .teamContainer {
         margin-left: 10%;
      }
      img {
         width: 100%;
         height: 200px;
      }
      *,
      *:before,
      *:after {
         box-sizing: inherit;
      }
      .teamColumn {
         display: inline-block;
         width: 300px;
         height: 400px;
         margin-bottom: 16px;
         padding: 0 8px;
      }
      @media screen and (max-width: 650px) {
         .teamColumn {
            display: block;
         }
      }
      .teamCard {
         background-color: rgb(162, 162, 255);
         text-align: center;
         font-size: 20px;
      }
      .personContainer {
         padding: 0 16px;
      }
      .personContainer::after,
      .teamContainer::after {
         content: "";
         clear: both;
         display: table;
      }
      .Designation {
         color: rgb(15, 0, 100);
         font-weight: bolder;
         font-size: 20px;
      }
      .contact {
         border: none;
         outline: 0;
         display: inline-block;
         padding: 12px;
         color: white;
         font-weight: bolder;
         background-color: rgb(78, 0, 102);
         text-align: center;
         cursor: pointer;
         width: 100%;
      }
      .contact:hover {
         background-color: #555;
      }
   </style>
</head>
<body>
   <h1>About Us</h1>
   <div class="teamContainer">
      <div class="teamColumn">
         <div class="teamCard">
            <img src="https://images.pexels.com/photos/839011/pexels-photo-839011.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
            <div class="personContainer">
               <h3>Jane Doe</h3>
               <p class="Designation">CTO</p>
               <p><button class="contact">Contact</button></p>
            </div>
         </div>
      </div>
      <div class="teamColumn">
         <div class="teamCard">
            <img src="https://images.pexels.com/photos/614810/pexels-photo-614810.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
            <div class="personContainer">
               <h3>Mike Ross</h3>
               <p class="Designation">Front End Developer</p>
               <p><button class="contact">Contact</button></p>
            </div>
         </div>
      </div>
      <div class="teamColumn">
         <div class="teamCard">
            <img src="https://images.pexels.com/photos/736716/pexels-photo-736716.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
            <div class="personContainer">
               <h3>John Doe</h3>
               <p class="Designation">FullStack Developer</p>
               <p><button class="contact">Contact</button></p>
            </div>
         </div>
      </div>
   </div>
</body>
</html>

更新於: 2023-12-14

747 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.