HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line

HTML Card

Introduction

A card is a versatile and expandable content container. It contains choices for headers and footers, a large content selection, contextual background colors, and strong display settings. If you're acquainted with Bootstrap 3, cards replace our previous panels, wells, and thumbnails. Similar functionality to those components is offered as modifier classes for cards.

Regarding web development, no tool is as basic as CSS and HTML, the two languages responsible for producing visually attractive and effective site designs. A card design is one of any website's most common design components. It is a fantastic technique for displaying content compact and orderly, making it easy for the user to explore the information.

With free HTML and CSS card code samples accessible online, designers and developers can quickly experiment with various layouts and functionality.

Requirements

  • Create a series of cards, each component comprising a title, picture, content, and, optionally, a footer.
  • Each card in the collection should be the same height. The optional card footer should be attached to the bottom of the card.
  • Each card in the group should match up in two dimensions—vertically and diagonally.

Example

Cards are constructed with as minimal markup and styles as possible yet still manage to give a ton of control and flexibility. Built using Flexbox, they allow simple alignment and combine nicely with other Bootstrap components. They have no margin by default, so utilize spacing tools as required.

Below is an example of a basic card with mixed content and a set width. Cards have no predetermined width to start; thus, they'll automatically occupy the entire width of their parent element. That is readily customizable with our numerous size choices.

HTML

<div class="card">

  <img src="another_avatar.png" alt="Avatar" style="width:100%">

  <div class="container">

    <h4><b>Jane Smith</b></h4>

    <p>Designer & Developer</p>

  </div>

</div>

CSS

.card {

  /* Add shadows to create the "card" effect */

  boxshadow: 0 9px 11px 7 rgba(0, 0.3, 0, 0.3);

  transition: 0.4s;

}

/* On mouse-over, add a deeper shadow */

.card: hover {

  boxshadow: 0 11px 0px 0 rgba(0, 0.3, 0, 0.4);

}

/* Add some padding inside the card container */

.container {

  padding: 8px 20px;

}

Choices Made

Each card is set out using a CSS grid layout despite the layout being one-dimensional. That permits the use of content sizing for the grid tracks. To put up a single-column grid, we may utilize the following:

.card {

  display: grid;

grid-template-rows: max-content 200px 1fr;

}
  • Display: grid transforms the element into a grid container. The three values of the grid-template-rows property split the grid into a minimum of three rows, determining the height of the first three children of the card in sequence.
  • Each card comprises a <header>, <image>, and <div> in that sequence, with some additionally including a <footer>.
  • The track, or heading row, cannot extend since its max-content setting is applied.
  • The picture track is set at 200 pixels in height. The third track, where the content resides, is set to 1fr. That implies that it will fill any excess space.
  • Any children beyond the three with explicitly stated widths produce rows in the implicit grid, which fits the material supplied. These are auto-sized by default. If a card has a footer, it is auto-sized. The footer, when present, adheres to the bottom of the grid. The footer is auto-sized to accommodate its content; the content <div> then stretches to take up any surplus space.

The following ruleset produces the grid of cards:

.cards {

  display: grid;

grid-template-columns: repeat(auto-fill, min-max(230px, 1fr));

  gap: 20px;

}

The grid-template-columns attribute determines the widths of the grid columns. In this scenario, we configured the grid to auto-fill, with repeating columns that are at least 230 pixels but allowed to extend to cover the available space. The gap attribute establishes a space of 20 pixels between adjacent rows and adjacent columns.

Structure of HTMLWe will first organize the HTML for our card. Five elements are similar while looking at each card. I've shown them in the figure that follows:

Parts of our Card

  • Card: The main section and the header are the two child components in our parent component.
  • Header: All of the HTML headings are included in this component.
  • Primary section: The icon and the description are the two child components of this component.
  • Google's emblem is located in this component.
  • The description of it is included in this element. Primary section.

Alternative Techniques

  • Each card may alternatively be laid out using Flexbox. The flex property on each row, instead of the card container
  • It is used with Flexbox to define the size of each card's rows.
  • With Flexbox, the kids, not the parents, decide the Flex items' dimensions.
  • Whether you opt to utilize Grid or Flexbox depends on your choice, whether you like managing the tracks from the container or prefer attaching rules to the items.
  • We picked a grid for the cards since you normally want them lined up vertically and horizontally. Additionally, a subgrid may be used to connect the components of each card to the components of neighboring cards. Flex has no hack-free counterpart to Subgrid.

Adding an External Stylesheet to a Card Component

Method

So you understand how to add CSS to HTML. Allow me to use an external stylesheet for this exercise. Add to the element by creating a new file called style.css.

CSS rule set

To apply a 50% width to the picture, add this:

img {

width: 50%;

}
  • To choose and style an element, you need the attribute you want to style, its value, and a selector.
  • The property is enclosed in curly brackets, separated by colons, and concluded with semicolons; this arrangement is called a ruleset.

Accessibility considerations

Depending on the content of your card, there may be things you could or should change to boost accessibility. For a longer discussion of these issues, see Heydon Pickering's Inclusive Components: Card.