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的更多相关文章

  1. Web Components之Custom Elements

    什么是Web Component? Web Components 包含了多种不同的技术.你可以把Web Components当做是用一系列的Web技术创建的.可重用的用户界面组件的统称.Web Com ...

  2. 自定义元素(custom elements)

    记录下自定义html自定义元素的相关心得: 浏览器将自定义元素保留在 DOM 之中,但不会任何语义.除此之外,自定义元素与标准元素都一致 事实上,浏览器提供了一个HTMLUnknownElement, ...

  3. [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 ...

  4. 使用custom elements和Shadow DOM自定义标签

    具体的api我就不写 官网上面多  如果不知道这个的话也可以搜索一下 目前感觉这个还是相当好用的直接上码. <!DOCTYPE html> <html lang="en&q ...

  5. window 属性:自定义元素(custom elements)

      概述 Web Components 标准非常重要的一个特性是,它使开发者能够将HTML页面的功能封装为 custom elements(自定义标签),而往常,开发者不得不写一大堆冗长.深层嵌套的标 ...

  6. HTML Custom Elements & valid name

    HTML Custom Elements & valid name valid custom element name https://html.spec.whatwg.org/multipa ...

  7. HTML Custom Elements (v1)

    HTML Custom Elements (v1) https://developers.google.com/web/fundamentals/web-components/customelemen ...

  8. Knockoutjs:Component and Custom Elements(翻译文章)

    Knockoutjs 的Components 是一种自定义的组件,它以一种强大.简介的方式将你自己的ui代码组织成一种单独的.可重用的模块,自定义的组件(Component)有以下特点: 1.可以替代 ...

  9. webAssmebly实现js数组排序 使用custom elements和Shadow DOM自定义组件

    直接上码了……………… .wat源码 (module (type $t0 (func (param i32 i32))) (type $t1 (func (result i32))) (type $t ...

随机推荐

  1. JS 实现 Tab标签切换功能

    Tab标签切换 效果图: HTML部分: <div class="wrap">     <ul id="tag">       < ...

  2. Centos 5.2安装配置DNS服务器

    BIND安装配置(主从)我的系统环境:centos 5.2 作者:哈密瓜 主:我采用的是yum安装[root@linux src]#yum -y install bind* 生成rndc控制命令的ke ...

  3. angularjs自定义日期过滤器,如:周日(前天 21:24)

    今天给大家分享一个,我在项目中自定义的一个日期过滤器.具体过滤出来的效果可参看下图: 用法: {{ time | timeFilter }} filter: App.filter('timeFilte ...

  4. tribonacci

    Everybody knows Fibonacci numbers, now we are talking about the Tribonacci numbers: T[0] = T[1] = T[ ...

  5. vs code(egret wing) php配置与调试

    所需插件 下面是便于编写以及调试php的插件,可以从IDE Store中搜索. PHP Debug,PHP IntelliSense,PHP IntelliSence Cranne. 环境配置 找到项 ...

  6. iOS开发——C篇&结构体与枚举

    一:结构体与枚举的介绍: 结构体与枚举:是一种存储复杂的数据结构体:是用户自定义的一种类型,不同类型的集合,而数组是相同类型变量的集合. 二:结构体的创建 struct user {     char ...

  7. 大小写转换,split分割

    一.大小写转换 1.定义和用法 toUpperCase() 方法用于把字符串转换为大写. toLowerCase() 方法用于把字符串转换为小写.    用法: stringObject.toUppe ...

  8. 一个简单LINUX程序的逆向

    开始之前的准备: 反汇编:IDA 十六进制编辑器: Hexworkshop LINUX环境: KALI LINUX 调试: EDB (KALI自带的) 一个简单的动态追码, 大牛们就略过吧…… 用16 ...

  9. sae Servlet class XXXX is not a javax.servlet.Servlet

    以前都是使用myeclipse开发web工程上传sae后没有问题,但是使用javaee导出war包上传sae 无法访问 Servlet class  XXXX is not a javax.servl ...

  10. spark1.1.0源码阅读-dagscheduler and stage

    1. rdd action ->sparkContext.runJob->dagscheduler.runJob def runJob[T, U: ClassTag]( rdd: RDD[ ...