成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Web Components 系列之實現 MyCard 的基本布局

開發 前端
在這篇文章中,我們只使用 Custom Elements 和 Templates 實現了基本布局和樣式,實用價值基本為零。

前言

前面針對 Web Components 學習了一些基本的理論知識,我們了解到的概念有:

  • Custom Elements
  • Shadow DOM
  • Templates
  • Slots

以及和這些概念相關的子知識點。

理論知識基本上夠用了,從現在開始我們需要將理論運用到實踐中,讓理論為實踐服務。今天,我們就使用 Web Components 的相關知識來實現 MyCard 的制作,原型呢就以我們人人都有的身份證做參照吧。

最終實現的基本布局效果如下:

使用 Templates 布局

這里我們使用 HTML 模板將布局先構建出來,代碼如下:

<template id="card_layout">
<style>
* {
box-sizing: border-box;
}

:host {
display: inline-block;
width: 400px;
height: 240px;
border: 1px solid black;
border-radius: 10px;
box-shadow: -2px -2px 5px 0px #7a8489;
}

.container {
display: flex;
flex-direction: column;
padding: 10px;
height: 100%;
}

.card-body {
flex: 1;
display: flex;
}

.card-footer {
padding: 10px 0;
}

.main-info {
flex: 2;
}

.photo {
flex: 1;
display: flex;
align-items: center;
}

.photo img{
width: 100%;
}

.info-row {
display: flex;
padding-top: 15px;
}

.info-column {
display: flex;
align-items: center;
}

.info-title {
padding: 0 10px;
color: #0e5bd3;
font-size: 12px;
word-break: keep-all;
}

.info-content {
letter-spacing: 2px;
}
</style>
<div class="container">
<div class="card-body">
<div class="main-info">
<div class="info-row">
<div class="info-column">
<div class="info-title">姓名</div>
</div>
<div class="info-content">編程三昧</div>
</div>
<div class="info-row">
<div class="info-column">
<div class="info-title">性別</div>
<div class="info-content"></div>
</div>
<div class="info-column">
<div class="info-title">民族</div>
<div class="info-content"></div>
</div>
</div>
<div class="info-row">
<div class="info-column">
<div class="info-title">出生</div>
<div class="info-content">2022</div>
</div>
<div class="info-column">
<div class="info-title"></div>
<div class="info-content">12</div>
</div>
<div class="info-column">
<div class="info-title"></div>
<div class="info-content">12</div>
</div>
<div class="info-column">
<div class="info-title"></div>
</div>
</div>
<div class="info-row">
<div class="info-column">
<div class="info-title">住址</div>
</div>
<div class="info-content">xx省xx市xx區xx街道xx小區xx樓xx單元xx樓xx室</div>
</div>
</div>
<div class="photo">
<img src="./static/photo.jpg">
</div>
</div>
<div class="card-footer">
<div class="info-row">
<div class="info-column">
<div class="info-title">公民身份號碼</div>
</div>
<div class="info-content">12345678901234567X</div>
</div>
</div>
</div>

</div>
</template>

創建自定義元素

使用我們前面學習過的方法,創建一個基本的自定義元素 my-card,在自定義組件中引入 Templates 布局,代碼如下:

class MyCard extends HTMLElement {
constructor () {
super();
this.shadow = this.attachShadow({mode: "open"});
let tempEle = document.getElementById("card_layout");
this.shadow.appendChild(tempEle.content);
}
}
customElements.define("my-card", MyCard);

使用自定義元素

在 HTML 的 body 中引入 my-card 標簽:

<my-card></my-card>

總結

最終實現的效果如文章開頭所示。

在這篇文章中,我們只使用 Custom Elements 和 Templates 實現了基本布局和樣式,實用價值基本為零。

在后續中,會加入 Slots 讓自定義元素實現可復用的效果。

~


責任編輯:武曉燕 來源: 編程三昧
相關推薦

2022-02-10 22:24:05

DOM結構工具

2022-02-09 20:20:30

瀏覽器組件化網頁

2024-02-26 09:13:35

WebComponents開源項目

2022-02-16 08:12:03

組件樣式元素

2014-05-26 15:35:55

Web組件Web Compone

2023-11-03 08:04:47

Web微前端框架

2014-05-19 10:55:12

Web組件Web Compone

2022-02-25 10:44:38

Web前端框架

2016-08-30 21:09:33

2024-11-12 13:34:25

2014-05-26 17:26:16

Web ComponeGMU

2025-03-27 03:30:00

Web框架組件

2015-02-01 09:26:10

2024-05-06 08:36:30

Web組件開發

2022-03-21 09:40:48

TektonJenkinsPipeline

2018-09-18 10:11:21

前端vue.jsjavascript

2011-05-27 15:56:30

Android

2022-06-16 07:31:41

Web組件封裝HTML 標簽

2021-02-24 08:32:45

Web Compone前端Web 應用

2022-03-10 13:57:23

TektonJenkinsPipeline
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 99久久精品免费视频 | 久草综合在线 | 色综合视频 | 在线欧美 | 亚洲午夜精品视频 | 日韩一级 | 性国产丰满麻豆videosex | 精品一区二区在线观看 | 午夜影院视频在线观看 | 国产精品久久久久久久久久久久久 | 亚洲视频区 | 黑人精品xxx一区一二区 | www.激情.com| 久久中文网 | 欧美网站一区二区 | 操操网站| 成人免费观看视频 | 一级毛片免费完整视频 | 国产在线精品一区 | 中文字幕日韩专区 | 国产精品a久久久久 | 狠狠干2020| 在线婷婷| 久久久久香蕉视频 | 国产精品国产三级国产aⅴ中文 | 91久久精品国产 | 精品欧美一区二区精品久久 | 亚洲精品自在在线观看 | 人人做人人澡人人爽欧美 | 日韩成人在线电影 | 久久在看| 性色综合 | 精品成人av | 成人二区 | 亭亭五月激情 | 婷婷激情在线 | 免费国产一区二区 | 国内精品免费久久久久软件老师 | 国产精品视频久久久久久 | 精品综合久久久 | 粉嫩av久久一区二区三区 |