Friday, July 30, 2021
Combinators in CSS is term used to define a style that combines more than one selectors together.
For example let's say you have the following markup
<div id="combinator-div"><h1>I'll be back.</h1></div>
<h1>Combinator me</h1>
Let's say you only want to apply the styles for the <h1> tag that's inside the combinator-div, you can use a combinator style which is a combination of the div id and the h1 tag as combination to style a very specific element on the page. The style would look like the following
#combinator-div h1 {font-family: sans-serif; font-weight: bold; color: green;}
If you run the page with the code then you would get the following output
As you can see only the I'll be back <h1> is styled, the other <h1> is just not cool enough to get styled.
There are more combinators that you can do that's more specific, they are the following:
Everything is green, including the <p> element inside the <article> element.
For example let's say you have the following markup
<div id="combinator-div"><h1>I'll be back.</h1></div>
<h1>Combinator me</h1>
Let's say you only want to apply the styles for the <h1> tag that's inside the combinator-div, you can use a combinator style which is a combination of the div id and the h1 tag as combination to style a very specific element on the page. The style would look like the following
#combinator-div h1 {font-family: sans-serif; font-weight: bold; color: green;}
If you run the page with the code then you would get the following output
As you can see only the I'll be back <h1> is styled, the other <h1> is just not cool enough to get styled.
There are more combinators that you can do that's more specific, they are the following:
- Adjacent Sibling +
- Applies the styles to the adjacent tag only the matches the combinator
- Let's say you have the following style defined as your combinator
- h3 + p {font-family: sans-serif; font-weight: bold; color: green;}
- And the following HTML markup
<p>I am green</p>
<h3>I am green</h3>
<p>I am green</p>
<p>I am green</p>
<h3>I am green</h3>
<p>I am green</p>
- General Sibling ~
- The general sibling is as the name implies it's not as strict, as long as there's an <h3> as the parent all the <p> tags will be applied the styles
- Let's you have the following style
- h3 ~ p {font-family: sans-serif; font-weight: bold; color: green;}
- With the following HTML
<p>I am green</p>
<h3>I am green</h3>
<p>I am green</p>
<p>I am green</p>
<p>I am green</p>
The output is
- Child >
- Applies style to only the direct child of the first element for example if you have the following style
- div > p {font-family: sans-serif; font-weight: bold; color: green;}
- With the following HTML
<div>
<p>I am green</p>
<article>
<p>I am green</p>
</article>
<p>I am green</p>
</div>
The output is
As you can see the <p> in the <article> tag is not green
- Descendent
- which is just white separator is the ones being used the most, this combinator will seek out all the occurrences of the second element and apply the style so if we have the following style div p {font-family: sans-serif; font-weight: bold; color: green;} with the same HTML as the one above. We would have the following output
Everything is green, including the <p> element inside the <article> element.
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
ReplyDeleteNice Blog. I also have some information about Gratisol labs which is a leading Clinical Research training Institute providing Clinical Research Certification Coures . This Clinical Research Certification Course is covered with 4 Modules of Certification. Pharmacovigilance Certification Training, Clinical Data Management Certification Training,Regulatory Affairs Course and Medical Writing course and SAS Certification Training
https://gratisol.com/clinical-data-management-training/
https://gratisol.com/pharmacovigilance-training/
https://gratisol.com/regulatory-affairs-training/
https://gratisol.com/clinical-sas-certification-training/
https://gratisol.com/clinical-research-course/