[Polymer] Custom Elements: Styling
Code:
<dom-module id="business-card">
<template>
<div class="card">
<h1>Joe Maddalone</h1>
<h2>Instructor</h2>
<h3>egghead.io</h3>
</div>
<style>
.card{
background-color: #e8e8e8;
box-shadow: 0 0 1px #e8e8e8;
position: relative;
font-family: monospace;
display: flex;
width: 350px;
height: 200px;
flex-flow: column wrap;
margin: 20px;
}
.card:before, .card:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width:300px;
background: rgba(0, 0, 0, 0.7);
box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7);
transform: rotate(-3deg);
}
.card:after {
transform: rotate(3deg);
right: 10px;
left: auto;
}
.card h1,.card h2,.card h3 {
font-weight: normal;
color: var(--custom-text-color,--text-color)
}
.card h1 {
flex:4;
padding-top: 50px;
font-size: 24px;
align-self: center;
}
.card h2 {
flex:3;
margin-top: -30px;
align-self: center;
font-size: 12px;
}
.card h3 {
flex:1;
font-size: 14px;
align-self: flex-end;
margin-right: 20px;
}
</style>
</template>
<script>
Polymer( {
is: "business-card"
} )
</script>
</dom-module>
Using parent compoment in css :host
- remove the <div class="host"></div>
- change .card class to :host, which can be consider as <div class=":host"><h1>..</h1><h2>..</h2><h3>..</h3></div>
<dom-module id="business-card">
<template>
<h1>Joe Maddalone</h1>
<h2>Instructor</h2>
<h3>egghead.io</h3>
<style>
:host {
background-color: #e8e8e8;
box-shadow: 0 0 1px #e8e8e8;
position: relative;
font-family: monospace;
display: flex;
width: 350px;
height: 200px;
flex-flow: column wrap;
margin: 20px;
} :host:before, :host:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: rgba(0, 0, 0, 0.7);
box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7);
transform: rotate(-3deg);
} :host:after {
transform: rotate(3deg);
right: 10px;
left: auto;
} h1, h2, h3 {
font-weight: normal;
color: var(--custom-text-color, --text-color)
} h1 {
flex: 4;
padding-top: 50px;
font-size: 24px;
align-self: center;
} h2 {
flex: 3;
margin-top: -30px;
align-self: center;
font-size: 12px;
} h3 {
flex: 1;
font-size: 14px;
align-self: flex-end;
margin-right: 20px;
}
</style>
</template>
<script>
Polymer( {
is: "business-card"
} )
</script>
</dom-module>
Create variable in css:
:host{
--card-color: #e8e8e8;
--text-color: #222;
}
:host {
background-color: var(--card-color);
box-shadow: 0 0 1px var(--card-color);
...
}
Default value:
background-color: var(--custom-card-color, --card-color);
box-shadow: 0 0 1px var(--custom-card-color, --card-color);
--card-color will be the default value if --custom-card-color not exists.
------------------------------
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Polymer</title>
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="my-card.html">
</head>
<body>
<my-card></my-card>
</body>
</html>
my-card.html:
<link rel="import" href="./business-card.html">
<dom-module id="my-card">
<template>
<business-card></business-card>
<business-card class="red"></business-card>
<style>
.red{
--custom-card-color: red;
--custom-text-color: white;
}
</style>
</template>
<script>
Polymer( {
is: "my-card"
} )
</script>
</dom-module>
busniess-card.html:
<dom-module id="business-card">
<template>
<h1>Joe Maddalone</h1>
<h2>Instructor</h2>
<h3>egghead.io</h3>
<style>
:host{
--card-color: #e8e8e8;
--text-color: #222;
}
:host {
background-color: var(--custom-card-color, --card-color);
box-shadow: 0 0 1px var(--custom-card-color, --card-color);
position: relative;
font-family: monospace;
display: flex;
width: 350px;
height: 200px;
flex-flow: column wrap;
margin: 20px;
} :host:before, :host:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: rgba(0, 0, 0, 0.7);
box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7);
transform: rotate(-3deg);
} :host:after {
transform: rotate(3deg);
right: 10px;
left: auto;
} h1, h2, h3 {
font-weight: normal;
color: var(--custom-text-color, --text-color)
} h1 {
flex: 4;
padding-top: 50px;
font-size: 24px;
align-self: center;
} h2 {
flex: 3;
margin-top: -30px;
align-self: center;
font-size: 12px;
} h3 {
flex: 1;
font-size: 14px;
align-self: flex-end;
margin-right: 20px;
}
</style>
</template>
<script>
Polymer( {
is: "business-card"
} )
</script>
</dom-module>

