Welcome to CSS Tutorial!
Let's have some fun
What's in it for you ?
- Detailed Description of Individual Sections with Appropriate Examples
- Made CSS Simple for Beginners
- Examples Demonstrating usage of CSS properties to specific use.
- One Quiz and a Final Self Assesment Test.
IWT ASSIGNMENT
Assigned by- Prof. Bharati Mishra
Submitted By :
-
Saidatta Sahu [B118051]
-
Sidhartha Mallick [B118055]
-
Subham Hazra [B118057]
CSS Selectors
CSS selectors are used to find (or select) the HTML elements you want to style.
We can divide CSS selectors into five categories:
- Simple selectors (select elements based on name, id, class)
- Combinator selectors (select elements based on a specific relationship between them)
- Pseudo-class selectors (select elements based on a certain state)
- Pseudo-elements selectors (select and style a part of an element)
- Attribute selectors (select elements based on an attribute or attribute value)
This page will explain the most basic CSS selectors.
The CSS element Selector
The element selector selects HTML elements based on the element name.
Example
Here, all <p> elements on the page will be center-aligned, with a red text color
html: <p>This is center-aligned, with a red text color</p>
CSS: p { text-align: center; color: red; }
Result
This is center-aligned, with a red text color
The CSS id Selector
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique element!
To select an element with a specific id, write a hash (#) character, followed by the id of the element.
Example
The CSS rule below will be applied to the HTML element with id="para1"
html: <p id="para1">This is center-aligned, with a red text color</p>
CSS: #para1 { text-align: center; color: blue; }
Result
This is para1 with center-aligned, with a red text color
The CSS class Selector
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
Example
In this example all HTML elements with class="center" will be red and center-aligned:
html: <p class="para2">This is center-aligned, with a red text color</p>
CSS: .para2 { text-align: center; color: green; }
Result
This is para2 with center-aligned, with a red text color
The CSS Universal Selector
The universal selector (*) selects all HTML elements on the page.
Example
The CSS rule below will affect every HTML element on the page:
* { text-align: center; color: red; }
The CSS Grouping Selector
The grouping selector selects all the HTML elements with the same style definitions.
Look at the following CSS code (the h1, h2, and p elements have the same style definitions):
h1, h2, p { text-align: center; color: red; }
It will be better to group the selectors, to minimize the code.
To group selectors, separate each selector with a comma.
The CSS background properties are used to define the background effects for elements.
CSS background-color
The background-color property specifies the background color of an element.
The background color of a page is set like this:
body { background-color: lightblue; }
You can set the background color for any HTML elements:
Here, the h1 , p, and
div elements will have different background colors:
h1 { background-color: green; } div { background-color: lightblue; } p { background-color: yellow; }
Opacity / Transparency
The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 - 1.0. The lower value, the more transparent:
Example
HTML: <div class="first"> <h1>opacity 0.4</h1> </div> <div class="second"> <h1>opacity 0.4</h1> </div> <div class="third"> <h1>opacity 0.6</h1> </div>
CSS: div { background-color: green; } div.first { opacity: 0.2; } div.second { opacity: 0.4; } div.third { opacity: 0.6; }
Result
opacity 0.2
opacity 0.4
opacity 0.6
CSS background-image
The background-image property specifies an image to use as the background of an element.
By default, the image is repeated so it covers the entire element.
body { background-image: url("pic.jpg"); }
CSS background-repeat
By default, the background-image property repeats an image both horizontally and vertically.
CSS background-position
The background-position property is used to specify the position of the background image.
Example
body { background-image: url("pic.png"); background-repeat: no-repeat; background-position: center; }
Result
Styling Fonts with CSS
Choosing the right font and style is very crucial for the readability of text on a page.
CSS provide several properties for styling the font of the text, including changing their face,
controlling their size and boldness, managing variant, and so on.
The font properties are: font-family, font-style, font-weight, font-size, and font-variant.
Font Family:
The font-family property is used to specify the font to be used to render the text.
This property can hold several comma-separated font names as a fallback system, so that if the first
font is not available on the user's system, browser tries to use the second one, and so on.
Hence, list the font that you want first, then any fonts that might fill in for the first if it is
not available. You should end the list with a generic font family which are five — serif,
sans-serif,monospace,cursive and fantasy. A typical font family declaration might look like this:
Example
html: <h1>Here the font-family is "monospace".</h1>
CSS: h1 { font-family:monospace; }
Result
Here the font-family is "monospace".
Font Style:
The font-style property is used to set the font face style for the text content of an element.
The font style can be normal, italic or oblique. The default value is normal.
Let's try out the following example to understand how it basically works:
Example
html: <p class="normal">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Inventore,praesentium. </p> <p class="italic">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt, recusandae? </p> <p class="oblique">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sit, veniam! </p>
CSS: p.normal { font-style: normal; } p.italic { font-style: italic; } p.oblique { font-style: oblique; }
Result
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Inventore,praesentium.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sunt, recusandae?
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sit, veniam!
Font Size:
The font-size property is used to set the size of font for the text content of an element.
There are several ways to specify the font size values e.g. with keywords, percentage, pixels, ems,
etc.
Setting Font Size with Pixels
Setting the font size in pixel values (e.g. 14px, 16px, etc.) is a good choice when you need the
pixel accuracy. Pixel is an absolute unit of measurement which specifies a fixed length.
Let's try out the following example to understand how it basically works:
Example
html: <h1 class="normal">Here the Font-size is 36px. </h1> <p class="italic">Here the Font-size is 20px. </p>
CSS: h1 { font-size: 36px; } p { font-size: 18px; }
Result
Here the Font-size 36px.
Here the Font-size is 20px.
Defining the font sizes in pixel is not considered very accessible, because the user cannot change
the font size from the browser settings. For instance, users with limited or low vision may wish to
set the font size
much
larger than the
size specified by you.
Therefore, you should avoid using the pixels values and use the values that are relative to the
user's
default font size
instead if you want to create an inclusive design.
Setting Font Size with EM
The em unit refers to the font size of the parent element. When defining the font-size property, 1em
is equal to the
size of the font that applies to the parent of the element.
So, if you set a font-size of 20px on the body element, then 1em = 20px and 2em = 40px.
However, if you haven't set the font size anywhere on the page, then it is the browser default,
which is normally 16px.
Therefore, by default 1em = 16px, and 2em = 32px.
Let's take a look at the following example to understand how it basically works:
Example
html: <h1 class="normal">Here the Font-size 3em. </h1> <p class="italic">Here the Font-size is 2em </p>
CSS: h1 { font-size: 3em; } p { font-size: 2em; }
Result
Here the Font-size 3em.
Here the Font-size is 2em.
Font Weight:
The font-weight property specifies the weight or boldness of the font.
This property can take one of the following values: normal, bold, bolder, lighter, 100, 200, 300,
400, 500, 600, 700,
800, 900 and inherit.
- The numeric values 100-900 specify the font weights, where each number represents a weight greater than its predecessor. 400 is same as normal & 700 is same as bold.
- The bolder and lighter values are relative to the inherited font weight, while the other values such as normal and bold are absolute font weights.
Example
html: <h2 style="font-weight: 800">Here the font-Weight is "800". </h2> <h3 style="font-weight: 400">Here the font-Weight is "400". </h3>
CSS: h2 { font-weight:800; } h3 { font-weight:400; }
Result
Here the font-Weight is "800".
Here the font-Weight is "400".
Most of the fonts are only available in a limited number of weights; often they are available only in normal and bold. In case, if a font is not available in the specified weight, an alternate will be chosen that is the closest available weight.
Display
CSS height and width
The height and width properties are used to set the height and width of an element.
The height and width properties do not include padding, borders, or margins. It sets the
height/width of the
area inside
the padding, border, and margin of the element.
CSS height and width Values
The height and width properties may have the following values:
- auto - This is default. The browser calculates the height and width
- length - Defines the height/width in px, cm etc.
- % - Defines the height/width in percent of the containing block
- initial - Sets the height/width to its default value
- inherit - The height/width will be inherited from its parent value
Example
div { height: 200px; width: 50%; background-color: aliceblue; }
Result
Setting max-width
The max-width property is used to set the maximum width of an element.
The max-width can be specified in length values, like px, cm, etc., or in percent (%) of the
containing
block, or set to
none (this is default. Means that there is no maximum width).
The problem with the
div above occurs when the browser window is smaller than the width of the element. The
browser then adds a horizontal scrollbar to the page.
Using max-width instead, in this situation, will improve the browser's handling of small windows.
div { max-width: 400px; height: 150px; background-color: powderblue; }
Result
The value of the max-width property overrides width.
CSS Padding
The CSS padding properties are used to generate space around an element's content, inside of any
defined borders.
With CSS, you have full control over the padding. There are properties for setting the padding for
each side of an
element (top, right, bottom, and left).
Padding - Individual Sides
CSS has properties for specifying the padding for each side of an element:
- padding-top
- padding-right
- padding-bottom
- padding-left
All the padding properties can have the following values:
- length - specifies a padding in px, pt, cm, etc.
- % - specifies a padding in % of the width of the containing element
Example
div { padding-left:300px; padding-right:200px; padding-top:80px; padding-bottom:150px; }
Result
CSS Margins
The CSS margin properties are used to create space around elements, outside of any defined borders. With CSS, you have full control over the margins. There are properties for setting the margin for each side of an element (top, right, bottom, and left).
p { margin-top: 150px; margin-bottom: 100px; margin-right: 150px; margin-left: 80px; }
Result
This div element has a top margin of 150px, a right margin of 150px, a bottom margin of 100px, and a left margin of 80px.
CSS Comments
Comments are used to explain the code, and may help when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment is placed inside the style element, and starts with /* and ends with */
/* This is a single-line comment */ p { color: red; } p { color: red; /* Set text color to red */ } /* This is a multi-line comment */ p { color: red; }
Tables
The look of an HTML table can be greatly improved with CSS:
Table Borders
To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td elements:
Example
table, th, td { border: 1px solid black; }
Result
Firstname | Lastname |
---|---|
lorem | epsom |
Lois | Griffin |
Notice that the table in the example above has double borders. This is because both the table and the th and td elements have separate borders.
Collapse Table Borders
The border-collapse property sets whether the table borders should be collapsed into a single border:
Example
table { border-collapse: collapse; }
Result
Firstname | Lastname |
---|---|
lorem | epsom |
Lois | Griffin |
If you only want a border around the table, only specify the border property for table:
table { border: 1px solid black; }
Result
Firstname | Lastname |
---|---|
lorem | epsom |
Lois | Griffin |
Table Width and Height
Width and height of a table are defined by the width and height properties. The example below sets the width of the table to 100%, and the height of the "th" elements to 50px:
table { width: 100%; } th { height: 50px; }
Result
Firstname | Lastname | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Cleveland | Brown | $250 |
HorizontalVertical Alignment
The text-align property sets the horizontal alignment (like left, right, or center) of the
content in "th" or "td".
By default, the content of "th" elements are center-aligned and the content of "td" elements are
left-aligned.
The vertical-align property sets the vertical alignment (like top, bottom, or middle) of the content in
th or td.
By default, the vertical alignment of the content in a table is middle (for both th and td elements).
Example
td { height: 50px; vertical-align: bottom; text-align: center; }
Result
Firstname | Lastname | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Cleveland | Brown | $250 |
Postion
Position: static
This is a static element.
An element with position: static; is not positioned in any special way;
it is always positioned according to the normal flow of the page:
Position: relative
This is a position: relative element
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned
element will cause it to be adjusted away from its normal position.
Other content will not be adjusted to fit into any gap left by the element.
Position: fixed
The two UI components at the bottom-right and top-right corners are
fixed elements.
An element with position: fixed; is positioned relative to the viewport,
which means it always stays in the same place even if the page is scrolled.
The top, right, bottom, and left properties are used to position the element.
A fixed element does not leave a gap in the page where it would normally have been located.
Position: absolute
This < div> is an position: relative
An element with position: absolute; is positioned relative to the nearest positioned ancestor
(instead of positioned relative to the viewport, like fixed).
This < div> element has position: absolute;
Position: sticky
An element with position: sticky; is positioned based on the user's scroll position. A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).
Try to scroll inside this frame to understand how sticky positioning works.
Note: IE/Edge 15 and earlier versions do not support sticky position.
In this example, the sticky element sticks to the top of the page (top: 0), when you reach its scroll position.
Scroll back up to remove the stickyness.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.
Dropdowns
The dropdown appears when you hover on the element
Link 1
Link 2
Link 3
HTML: < div class="dropdown"> < span>Mouse over me< /span> < div class="dropdown-content"> < p>Hello World!< /p> < /div> < /div>
.dropdown { position: relative; display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); padding: 12px 16px; z-index: 1; } .dropdown:hover .dropdown-content { display: block; }
CSS Layout - Overflow
The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area. The overflow property has the following values:
- Default - The overflow is not clipped. The content renders outside the element's box
- hidden - The overflow is clipped, and the rest of the content will be invisible
- scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content
- auto - Similar to scroll, but it adds scrollbars only when necessary
Example
HTML: <h1> You can use the overflow property when you want to have better control of the layout. < br> The overflow property specifies what happens if content overflows an element's box. <h1>
CSS: div { background-color: #eee; width: 200px; height: 100px; border: 1px dotted black; overflow: scroll; }
Result
You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box. You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.
P.S - You can try other overflow options just by changing it in div style tag.
Note: The overflow property only works for block elements with a specified height.
Note: In OS X Lion (on Mac), scrollbars are hidden by default and only shown when being used (even though "overflow : scroll" is set).
Image and Icons
Image Overlay Icon
Hover over the image to see the overlay effect.
Example 1
HTML: < div class="container"> < img src="img_avatar.png" alt="Avatar" class="image"> < div class="overlay"> < a href="#" class="icon" title="User Profile"> < i class="fa fa-user">< /i> < /a> < /div> < /div>
CSS: .container { position: relative; width: 100%; max-width: 400px; } /* Make the image to responsive */ .image { width: 100%; height: auto; } /* The overlay effect (full height and width) - lays on top of the container and over the image */ .overlay { position: absolute; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; transition: .3s ease; background-color: red; } /* When you mouse over the container, fade in the overlay icon*/ .container:hover .overlay { opacity: 1; } /* The icon inside the overlay is positioned in the middle vertically and horizontally */ .icon { color: white; font-size: 100px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); text-align: center; } /* When you move the mouse over the icon, change color */ .fa-user:hover { color: #eee; }
Result
Fade in Overlay Icon
Hover over the image to see the effect.
Image Filters
The CSS filter property adds visual effects (like blur and saturation) to an element.
Example 2
HTML: < p>Apply a blur effect to the image:< /p> < img src="images/gal1.jpg" alt="img_avatar" width="300" height="300">
CSS: img { -webkit-filter: blur(5px); filter: blur(5px); }
Result:
Apply a blur effect to the image:
Explre other images effects and try them out.
ICONS
HTML: < div> < h4>Social Media:< /h4> < a href="#footer"> < img src="icons/instagram-brands.svg" style="width: 30px; height: 30px;" alt="insta"> < /a> < a href="#footer"> < img src="icons/twitter-brands.svg" style="width: 30px; height: 30px;" alt="twitter"> < /a> < a href="#footer"> < img src="icons/facebook-square-brands.svg" style="width: 30px; height: 30px;" alt="fb"> < /a> < /div>
Box model
All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content. Explanation of the different parts:
- Content - The content of the box, where text and images appear
- Padding - Clears an area around the content. The padding is transparent
- Border - A border that goes around the padding and content
- Margin - Clears an area outside the border. The margin is transparent
Example 1
HTML: < h2>Demonstrating the Box Model< /h2> < p> The CSS box model is essentially a box that wraps around every HTML element. < br> It consists of: borders, padding, margins, and the actual content. < /p> < div>This text is the content of the box. We have added a 50px padding ....< /div>
CSS: div { background-color: lightgrey; width: 300px; border: 15px solid green; padding: 50px; margin: 20px; }
Result
Demonstrating the Box Model
The CSS box model is essentially a box that wraps around every HTML element. It consists of: borders, padding, margins, and the actual content.
Width and Height of an Element
In order to set the width and height of an element correctly in all browsers, you need to
know how the box model works.
Here is the calculation:
320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px
The total width of an element should be calculated like this:
Total element width = width + left padding + right padding + left border + right border +
left margin + right margin
The total height of an element should be calculated like this:
Total element height = height + top padding + bottom padding + top border + bottom border +
top margin + bottom margin
Important: When you set the width and height
properties of an element with CSS, you just set the width and height of the content
area.
To calculate the full size of an element, you must also add padding, borders
and margins.
CSS Website Layout
A website is often divided into headers, menus, content and a footer:
Responsive Website Layout
By using some of the CSS code above, we have created a responsive website layout,
which varies
between two columns and full-width columns depending on screen width:
Example 1
CODE :
<!DOCTYPE html> <html> <head> <style> /* Header/Blog Title */ .header { padding: 30px; text-align: center; background: white; } .header h1 { font-size: 50px; } /* Style the top navigation bar */ .topnav { overflow: hidden; background-color: #333; } /* Style the topnav links */ .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; } /* Change color on hover */ .topnav a:hover { background-color: #ddd; color: black; } /* Create two unequal columns that floats next to each other */ /* Left column */ .leftcolumn { float: left; width: 75%; } /* Right column */ .rightcolumn { float: left; width: 25%; background-color: #f1f1f1; padding-left: 20px; } /* Fake image */ .fakeimg { background-color: #aaa; width: 100%; padding: 20px; } /* Add a card effect for articles */ .card { background-color: white; padding: 20px; margin-top: 20px; } /* Clear floats after the columns */ .row:after { content: ""; display: table; clear: both; } /* Footer */ .footer { padding: 20px; text-align: center; background: #ddd; margin-top: 20px; } /* Responsive layout - when the screen is less than 800px wide,
make the two columns stack on top of each other instead of next to each other */ @media screen and (max-width: 800px) { .leftcolumn, .rightcolumn { width: 100%; padding: 0; } } /* Responsive layout - when the screen is less than 400px wide,
make the navigation links stack on top of each other instead of next to each other */ @media screen and (max-width: 400px) { .topnav a { float: none; width: 100%; } } </style> </head> <body> <div class="header"> <h1>Test</h1> <p>Resize the browser window to see the effect.</p> </div> <div class="topnav"> <a href="#">Link</a> <a href="#">Link</a> <a href="#">Link</a> <a href="#" style="float:right">Link</a> </div> <div class="row"> <div class="leftcolumn"> <div class="card"> <h2>Your Heading</h2> <h5>Title description</h5> <div class="fakeimg" style="height:200px;">Image</div> <p><b>JSON</b></p> <p>JSON stands for JavaScript Object Notation.
JSON is a standard lightweight data-interchange format which is quick and easy to parse and generate. JSON, like XML, is a text-based format that's easy to write and easy to understand for both humans
and computers, but unlike XML, JSON data structures occupy less bandwidth than their XML versions.</p> </div> </div> <div class="rightcolumn"> <div class="card"> <h2>About Me</h2> <div class="fakeimg" style="height:100px;">Image</div> <p>Anything......</p> </div> </div> </div> <div class="footer"> <h2>Footer</h2> </div> </body> </html>
Result
Test
Resize the browser window to see the effect.
Your Heading
Title description
JSON
JSON stands for JavaScript Object Notation. JSON is a standard lightweight data-interchange format which is quick and easy to parse and generate. JSON, like XML, is a text-based format that's easy to write and easy to understand for both humans and computers, but unlike XML, JSON data structures occupy less bandwidth than their XML versions.
About Me
Anything......
Combinators
A combinator is something that explains the relationship between the selectors. A CSS selector can contain more than one simple selector. Between the simple selectors, we can include a combinator. There are four different combinators in CSS:
- descendant selector (space)
- child selector (>)
- adjacent sibling selector (+)
- general sibling selector (~)
Descendant Selector
The descendant selector matches all elements that are descendants of a specified element.
The following example selects all < p> elements inside < div> elements:
Example:
div p {
background-color: yellow;
}
Child Selector
The child selector selects all elements that are the children of a specified element.
The following example selects all < p> elements that are children of a < div> element:
Example:
div > p {
background-color: yellow;
}
Adjacent Sibling Selector
The adjacent sibling selector selects all elements that are the adjacent siblings of a specified
element.
Sibling elements must have the same parent element, and "adjacent" means "immediately following".
The following example selects all < p> elements that are placed immediately after < div> elements:
Example:
div + p {
background-color: yellow;
}