General Sibling Combinator
6) General Sibling Combinator
The element1~element2 selector
matches occurrences of element2 that are preceded
by element1.
A general sibling combinator matches elements based on sibling relationships.
<html>
<head>
<style>
h1 ~ p {
margin-left: 200px;
}
</style>
</head>
<body>
<h1>This is heading </h1>
<p> Now i have realtionship with h1 </p>
<p> Now i have realtionship with h1</p>
<p> Now i have realtionship with h1</p>
<div>
<p> Now i do no have realtionship with h1</p>
</div>
<p>Now i have realtionship with h1.</p>
<span>
<p> Now i do no have realtionship with h1</p>
</span>
<p>Now i have realtionship with h1.</p>
</body>
</html>
<html>
<head>
<style>
p~ul {
background: #ff0000;
}
</style>
</head>
<body>
<div> A div element.</div>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<p>The first paragraph.</p>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<div> B div element.</div>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<div> c div element.
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</div>
<div> D div element.</div>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
No comments:
Post a Comment