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. solr和mongodb比较

    solr非常灵活,虽然mongodb添加索引查询速度比较快,但是solr查询比mongodb更加灵活,所以需要获取mongodb的oplog,实时将oplog中的数据推送到solr中 oplog A  ...

  2. maven的pom.xml深入理解

    maven的pom.xml的具体使用和各个xml标签的作用.这样设计的原理是什么? maven实战的第17章-18章是架构方面的知识

  3. php和java静态变量用途的思考

    静态变量有哪些用途? 比如创建单例对象. 统计访问次数.数量等等. 多线路和进程中可能会使用. 深入理解补充.... PHP 单例模式解析和实战 php设计模式——单例模式 php static 与 ...

  4. vim 学习笔记

    vim介绍:一款编辑器,另外一般linux系统会自带,所以一般linux下日志.配置文件等 纯文本文件的修改编辑等通过vim操作 学会的好处:1 方便操作linux下日志.配置文件等纯文本文件 2 功 ...

  5. 1.Tomcat配置

    1.启动 解压缩安装包后,点击startup.bat,保持控制台窗口开启 浏览器中输入http://localhost:8080 后看到启动界面则表示启动成功 点击shutdown.bat则关闭Tom ...

  6. JAVA-1-HelloWorld

    public class HelloWorld{ public static void main(String[] args){ System.out.println("HelloWorld ...

  7. 转自:http://blog.sina.com.cn/s/blog_86e874d30101e3d8.html(谢谢原文作者),Win7下安装CentOS 6.5双系统

    经过一下午的折腾,终于在64位的Windows 7上面成功安装了CentOS 6.5(64bit)系统,中途因为硬盘分区的问题失败了一次.下面是安装过程: 在安装过程中借助了这篇文章的内容:http: ...

  8. ACM中常用的C/C++函数

    只大概说明功能,具体用法请自行百度. C函数 memset:按字节填充地址空间 sscanf:从一个字符串中格式化读取变量 sprintf:将变量格式化写入字符串中 atoi:字符串转int atof ...

  9. javascript 关于闭包的知识点

    javascript 关于闭包的认识 概念:闭包(closure)是函数对象与变量作用域链在某种形式上的关联,是一种对变量的获取机制. 所以要大致搞清三个东西:函数对象(function object ...

  10. javascript之闭包深入理解(二)

    在上一节中,详细理解了作用域链和垃圾回收机制,似乎这两点跟闭包关系不大,但是仔细想一想就会发现,其实不然.这一节将通过上一部分的说明详细理解闭包.请看代码: function createCompar ...