[Angular] How to styling ng-content
Let's say you are builing a reuseable component. The style structure like this:
div > input
If you want to style this input field, it can be quite easy, we can just use :host selector:
:host input {
outline: none;
border: none;
}
But one day you figure out that hard cord input into the component might not be a good idea. You want to use content projection 'ng-content' to do that. Now the html stucture boecomes:
div > ng-content
Even you know the ng-content will be the input field. But he will find that your styling no longer works.
This is because Angular style encapsulation. It tries to preserve the style of projection element (because the element is not part of component, it has its own styling, we don't want to break that).
So the way to solve this problem is using CSS '/deep/' selector.
:host /deep/ input {
outline: none;
border: none;
}
'/deep/' break angular style encapsulation. You can think it is a global css styling which can overwrite everything ..:P Sounds pretty prowerful, and a little bit damage, yes! it is.
For example, if you doning like this :
/deep/ input {
outline: none;
border: none;
}
You will find that, all the input fields in your app has been affected!! So to be safe, use with :host selector.
[Angular] How to styling ng-content的更多相关文章
- angular报错:angular.min.js:118Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq
报错代码如下: <div ng-controller="HelloAngular"> <p>{{greeting.text}},angular</p& ...
- Angular CLI 启动 版本ng 4
npm install -g angular-cli ng -v ng new project_name cd project_name ng serve 浏览器打开输入 localhost:4200
- angular 2 - 001 ng cli的安装和使用
angular cli 创建项目和组件 ng new my-app --skip-install cd my-app cnpm install ng serve localhost:4200 angu ...
- Angular源代码学习笔记-原创
时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...
- 利用angular打造管理系统页面
1 创建一个新的angular应用 ng new adminSystem 2 利用WebStorm打开adminSystem应用 3 借助AdminLTE这个开源项目来辅助开发 AdminLTE项目: ...
- 使用路由延迟加载 Angular 模块
使用路由延迟加载 Angular 模块 Angular 非常模块化,模块化的一个非常有用的特性就是模块作为延迟加载点.延迟加载意味着可以在后台加载一个模块和其包含的所有组件等资源.这样 Angular ...
- Angular07 利用angular打造管理系统页面
1 创建一个新的angular应用 ng new adminSystem 2 利用WebStorm打开adminSystem应用 3 借助AdminLTE这个开源项目来辅助开发 AdminLTE项目: ...
- angular常见问题总结
本文引自:https://www.cnblogs.com/zhoulujun/p/8881414.html 这篇是对angularJS的一些疑点回顾,是对目前angularJS开发的各种常见问题的整理 ...
- Ngnice-国内ng学习网站
今天给angular新手介绍一个国内开源的ng学习网站http://www.ngnice.com/这是由一批ng爱好者在雪狼大叔的带领下共同开发完成,致力于帮助更多的ng新人,他们分别是: ckken ...
随机推荐
- 洛谷 P3371 【模板】单源最短路径
P3371 [模板]单源最短路径 题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入输出格式 输入格式: 第一行包含三个整数N.M.S,分别表示点的个数.有向边的个数.出 ...
- 深入理解javascript之原型
理解原型 原型是一个对象.其它对象能够通过它实现属性继承. 不论什么一个对象都能够成为继承,全部对象在默认的情况下都有一个原型.由于原型本身也是对象,所以每一个原型自身又有一个原型. 不论什么一个对象 ...
- Rsync 指令的使用方法
RsyncLinux版下载:http://rsync.samba.org/download.htmlWindows版下载:https://www.itefix.no/i2/cwrsync-get 选( ...
- 新技能 get —— 如何校验 md5(windows)
我们在某资源网站上下载完成指定文件后,尤其是一些下载所需较高时长的大型文件,如何检验下载的文件是否完好,也即如何保证和原始网站上的资源一样.此时就要用到检验码的机制,一般文件的下载界面,通常都会给出此 ...
- TypeScript基础知识
一. TypeScript是js的超集,可以应用所有js语法 二. 特点: 1. 优点 a. 可以在编译阶段就发现大部分错误,这总比在运行时候出错好 b. 同一目录下不同文件中,使用统一命名,会有命名 ...
- MFC窗口显隐
使用SetLayeredWindowAttributes可以方便的制作透明窗体,此函数在w2k以上才支持,而且如果希望直接使用的话,可能需要下载最新的SDK.不过此函数在w2k的user32.dll里 ...
- Windows下多个Mysql实例配置主从
序: 网上有很多类似的文章,也是各种百度出来的,但是对于多数刚开始接触MYSQL主从的小白来说,网上文章的代码里面很多技术点都没有理解,有跌打误撞碰上的,但多数都是这篇文章卡主了,换篇文章接着 ...
- 洛谷——U10783 名字被和谐了
https://www.luogu.org/problem/show?pid=U10783 题目背景 众所周知,我们称g是a的约数,当且仅当g是正数且a mod g = 0. 众所周知,若g既是a的约 ...
- 配置PL/SQL Developer连接server数据库
配置PL/SQL Developer连接server数据库 远程应用server上安装client客户端软件,可在oracle官网上下载. 举例: 环境 应用server操作系统 WIN 7 本地地址 ...
- 学习笔记:TypeScript入门——基础类型
前言: TypeScript官网断断续续看过几遍,不知道项目中如何使用,有机会还是要实践一下.现在再把文档上不懂的知识点理一遍. 基础类型 1.什么是元组Tuple? 元组类型允许表示一个已知元素数量 ...