[Polymer] Custom Elements: Styling的更多相关文章
- Web Components之Custom Elements
什么是Web Component? Web Components 包含了多种不同的技术.你可以把Web Components当做是用一系列的Web技术创建的.可重用的用户界面组件的统称.Web Com ...
- 自定义元素(custom elements)
记录下自定义html自定义元素的相关心得: 浏览器将自定义元素保留在 DOM 之中,但不会任何语义.除此之外,自定义元素与标准元素都一致 事实上,浏览器提供了一个HTMLUnknownElement, ...
- [HTML5] Render Hello World Text with Custom Elements
Custom elements are fun technology. In this video, you will learn how to set one up and running in l ...
- 使用custom elements和Shadow DOM自定义标签
具体的api我就不写 官网上面多 如果不知道这个的话也可以搜索一下 目前感觉这个还是相当好用的直接上码. <!DOCTYPE html> <html lang="en&q ...
- window 属性:自定义元素(custom elements)
概述 Web Components 标准非常重要的一个特性是,它使开发者能够将HTML页面的功能封装为 custom elements(自定义标签),而往常,开发者不得不写一大堆冗长.深层嵌套的标 ...
- HTML Custom Elements & valid name
HTML Custom Elements & valid name valid custom element name https://html.spec.whatwg.org/multipa ...
- HTML Custom Elements (v1)
HTML Custom Elements (v1) https://developers.google.com/web/fundamentals/web-components/customelemen ...
- Knockoutjs:Component and Custom Elements(翻译文章)
Knockoutjs 的Components 是一种自定义的组件,它以一种强大.简介的方式将你自己的ui代码组织成一种单独的.可重用的模块,自定义的组件(Component)有以下特点: 1.可以替代 ...
- webAssmebly实现js数组排序 使用custom elements和Shadow DOM自定义组件
直接上码了……………… .wat源码 (module (type $t0 (func (param i32 i32))) (type $t1 (func (result i32))) (type $t ...
随机推荐
- php访问方法外变量
class Capture { private static $_CapSite = 222; function dd() { echo self::$_CapSite; } } $cc=new Ca ...
- java制作简单的坦克大战
坦克大战是我们小时候玩红白机时代的经典游戏,看到有不少小伙伴都使用各种语言实现了一下,手痒痒,也使用java做的一个比较简单的坦克大战,主要面向于学过Java的人群,与学了一段时间的人,有利于面向对象 ...
- HAOI 硬币购物
试题描述: 现在一共有4种硬币,面值各不相同,分别为ci(i=1,2,3,4).某人去商店买东西,去了tot次,每次带di枚ci硬币,购买价值为si的货物.请问每次有多少种付款方法. 输入: 第一行包 ...
- 如何实现一个通用的IHttpHandler 万能的IHttpHandler HttpWebRequest文件上传
昨天遇到一个比较奇怪的需求,大致是需要在服务器上部署一个http服务,但是服务的具体功能不知道,以后在客服端实现.这里介绍一下系统背景,有一个系统运(部署在美国)行了很多年了,给系统产生了很多文件,现 ...
- web前端开发框架搜集
Web应用框架(Web application framework)是一种电脑软件框架,用来支持动态网站.网络应用程序及网络服务的开发.这种框架有助于减轻网页开发时共通性活动的工作负荷,例如许多框架提 ...
- iOS开发——C篇&动态内存分配
再C语言中关于内存是一个很重要的知识点,所以今天我就从c语言的内存分配开始为大家解析一下C语言再iOS开发中非常重要的一些知识. 1:malloc函数的介绍 C语言中开辟内存空间:malloc函数 再 ...
- 如何访问google
http://www.williamlong.info/archives/3983.html http://jingyan.baidu.com/article/29697b91316f2fab20de ...
- 设置 cell点击 背景色
//设置 cell点击 背景色 cell.selectionStyle = UITableViewCellSelectionStyleDefault; cell.selectedBackgroundV ...
- IOS之动画
IOS之动画 15.1 动画介绍 15.2 Core Animation基础 15.3 隐式动画 15.4 显式动画 15.5 关键帧显式动画 15.6 UIView级别动画 15.1 动画介绍 ...
- Go http.HandlerFunc()
//http.Handler type Handler interface { ServeHTTP(ResponseWriter, *Request) } type HandlerFunc func( ...