搜尋

現代CSS卡片

Aug 23, 2023 pm 01:25 PM

現代CSS卡片

如今,在網站上建立卡片非常重要,可以在網站上展示各種資料。例如,在TutorialsPoint網站的首頁上,您會發現以卡片格式展示不同的課程,當您點擊卡片時,它會將您重定向到該課程的特定頁面。

此外,如果您造訪任何電子商務商店,例如亞馬遜或Flipkart,它們會以卡片格式顯示產品。創建卡片的主要好處是我們可以在圖片上顯示產品的簡短訊息,並在產品頁面上提供完整資訊。

在本教學中,我們將學習僅使用HTML和CSS建立不同的卡片。

Example 1 (Basic CSS Cards)

In the example below, we created the ‘card’ div element containing the single image and the ‘card-content’ div element. The ‘card-content’ div element contains the text information.

In CSS, we set the fixed dimensions for the card element. Also, we have given styles such as background color, border radius, and border, etc. Also, we apply the box-shadow effect on the card users hso, we apply the box-shadow effect on the card提供over the card.

Furthermore, we fixed the dimensions for the image and set the border radius for the top corners. Also, we set the font size of the text content. In the output, users can observe the resultant card.

ant card.

ant
<html>
<head>
   <style>
      .card {
         display: flex;
         flex-direction: column;
         border-radius: 5px;
         box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
         transition: box-shadow 0.3s ease-in-out;
         width: 18rem;
         background-color: #fff;
      }
      .card:hover { box-shadow: 0 8px 16px rgba(0, 0, 0, 0.6);}
      .card>img {
         border-radius: 5px 5px 0 0;
         height: 150px;
         width: 100%;
         object-fit: contain;
      }
      .card-content { padding: 20px;}
      .card h3 { font-size: 1.4rem; margin-top: 0;}
      .card p { font-size: 1rem; margin-bottom: 10px;
      }
      .card a {
         padding: 10px 20px;
         background-color: #222;
         border-radius: 10px;
         color: white;
         text-align: center;
         display: inline-block;
         text-decoration: none;
         transition: background-color 0.4s ease-in-out;
      }
      .card a:hover { background-color: #4b4a4a;}
   </style>
</head>
<body>
   <h2 id="Creating-the-i-basic-cards-i-using-the-CSS"> Creating the <i> basic cards </i> using the CSS </h2>
   <div class = "card">
      <img src = "https://www.tutorialspoint.com/static/images/logo.png?v2" alt = "Logo">
      <div class = "card-content">
         <h3 id="Python"> Python </h3>
         <p> Python course by Shubham Vora </p>
         <a href = "#"> Join now </a>
      </div>
   </div>
</body>
</html>

Example 2

的中文翻譯為:

範例2

我們在下面的範例中建立了一個類似第一個範例的卡片。在這裡,我們為「card-image」 div元素設定了背景圖片。同時,我們透過從「Picsum」網站取得隨機圖片來設定圖片。在這個卡片中,我們沒有像第一個範例中那樣添加「立即加入」的錨點標籤。

<html>
<head>
   <style>
      .card {
         display: flex;
         flex-direction: column;
         width: 20rem;
         background-color: white;
         border-radius: 10px;
         box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
      }
      .card-image {
         height: 200px;
         background-image: url("https://picsum.photos/300/200");
         background-size: cover;
         border-radius: 10px 10px 0 0;
      }
      .card-content { padding: 20px;}
      .card-title {
         font-size: 1.5rem;
         font-weight: bold;
         margin: 0 0 10px 0;
      }
      .card-text { font-size: 1rem; margin: 0; }
   </style>
</head>
<body>
   <h2 id="Creating-the-i-basic-cards-i-using-the-CSS"> Creating the <i> basic cards </i> using the CSS. </h2>
   <div class = "card">
      <div class = "card-image"> </div>
      <div class = "card-content">
         <h2 id="Random-Image"> Random Image</h2>
         <p class = "card-text"> This is an random image description. </p>
      </div>
   </div>
</body>
</html>

Example 3

在下面的範例中,我們在卡片上添加了懸停效果,以顯示額外的資訊。

Here, we created the card container first to create a normal card and styled it using the CSS with 'position: relative.' We added the 'card-first' and 'card-second' div elements inside the card container. The 'card-first' div element contains the information on the card, and the 'card-second' div element contains the information to show whenever users hover over the card.

Furthermore, we set the dimensions for CSS's 'card-first' div element. Also, we set dimensions for the 'card-second' div element in the CSS and used the 'transform: translate(100%)' CSS property to hide the second part. When users hover over the card element, we use the 'transform: translateX(-100%)' CSS property to show the second part of the card.

<html>
<head>
   <style>
      .card {
         position: relative;
         width: 300px;
         height: 200px;
         background-color: rgb(64, 64, 247);
         color: white;
         border-radius: 10px;
         box-shadow: 0px 3px 7px rgba(0, 0, 0, 0.4);
         overflow: hidden;
      }
      .card-first {
         position: absolute;
         width: 100%;
         height: 100%;
         padding: 20px;
         font-size: 1.7rem;
         transition: transform 0.5s ease-in-out;
      }
      .card-second {
         position: absolute;
         top: 0;
         left: 0;
         width: 100%;
         height: 100%;
         padding: 20px;
         transform: translateX(100%);
         transition: transform 0.5s ease-in-out;
      }
      .card:hover .card-first { transform: translateX(-100%);}
      .card:hover .card-second { transform: translateX(0%); }
   </style>
</head>
<body>
   <h2 id="Creating-the-i-hover-effect-on-the-card-i-to-show-additional-information"> Creating the <i> hover effect on the card </i> to show additional information. </h2>
   <div class = "card">
      <div class = "card-first">
         <h3 id="Samsung-s"> Samsung s22 </h3>
         <p> 1,01,000 INR </p>
      </div>
      <div class = "card-second">
         <p> 6.4 inch display </p>
         <p> 8 GB RAM </p>
         <p> 128 GB Storage </p>
         <p> 64 MP Camera </p>
      </div>
   </div>
</body>
</html>

Example 4

在下面的範例中,我們建立了一個名為'parent'的div元素。之後,我們添加了多個包含圖片和卡片描述的卡片元素。

在CSS中,我們使用clamp()函數來設定卡片的寬度。 clamp()函數接受三個參數。第一個是最小值,第二個是百分比值,第三個是最大值。在我們的例子中,如果螢幕尺寸的20%在300和500像素之間,卡片寬度將為20%。否則,它將是300像素或500像素。

此外,我們將「parent」容器設定為flexbox以正確顯示所有卡片。

<html>
<head>
   <style>
      .parent {
         padding: 30px 5%;
         display: flex;
         flex-wrap: wrap;
         justify-content: space-between;
      }
      .card {
         position: relative;
         margin: 20px;
         width: clamp(230px, 20%, 500px);
         height: 250px;
         background-color: green;
         color: white;
         border-radius: 10px;
         transition: all 0.3s ease;
      }
      .card img {
         width: 100%;
         height: 150px;
         border-radius: 10px 10px 0 0;
         object-fit: cover;
      }
      .card-text {
         padding: 20px;
         text-align: center;
         position: absolute;
         bottom: 0;
         left: 0;
         right: 0;
         transition: all 0.3s ease;
      }
      .card-text h3 { font-size: 24px; margin-bottom: 10px;}
      .card-text p { font-size: 16px; margin-bottom: 0;}
   </style>
</head>
<body>
   <h3 id="Creating-the-i-card-with-clamp-function-i-to-manage-card-dimensions-according-to-the-screen-dimensions"> Creating the <i> card with clamp() function </i> to manage card dimensions according to the screen dimensions </h3>
   <div class = "parent">
      <div class = "card">
         <img src = "https://picsum.photos/300/200" alt = "Random image">
         <div class = "card-text">
            <h2 id="Card"> Card 1 </h2>
            <p> This is a card description. </p>
         </div>
      </div>
      <div class = "card">
         <img src = "https://picsum.photos/300/200" alt = "Random image">
         <div class = "card-text">
            <h2 id="Card"> Card 2 </h2>
            <p> This is a card description. </p>
         </div>
      </div>
   </div>
</body>
</html>

Users learned to create modern cards using HTML and CSS. In the first two examples, we created the basic cards; in the third example, we created the cards with the hover effect. Also, we learned to use the clamp( function to handle the card size according to the device's screen dimensions.###

以上是現代CSS卡片的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:tutorialspoint。如有侵權,請聯絡admin@php.cn刪除
光標的下一個CSS樣式光標的下一個CSS樣式Apr 23, 2025 am 11:04 AM

具有CSS的自定義光標很棒,但是我們可以將JavaScript提升到一個新的水平。使用JavaScript,我們可以在光標狀態之間過渡,將動態文本放置在光標中,應用複雜的動畫並應用過濾器。

世界碰撞:使用樣式查詢的鑰匙幀碰撞檢測世界碰撞:使用樣式查詢的鑰匙幀碰撞檢測Apr 23, 2025 am 10:42 AM

互動CSS動畫和元素相互啟動的元素在2025年似乎更合理。雖然不需要在CSS中實施乒乓球,但CSS的靈活性和力量的增加,可以懷疑Lee&Aver Lee有一天會成為一種

使用CSS背景過濾器進行UI效果使用CSS背景過濾器進行UI效果Apr 23, 2025 am 10:20 AM

有關利用CSS背景濾波器屬性來樣式用戶界面的提示和技巧。您將學習如何在多個元素之間進行背景過濾器,並將它們與其他CSS圖形效果集成在一起以創建精心設計的設計。

微笑嗎?微笑嗎?Apr 23, 2025 am 09:57 AM

好吧,事實證明,SVG的內置動畫功能從未按計劃進行棄用。當然,CSS和JavaScript具有承載負載的能力,但是很高興知道Smil並沒有像以前那樣死在水中

'漂亮”在情人眼中'漂亮”在情人眼中Apr 23, 2025 am 09:40 AM

是的,讓#039;跳上文字包裝:Safari Technology Preview In Pretty Landing!但是請注意,它與在鉻瀏覽器中的工作方式不同。

CSS-tricks編年史XLIIICSS-tricks編年史XLIIIApr 23, 2025 am 09:35 AM

此CSS-tricks更新了,重點介紹了年鑑,最近的播客出現,新的CSS計數器指南以及增加了幾位新作者,這些新作者貢獻了有價值的內容。

tailwind的@Apply功能比聽起來更好tailwind的@Apply功能比聽起來更好Apr 23, 2025 am 09:23 AM

在大多數情況下,人們展示了@Apply的@Apply功能,其中包括Tailwind的單個property實用程序之一(會改變單個CSS聲明)。當以這種方式展示時,@Apply聽起來似乎很有希望。如此明顯

感覺就像我沒有釋放:走向理智的旅程感覺就像我沒有釋放:走向理智的旅程Apr 23, 2025 am 09:19 AM

像白痴一樣部署的部署歸結為您部署的工具與降低複雜性與添加的複雜性之間的獎勵之間的不匹配。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器