Css Layouts
The Display Property
display: none:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiamsemper
diam at erat pulvinar, at pulvinar felis blandit.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.
display: inline:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiamsemper
diam at erat pulvinar, at pulvinar felis blandit.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.
display: block:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiamsemper
diam at erat pulvinar, at pulvinar felis blandit.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.
display: inline-block:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiamsemper
diam at erat pulvinar, at pulvinar felis blandit.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.display: block:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiamsemper
diam at erat pulvinar, at pulvinar felis blandit.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.
display: inline-block:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiamsemper
diam at erat pulvinar, at pulvinar felis blandit.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.
This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.This is a paragraph tag
Vestibulum volutpat tellus diam, consequat gravida liberorhoncus ut.Width and Max-Width
See the Result: Drag the browser window to smaller than 768px wide, to see the difference between the two divs!
The Position Property
position: static;
The Parent1 element has position: static, and will remain in the natural flow of the page. It will NOT act as anchor point for the absolutely positioned Child1 element:
position: relative;
The Parent2 element has position: relative, and will remain in the natural flow of the page. It will also act as anchor point for the absolutely positioned Child2 element:
position: absolute;
The Parent3 element has position: absolute, and will NOT remain in the natural flow of the page. It will position itself according to the closest positioned ancestor. It will also act as anchor point for the absolutely positioned Child3 element:
position: fixed;
The Parent4 element has position: fixed, and will NOT remain in the natural flow of the page. It will position itself according to the viewport. It will also act as anchor point for the absolutely positioned Child4 element:
Like the header
The Z-Index
If you set z-index (-1) of the Z-index 1 div, then it will be placed behind the 1 div.
Overflow
Overflow: visible
Overflow: hidden
Overflow: scroll
Overflow: auto
Overflow: X and Y
Float and Clear
Without Clearfix
This image is floated to the right. It is also taller than the element containing it, so it overflows outside of its container:
With New Modern Clearfix
Add the clearfix hack to the containing element, to fix this problem:
Horizontal & Vertical Align
Center with position and transform
In this example, we use positioning and the transform property to vertically and horizontally center the div element:
I am vertically and horizontally centered.
Combinators
Descendant Selector
The descendant selector matches all elements that are descendants of a specified element.
Paragraph 1 in the div.
Paragraph 2 in the div.
Paragraph 3 in the div.
Paragraph 4. Not in a div.
Paragraph 5. Not in a div.
Child Selector
The child selector (>) selects all elements that are the children of a specified element.
Paragraph 1 in the div.
Paragraph 2 in the div.
Paragraph 3 in the div (inside a section element).
Paragraph 4 in the div.
Paragraph 5. Not in a div.
Paragraph 6. Not in a div.
Adjacent Sibling Selector
The + selector is used to select an element that is directly after another specific element.
The following example selects the first p element that are placed immediately after div elements:
Paragraph 1 in the div.
Paragraph 2 in the div.
Paragraph 3. After a div.
Paragraph 4. After a div.
Paragraph 5 in the div.
Paragraph 6 in the div.
Paragraph 7. After a div.
Paragraph 8. After a div.
General Sibling Selector
The general sibling selector (~) selects all elements that are next siblings of a specified element.
Paragraph 1.
Paragraph 2.
Paragraph 3.
Some code.
Paragraph 4.
Pseudo Classes
Styling a link depending on state
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective.
Note: a:active MUST come after a:hover in the CSS definition in order to be effective.
Dropdowns
Hoverable Dropdown
Move the mouse over the text below to open the dropdown content.
- CSE
- EEE
- CIVIL
- SWE
Attribute Selector
CSS [attribute] Selector
The links with a target attribute gets a yellow background:
Google.com disney.com wikipedia.orgCSS [attribute="value"] Selector
The link with target="_blank" gets a yellow background:
Google.com disney.com wikipedia.orgCSS [attribute|="value"] Selector
Welcome
Hello world!
Are you learning CSS?
CSS [attribute^="value"] Selector
Welcome
Hello world!
Are you learning CSS?
CSS [attribute$="value"] Selector
This is some text in a paragraph.
CSS [attribute*="value"] Selector
This is some text in a paragraph.