如何使用 Tailwind CSS 構建卡片元件?
Tailwind CSS 中的卡片元件是網頁設計中的一個重要概念,尤其是在電子商務網站、部落格網站等中使用。Tailwind CSS 以構建吸引人的網站而聞名。本文將解釋如何使用 Tailwind CSS 構建卡片元件。
如何在 Tailwind CSS 中新增單個卡片元件
Tailwind CSS 為我們提供了一種非常方便的方法來新增卡片元件。卡片元件還可以包含其他子元件,如影片、音訊、影像等。此外,我們可以使用可用的屬性輕鬆自定義整體設計。還可以使用 Tailwind CSS 為卡片元件新增動畫和懸停效果。
示例
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.tailwindcss.com/"></script>
<title>Tutorials Point</title>
</head>
<body class="bg-gray-300 text-gray-600">
<section class="py-12 px-5 mx-auto">
<div class="flex flex-wrap -m-4">
<div class="p-4 lg:w-1/3">
<div class="bg-white bg-opacity-75 rounded-lg p-8 overflow-hidden text-center relative">
<h2 class="text-xs title-font font-medium text-gray-700 mb-
1">TUTORIALS POINT</h2>
<h1 class="title-font sm:text-2xl text-xl font-medium text-gray-
900 mb-3">Elegant and Concise Tutorials</h1>
<p class="mb-3 text-justify">
Unlock the potential of limitless learning with Tutorials Point!
Our platform offers a wide range of tutorials, covering subjects
such as programming, web development, data science, and more. Our
step-by-step guides and interactive learning experiences will help
you master the concepts and skills needed to succeed in your
field. Enhance your knowledge and boost your career with Tutorials
Point today!
</p>
<img class="w-full object-cover object-center" src="https://tutorialspoint.tw/images/logo.png"
</div>
</div>
</div>
</section>
</body>
</html>
解釋
本節包括:➔ 到 Tailwind CSS 庫的連結,這是一個流行的實用優先 CSS 框架,用於構建快速且響應式的網站。
HTML 文件定義了一個包含一個框的部分,該框包含標題、副標題、一些描述性文字和影像。<head> 部分包含一個 <title> 和一個匯入 Tailwind CSS 庫的 <script>。<body> 部分有一個類,用於設定背景顏色和文字顏色。
Tailwind CSS 庫簡潔優雅地為 HTML 元素設定樣式。該框採用圓角邊框、填充和不透明度進行樣式設定,其內容居中。影像設定為全寬並覆蓋框,同時保持其縱橫比。
如何新增多個卡片?
您可能已經注意到,像部落格、電子商務等流行的網頁包含多個卡片元件。在 Tailwind CSS 中實現這一點非常簡單。我們只需要多次編寫相同的卡片基本程式碼即可。根據我們傳遞的引數(如寬度、高度等),瀏覽器將放置卡片。
示例
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.tailwindcss.com/"></script>
<title>Awesome Card</title>
</head>
<body class="bg-gray-300 text-gray-600">
<section class="py-12 px-5 mx-auto">
<div class="flex flex-wrap -m-4">
<div class="p-4 lg:w-1/3">
<div class="bg-white rounded-lg p-8 shadow-lg overflow-hidden">
<img class="w-full object-cover object-center"
src="https://imgnew.outlookindia.com/uploadimage/library/16_9/16_9_5/IMAGE_1651057728.jpeg"
<h2 class="text-xs title-font font-medium text-gray-700 mb-1 mt-5">ASUS LAPTOP</h2>
<h1 class="title-font sm:text-2xl text-xl font-medium text-gray-
900 mb-3">GAMING LAPTOP</h1>
<p class="mb-3 text-justify">
ASUS laptops are designed for versatility, with features like
sleek and lightweight designs, powerful performance, and
innovative technologies. Whether you're a gamer, creative
professional, or just need a reliable device for everyday use,
ASUS has you covered.
</p>
<button class="bg-indigo-500 text-white py-2 px-4 roundedfull"> Get Started</button>
</div>
</div>
<div class="p-4 lg:w-1/3">
<div class="bg-white rounded-lg p-8 shadow-lg overflow-hidden">
<img class="w-full object-cover object-center"src="https://images.indianexpress.com/2022/08/HP_Laptop_LEAD.jpg"
<h2 class="text-xs title-font font-medium text-gray-700 mb-1 mt-5">HP LAPTOP</h2>
<h1 class="title-font sm:text-2xl text-xl font-medium text-gray-900 mb-3">ULTRABOOK</h1>
<p class="mb-3 text-justify">
HP offers a wide range of laptops to choose from, designed to suit
every need and budget. From lightweight and portable devices perfect
for on-the-go computing, to powerful machines capable of handling
demanding tasks, HP has got you covered.
</p>
<button class="bg-indigo-500 text-white py-2 px-4 roundedfull">Get Started</button>
</div>
</div>
<div class="p-4 lg:w-1/3">
<div class="bg-white rounded-lg p-8 shadow-lg overflow-hidden">
<img class="w-full object-cover object-center"src="https://cdn.mos.cms.futurecdn.net/PZtqJj8yTeTYnw3WMjdomF.jpg"
<h2 class="text-xs title-font font-medium text-gray-700 mb-1 mt-5">DELL LAPTOP</h2>
<h1 class="title-font sm:text-2xl text-xl font-medium text-gray-900 mb-3">ULTRABOOK</h1>
<p class="mb-3 text-justify">
Dell has a wide range of laptops to choose from, making it easy to
find one that suits your needs and budget.From entry-level
machines perfect for basic computing, to high-end gaming laptops,
Dell has something for everyone.</p>
<button class="bg-indigo-500 text-white py-2 px-4 roundedfull">Get Started</button>
</div>
</div>
</div>
</section>
</body>
</html>
結論
本文介紹瞭如何使用 Tailwind CSS 建立卡片元件。我們在卡片元件中使用了不同的元素,如文字、標題、影像元件等。我們強烈建議讀者嘗試更改屬性和值,並檢視發生的更改。
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP