CSS Flashcards

1
Q

CSS display Property

p. ex1 {display: none;}
p. ex2 {display: inline;}
p. ex3 {display: block;}
p. ex4 {display: inline-block;}

A

The display Property
display: none:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.
display: inline:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. HELLO WORLD! Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.
display: block:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit.
HELLO WORLD!

Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.
display: inline-block:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. HELLO WORLD! Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.

p {color: red;}

p. ex1 {display: none;}
p. ex2 {display: inline;}
p. ex3 {display: block;}
p. ex4 {display: inline-block;}

<h1>The display Property</h1>

<h2>display: none:</h2>

<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. <p>HELLO WORLD!</p> Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.
</div>

<h2>display: inline:</h2>

<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. <p>HELLO WORLD!</p> Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.
</div>

<h2>display: block:</h2>

<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. <p>HELLO WORLD!</p> Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.
</div>

<h2>display: inline-block:</h2>

<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. <p>HELLO WORLD!</p> Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.
</div>

nline Displays an element as an inline element (like <span>). Any height and width properties will have no effect
block Displays an element as a block element (like <p>). It starts on a new line, and takes up the whole width
contents Makes the container disappear, making the child elements children of the element the next level up in the DOM
flex Displays an element as a block-level flex container
grid Displays an element as a block-level grid container
inline-block Displays an element as an inline-level block container. The element itself is formatted as an inline element, but you can apply height and width values
inline-flex Displays an element as an inline-level flex container
inline-grid Displays an element as an inline-level grid container
inline-table The element is displayed as an inline-level table
list-item Let the element behave like a </p><li> element
run-in Displays an element as either block or inline, depending on context
table Let the element behave like a element
table-caption Let the element behave like a element
table-column-group Let the element behave like a element
table-header-group Let the element behave like a element
table-footer-group Let the element behave like a element
table-row-group Let the element behave like a element
table-cell Let the element behave like a element
table-column Let the element behave like a element
table-row Let the element behave like a element
none The element is completely removed
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit</li></span>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Before CSS Flexbox

A

Before the Flexbox Layout module, there were four layout modes:

Block, for sections in a webpage
Inline, for text
Table, for two-dimensional table data
Positioned, for explicit position of an element
The Flexible Box Layout Module, makes it easier to design flexible responsive layout structure without using float or positioning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Flexbox Elements

A

To start using the Flexbox model, you need to first define a flex container.

.flex-container {
display: flex;
background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  margin: 10px;
  padding: 20px;
  font-size: 30px;
}
<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

<p>A Flexible Layout must have a parent element with the <em>display</em> property set to <em>flex</em>.</p>

<p>Direct child elements(s) of the flexible container automatically becomes flexible items.</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Parent Element (Container)

A

The flex container becomes flexible by setting the display property to flex:
.flex-container {
display: flex;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The flex container properties are:

A
flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

flex container - The flex-direction Property

A

The flex-direction property defines in which direction the container wants to stack the flex items.

The column value stacks the flex items vertically (from top to bottom):

.flex-container {
display: flex;
flex-direction: column;
}

The column-reverse value stacks the flex items vertically (but from bottom to top):

.flex-container {
display: flex;
flex-direction: column-reverse;
}

The row value stacks the flex items horizontally (from left to right):

.flex-container {
display: flex;
flex-direction: row;
}

The row-reverse value stacks the flex items horizontally (but from right to left):

.flex-container {
display: flex;
flex-direction: row-reverse;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

flex container - The flex-wrap Property

A

The flex-wrap property specifies whether the flex items should wrap or not.

The examples below have 12 flex items, to better demonstrate the flex-wrap property.


The wrap value specifies that the flex items will wrap if necessary:

.flex-container {
  display: flex;
  flex-wrap: wrap;
}
--
The nowrap value specifies that the flex items will not wrap (this is default):
.flex-container {
  display: flex;
  flex-wrap: nowrap;
}
--
The wrap-reverse value specifies that the flexible items will wrap if necessary, in reverse order:

.flex-container {
display: flex;
flex-wrap: wrap-reverse;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

flex container - The flex-flow Property

A

The flex-flow property is a shorthand property for setting both the flex-direction and flex-wrap properties.

Example
.flex-container {
  display: flex;
  flex-flow: row wrap;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

flex container - The justify-content Property -Horizontal alignment

A

The justify-content property is used to align the flex items:
The center value aligns the flex items at the center of the container:

.flex-container {
  display: flex;
  justify-content: center;
}
---
The flex-start value aligns the flex items at the beginning of the container (this is default):
.flex-container {
  display: flex;
  justify-content: flex-start;
}
---
The flex-end value aligns the flex items at the end of the container:
.flex-container {
  display: flex;
  justify-content: flex-end;
}
---
The space-around value displays the flex items with space before, between, and after the lines:
.flex-container {
  display: flex;
  justify-content: space-around;
}
---
The space-between value displays the flex items with space between the lines:
.flex-container {
  display: flex;
  justify-content: space-between;
}
----
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

flex container - The align-items Property - vertical alignment

A

flex container - The align-items Property
The align-items property is used to align the flex items vertically.

The center value aligns the flex items in the middle of the container:

.flex-container {
  display: flex;
  height: 200px;
  align-items: center;
}
--
The flex-start value aligns the flex items at the top of the container:
.flex-container {
  display: flex;
  height: 200px;
  align-items: flex-start;
}
--
The flex-end value aligns the flex items at the bottom of the container:
.flex-container {
  display: flex;
  height: 200px;
  align-items: flex-end;
}

The stretch value stretches the flex items to fill the container (this is default):

.flex-container {
  display: flex;
  height: 200px;
  align-items: stretch;
}

The baseline value aligns the flex items such as their baselines aligns:

.flex-container {
  display: flex;
  height: 200px;
  align-items: baseline;
}
Note: the example uses different font-size to demonstrate that the items gets aligned by the text baseline:
.flex-container {
  display: flex;
  height: 200px;
  align-items: baseline;
  background-color: DodgerBlue;
}
.flex-container > div {
  background-color: #f1f1f1;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}

<h1>The align-items Property</h1>

<p>The "align-items: baseline;" aligns the flex items such as their baselines aligns:</p>

<div class="flex-container">
  <div><h1>1</h1></div>
  <div><h6>2</h6></div>
  <div><h3>3</h3></div>  
  <div><small>4</small></div>  
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

flex container - The align-content Property -vertical alignment when there are multiple lines

A

flex container - The align-content Property
The align-content property is used to align the flex lines.


In these examples we use a 600 pixels high container, with the flex-wrap property set to wrap, to better demonstrate the align-content property.

Example
The space-between value displays the flex lines with equal space between them:

.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: space-between;
}
--
The space-around value displays the flex lines with space before, between, and after them:
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: space-around;
}
--
The stretch value stretches the flex lines to take up the remaining space (this is default):
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: stretch;
}
--
The center value displays display the flex lines in the middle of the container:
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: center;
}
--

The flex-start value displays the flex lines at the start of the container:

.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: flex-start;
}
--
The flex-end value displays the flex lines at the end of the container: 
.flex-container {
  display: flex;
  height: 600px;
  flex-wrap: wrap;
  align-content: flex-end;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

flex container- Perfect Centering

A

SOLUTION: Set both the justify-content and align-items properties to center, and the flex item will be perfectly centered:

Example
.flex-container {
  display: flex;
  height: 300px;
  justify-content: center;
  align-items: center;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Flex container -Child Elements (Items) or Flex items

A

The direct child elements of a flex container automatically becomes flexible (flex) items.

.flex-container {
display: flex;
background-color: #f1f1f1;
}

.flex-container > div {
  background-color: DodgerBlue;
  color: white;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}

<h1>Flexible Items</h1>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div> 
  <div>4</div>
</div>

<p>All direct children of a flexible container becomes flexible items.</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

flex item properties - The order Property

A

The order property specifies the order of the flex items.
The first flex item in the code does not have to appear as the first item in the layout.

The order value must be a number, default value is 0.
The order property can change the order of the flex items:

<div class="flex-container">
  <div style="">1</div>
  <div style="">2</div>
  <div style="">3</div>
  <div style="">4</div>
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

flex item properties -The flex-grow Property

A

The flex-grow property specifies how much a flex item will grow relative to the rest of the flex items.

The value must be a number, default value is 0.

Make the third flex item grow eight times faster than the other flex items:

<div class="flex-container">
  <div style="">1</div>
  <div style="">2</div>
  <div style="">3</div>
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

flex item properties -The flex-shrink Property

A

The flex-shrink property specifies how much a flex item will shrink relative to the rest of the flex items.

The value must be a number, default value is 1.

Do not let the third flex item shrink as much as the other flex items:

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div style="">3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
  <div>7</div>
  <div>8</div>
  <div>9</div>
  <div>10</div>
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

flex item properties - The flex-basis Property

A

The flex-basis property specifies the initial length of a flex item.
Set the initial length of the third flex item to 200 pixels:

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div style="">3</div>
  <div>4</div>
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

flex item properties -The flex Property

A

The flex property is a shorthand property for the flex-grow, flex-shrink, and flex-basis properties.

Example
Make the third flex item not growable (0), not shrinkable (0), and with an initial length of 200 pixels:

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div style="">3</div>
  <div>4</div>
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

flex item properties -The align-self Property

A

The align-self property specifies the alignment for the selected item inside the flexible container.

The align-self property overrides the default alignment set by the container’s align-items property.

In these examples we use a 200 pixels high container, to better demonstrate the align-self property:

Example
Align the third flex item in the middle of the container:

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div style="">3</div>
  <div>4</div>
</div>
---
.flex-container {
  display: flex;
  height: 200px;
  background-color: #f1f1f1;
}
.flex-container > div {
  background-color: DodgerBlue;
  color: white;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}

<h1>The align-self Property</h1>

<p>The "align-self: center;" aligns the selected flex item in the middle of the container:</p>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div style="">3</div>
  <div>4</div>
</div>

<p>The align-self property overrides the align-items property of the container.</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

styling div element within a class .flex-container>div

A
.flex-container {
  display: flex;
  align-items: stretch;
  background-color: #f1f1f1;
}
.flex-container>div {
  background-color: DodgerBlue;
  color: white;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}

<h1>The order Property</h1>

<p>Use the order property to sort the flex items as you like:</p>

<div class="flex-container">
  <div style="">1</div>
  <div style="">2</div>
  <div style="">3</div> 
  <div style="">4</div>
</div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Flex container - Flex items - align self property

A

Example
Align the second flex item at the top of the container, and the third flex item at the bottom of the container:

<div class="flex-container">
  <div>1</div>
  <div style="">2</div>
  <div style="">3</div>
  <div>4</div>
</div>
----
.flex-container {
  display: flex;
  height: 200px;
  background-color: #f1f1f1;
}
.flex-container > div {
  background-color: DodgerBlue;
  color: white;
  width: 100px;
  margin: 10px;
  text-align: center;
  line-height: 75px;
  font-size: 30px;
}

<h1>The align-self Property</h1>

<p>The "align-self: flex-start;" aligns the selected flex item at the top of the container.</p>

<p>The "align-self: flex-end;" aligns the selected flex item at the bottom of the container.</p>

<div class="flex-container">
  <div>1</div>
  <div style="">2</div>
  <div style="">3</div>
  <div>4</div>
</div>

<p>The align-self property overrides the align-items property of the container.</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

CSS Flexbox Properties

A

The following table lists the CSS properties used with flexbox:

Property Description
display Specifies the type of box used for an HTML element
flex-direction Specifies the direction of the flexible items inside a flex container
justify-content Horizontally aligns the flex items when the items do not use all available space on the main-axis
align-items Vertically aligns the flex items when the items do not use all available space on the cross-axis
flex-wrap Specifies whether the flex items should wrap or not, if there is not enough room for them on one flex line
align-content Modifies the behavior of the flex-wrap property. It is similar to align-items, but instead of aligning flex items, it aligns flex lines
flex-flow A shorthand property for flex-direction and flex-wrap
order Specifies the order of a flexible item relative to the rest of the flex items inside the same container
align-self Used on flex items. Overrides the container’s align-items property
flex A shorthand property for the flex-grow, flex-shrink, and the flex-basis properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

CSS2 Introduced Media Types

A

The @media rule, introduced in CSS2, made it possible to define different style rules for different media types.

Examples: You could have one set of style rules for computer screens, one for printers, one for handheld devices, one for television-type devices, and so on.

Unfortunately these media types never got a lot of support by devices, other than the print media type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

CSS3 Introduced Media Queries

A

Media queries in CSS3 extended the CSS2 media types idea: Instead of looking for a type of device, they look at the capability of the device.

Media queries can be used to check many things, such as:

width and height of the viewport
width and height of the device
orientation (is the tablet/phone in landscape or portrait mode?)
resolution
Using media queries are a popular technique for delivering a tailored style sheet to desktops, laptops, tablets, and mobile phones (such as iPhone and Android phones).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Media Query Syntax

A

A media query consists of a media type and can contain one or more expressions, which resolve to either true or false.

@media not|only mediatype and (expressions) {
CSS-Code;
}
The result of the query is true if the specified media type matches the type of device the document is being displayed on and all expressions in the media query are true. When a media query is true, the corresponding style sheet or style rules are applied, following the normal cascading rules.

Unless you use the not or only operators, the media type is optional and the all type will be implied.

You can also have different stylesheets for different media:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

CSS3 Media Types

A

CSS3 Media Types
Value Description
all Used for all media type devices
print Used for printers
screen Used for computer screens, tablets, smart-phones etc.
speech Used for screenreaders that “reads” the page out loud

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Media Queries Simple Examples

A

One way to use media queries is to have an alternate CSS section right inside your style sheet.

The following example changes the background-color to lightgreen if the viewport is 480 pixels wide or wider (if the viewport is less than 480 pixels, the background-color will be pink):

Example
@media screen and (min-width: 480px) {
  body {
    background-color: lightgreen;
  }
}

body {
background-color: pink;
}

@media screen and (min-width: 480px) {
  body {
    background-color: lightgreen;
  }
}

<h1>Resize the browser window to see the effect!</h1>

<p>The media query will only apply if the media type is screen and the viewport is 480px wide or wider.</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Media Query example 2

A

main {margin-left: 4px;}

The following example shows a menu that will float to the left of the page if the viewport is 480 pixels wide or wider (if the viewport is less than 480 pixels, the menu will be on top of the content):

Example
@media screen and (min-width: 480px) {
  #leftsidebar {width: 200px; float: left;}
  #main {margin-left: 216px;}
}
--

.wrapper {overflow: auto;}

#leftsidebar {
  float: none;
  width: auto;
}

margin: 0;
padding: 0;
}

.menuitem {
  background: #CDF0F6;
  border: 1px solid #d4d4d4;
  border-radius: 4px;
  list-style-type: none;
  margin: 4px;
  padding: 2px;
}
@media screen and (min-width: 480px) {
  #leftsidebar {width: 200px; float: left;}
  #main {margin-left: 216px;}
}

<div>
<div>
<ul>
<li>Menu-item 1</li>
<li>Menu-item 2</li>
<li>Menu-item 3</li>
<li>Menu-item 4</li>
<li>Menu-item 5</li>
</ul>
</div>

<div>
<h1>Resize the browser window to see the effect!</h1>
<p>This example shows a menu that will float to the left of the page if the viewport is 480 pixels wide or wider. If the viewport is less than 480 pixels, the menu will be on top of the content.</p>
</div>
</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Responsive Web Design

A

Responsive web design makes your web page look good on all devices.

Responsive web design uses only HTML and CSS.

Responsive web design is not a program or a JavaScript.

Designing For The Best Experience For All Users
Web pages can be viewed using many different devices: desktops, tablets, and phones. Your web page should look good, and be easy to use, regardless of the device.

Web pages should not leave out information to fit smaller devices, but rather adapt its content to fit any device:

It is called responsive web design when you use CSS and HTML to resize, hide, shrink, enlarge, or move the content to make it look good on any screen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Media Query example - setting background color based on size

A
/* Set the background color of body to tan */
body {
  background-color: tan;
}
/* On screens that are 992px or less, set the background color to blue */
@media screen and (max-width: 992px) {
  body {
    background-color: blue;
  }
}
/* On screens that are 600px or less, set the background color to olive */
@media screen and (max-width: 600px) {
  body {
    background-color: olive;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Media Queries For Menus

A
/* The navbar container */
.topnav {
  overflow: hidden;
  background-color: #333;
}
/* Navbar links */
.topnav a {
  float: left;
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
/* On screens that are 600px wide or less, make the menu links stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .topnav a {
    float: none;
    width: 100%;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Media Queries For Columns

A
A common use of media queries, is to create a flexible layout. In this example, we create a layout that varies between four, two and full-width columns, depending on different screen sizes:
/* Create four equal columns that floats next to each other */
.column {
  float: left;
  width: 25%;
}
/* On screens that are 992px wide or less, go from four columns to two columns */
@media screen and (max-width: 992px) {
  .column {
    width: 50%;
  }
}
/* On screens that are 600px wide or less, make the columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Media Query - setting flex direction

A
/* Container for flexboxes */
.row {
  display: flex;
  flex-wrap: wrap;
}
/* Create four equal columns */
.column {
  flex: 25%;
  padding: 20px;
}
/* On screens that are 992px wide or less, go from four columns to two columns */
@media screen and (max-width: 992px) {
  .column {
    flex: 50%;
  }
}
/* On screens that are 600px wide or less, make the columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .row {
    flex-direction: column;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Hide Elements With Media Queries

A

Another common use of media queries, is to hide elements on different screen sizes:

I will be hidden on small screens.
Example
/* If the screen size is 600px wide or less, hide the element */
@media screen and (max-width: 600px) {
  div.example {
    display: none;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Change Font Size With Media Queries

A
/* If screen size is more than 600px wide, set the font-size of <div> to 80px */
@media screen and (min-width: 600px) {
  div.example {
    font-size: 80px;
  }
}
/* If screen size is 600px wide, or less, set the font-size of <div> to 30px */
@media screen and (max-width: 600px) {
  div.example {
    font-size: 30px;
  }
}</div></div>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

For setting the mat-table in the position on a page with a div element

A
.content-main {
  margin: 21px 107px 23px;
}
--
<div class="content-main">

</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

CSS Margin

A

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).

Margin - Individual Sides
CSS has properties for specifying the margin for each side of an element:

margin-top
margin-right
margin-bottom
margin-left
All the margin properties can have the following values:

auto - the browser calculates the margin
length - specifies a margin in px, pt, cm, etc.
% - specifies a margin in % of the width of the containing element
inherit - specifies that the margin should be inherited from the parent element

Set different margins for all four sides of a <p> element:

p {
  margin-top: 100px;
  margin-bottom: 100px;
  margin-right: 150px;
  margin-left: 80px;
}
</p>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

CSS Box model

A

Element - Padding inside border - border - Margin outside border

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Margin - Shorthand Property

A

To shorten the code, it is possible to specify all the margin properties in one property.

The margin property is a shorthand property for the following individual margin properties:

margin-top
margin-right
margin-bottom
margin-left
So, here is how it works:

If the margin property has four values:

margin: 25px 50px 75px 100px;
top margin is 25px
right margin is 50px
bottom margin is 75px
left margin is 100px
Example
Use the margin shorthand property with four values:

p {
margin: 25px 50px 75px 100px;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

If the margin property has three values:

A

If the margin property has three values:

margin: 25px 50px 75px;
top margin is 25px
right and left margins are 50px
bottom margin is 75px
Example
Use the margin shorthand property with three values: 

p {
margin: 25px 50px 75px;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

If the margin property has two values:

A

If the margin property has two values:

margin: 25px 50px;
top and bottom margins are 25px
right and left margins are 50px
Example
Use the margin shorthand property with two values: 

p {
margin: 25px 50px;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

If the margin property has one value:

A

margin: 25px;
all four margins are 25px
Example
Use the margin shorthand property with one value:

p {
margin: 25px;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Margin auto value- for horizantal alignment

A

You can set the margin property to auto to horizontally center the element within its container.

The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.

Example
Use margin: auto:

div {
  width: 300px;
  margin: auto;
  border: 1px solid red;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Margin - Inherit value

A

This example lets the left margin of the <p class="ex1"> element be inherited from the parent element (</p><div>):

Example
Use of the inherit value:

div {
border: 1px solid red;
margin-left: 100px;
}

p.ex1 {
margin-left: inherit;
}

div {
border: 1px solid red;
margin-left: 100px;
}

p.ex1 {
margin-left: inherit;
}

<h2>Use of the inherit value</h2>

<p>Let the left margin be inherited from the parent element:</p>

<div>
<p>This paragraph has an inherited left margin (from the div element).</p>
</div>

</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Margin Collapse only on top and bottom and not on sides

A

Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins.

This does not happen on left and right margins! Only top and bottom margins!

Look at the following example:

Example
Demonstration of margin collapse:

h1 {
margin: 0 0 50px 0;
}

h2 {
margin: 20px 0 0 0;
}
In the example above, the <h1> element has a bottom margin of 50px and the <h2> element has a top margin set to 20px.

Common sense would seem to suggest that the vertical margin between the <h1> and the <h2> would be a total of 70px (50px + 20px). But due to margin collapse, the actual margin ends up being 50px.

h1 {
margin: 0 0 50px 0;
}

h2 {
margin: 20px 0 0 0;
}

</h2></h1></h2></h1><p>In this example the h1 element has a bottom margin of 50px and the h2 element has a top margin of 20px. Then, the vertical margin between h1 and h2 should have been 70px (50px + 20px). However, due to margin collapse, the actual margin ends up being 50px.</p>

<h1>Heading 1</h1>

<h2>Heading 2</h2>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

CSS 2D Transforms

A

CSS transforms allow you to move, rotate, scale, and skew elements.

Mouse over the element below to see a 2D transformation:
In this chapter you will learn about the following CSS property:

transform

47
Q

CSS 2D Transforms -Browser Specific Prefixes

A

Some older browsers (IE 9) need specific prefixes (-ms-) to understand the 2D transform properties:
div {
-ms-transform: rotate(20deg); /* IE 9 /
transform: rotate(20deg); /
Standard syntax */
}

48
Q

CSS 2D Transforms Methods

A

With the CSS transform property you can use the following 2D transformation methods:

translate()
rotate()
scaleX()
scaleY()
scale()
skewX()
skewY()
skew()
matrix()
49
Q

CSS 2D Transforms -The translate() Method

A

The translate() method moves an element from its current position (according to the parameters given for the X-axis and the Y-axis).

The following example moves the <div> element 50 pixels to the right, and 100 pixels down from its current position:

Example
div {
transform: translate(50px, 100px);
}</div>

50
Q

CSS 2D Transforms -The rotate() Method

A

The rotate() method rotates an element clockwise or counter-clockwise according to a given degree.

The following example rotates the <div> element clockwise with 20 degrees:

Example
div {
  transform: rotate(20deg);
}
Using negative values will rotate the element counter-clockwise.

The following example rotates the <div> element counter-clockwise with 20 degrees:

Example
div {
transform: rotate(-20deg);
}</div></div>

51
Q

CSS 2D Transforms -The scale() Method

A

The scale() method increases or decreases the size of an element (according to the parameters given for the width and height).

The following example increases the <div> element to be two times of its original width, and three times of its original height:

Example
div {
  transform: scale(2, 3);
}
The following example decreases the <div> element to be half of its original width and height: 

Example
div {
transform: scale(0.5, 0.5);
}</div></div>

52
Q

CSS 2D Transforms-The scaleX() Method

A
The scaleX() Method
The scaleX() method increases or decreases the width of an element.

The following example increases the <div> element to be two times of its original width:

Example
div {
  transform: scaleX(2);
}
The following example decreases the <div> element to be half of its original width: 

Example
div {
transform: scaleX(0.5);
}</div></div>

53
Q

CSS 2D Transforms -The scaleY() Method

A

The scaleY() method increases or decreases the height of an element.

The following example increases the <div> element to be three times of its original height:

Example
div {
  transform: scaleY(3);
}
The following example decreases the <div> element to be half of its original height: 

Example
div {
transform: scaleY(0.5);
}</div></div>

54
Q

CSS 2D Transforms - skew method

A
The skewX() Method
The skewX() method skews an element along the X-axis by the given angle.

The following example skews the <div> element 20 degrees along the X-axis:

Example
div {
  transform: skewX(20deg);
}
The skewY() Method
The skewY() method skews an element along the Y-axis by the given angle.

The following example skews the <div> element 20 degrees along the Y-axis:

Example
div {
  transform: skewY(20deg);
}
The skew() Method
The skew() method skews an element along the X and Y-axis by the given angles.

The following example skews the <div> element 20 degrees along the X-axis, and 10 degrees along the Y-axis:

Example
div {
  transform: skew(20deg, 10deg);
}
If the second parameter is not specified, it has a zero value. So, the following example skews the <div> element 20 degrees along the X-axis:

Example
div {
transform: skew(20deg);
}</div></div></div></div>

55
Q

CSS 2D Transforms -The matrix() Method

A

The matrix() method combines all the 2D transform methods into one.

The matrix() method take six parameters, containing mathematic functions, which allows you to rotate, scale, move (translate), and skew elements.

The parameters are as follow: matrix(scaleX(),skewY(),skewX(),scaleY(),translateX(),translateY())

Example
div {
transform: matrix(1, -0.3, 0, 1, 0, 0);
}

56
Q

CSS 2D Transform Properties

A

CSS Transform Properties
The following table lists all the 2D transform properties:

Property Description
transform Applies a 2D or 3D transformation to an element
transform-origin Allows you to change the position on transformed elements

57
Q

CSS 2D Transform Methods

A

Function Description
matrix(n,n,n,n,n,n) Defines a 2D transformation, using a matrix of six values
translate(x,y) Defines a 2D translation, moving the element along the X- and the Y-axis
translateX(n) Defines a 2D translation, moving the element along the X-axis
translateY(n) Defines a 2D translation, moving the element along the Y-axis
scale(x,y) Defines a 2D scale transformation, changing the elements width and height
scaleX(n) Defines a 2D scale transformation, changing the element’s width
scaleY(n) Defines a 2D scale transformation, changing the element’s height
rotate(angle) Defines a 2D rotation, the angle is specified in the parameter
skew(x-angle,y-angle) Defines a 2D skew transformation along the X- and the Y-axis
skewX(angle) Defines a 2D skew transformation along the X-axis
skewY(angle) Defines a 2D skew transformation along the Y-axis

58
Q

CSS Rounded Corners

A

With the CSS border-radius property, you can give any element “rounded corners”.

The CSS border-radius property defines the radius of an element’s corners.

Tip: This property allows you to add rounded corners to elements!

#rcorners1 {
  border-radius: 25px;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px;  
}
#rcorners2 {
  border-radius: 25px;
  border: 2px solid #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px;  
}
#rcorners3 {
  border-radius: 25px;
  background: url(paper.gif);
  background-position: left top;
  background-repeat: repeat;
  padding: 20px; 
  width: 200px;
  height: 150px;  
}

<h1>The border-radius Property</h1>

<p>Rounded corners for an element with a specified background color:</p>

<p>Rounded corners!</p>

<p>Rounded corners for an element with a border:</p>

<p>Rounded corners!</p>

<p>Rounded corners for an element with a background image:</p>

<p>Rounded corners!</p>

Tip: The border-radius property is actually a shorthand property for the border-top-left-radius, border-top-right-radius, border-bottom-right-radius and border-bottom-left-radius properties.

59
Q

CSS border-radius - Specify Each Corner

A
#rcorners1 {
  border-radius: 15px 50px 30px 5px;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px; 
}
#rcorners2 {
  border-radius: 15px 50px 30px;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px; 
}
#rcorners3 {
  border-radius: 15px 50px;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px; 
} 
#rcorners4 {
  border-radius: 15px;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px; 
} 

<h1>The border-radius Property</h1>

<p>Four values - border-radius: 15px 50px 30px 5px:</p>

<p></p>

<p>Three values - border-radius: 15px 50px 30px:</p>

<p></p>

<p>Two values - border-radius: 15px 50px:</p>

<p></p>

<p>One value - border-radius: 15px:</p>

<p></p>

60
Q

CSS Rounded border - Elliptical

A
#rcorners1 {
  border-radius: 50px / 15px;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px; 
}
#rcorners2 {
  border-radius: 15px / 50px;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px; 
}
#rcorners3 {
  border-radius: 50%;
  background: #73AD21;
  padding: 20px; 
  width: 200px;
  height: 150px;
} 

<h1>The border-radius Property</h1>

<p>Elliptical border - border-radius: 50px / 15px:</p>

<p></p>

<p>Elliptical border - border-radius: 15px / 50px:</p>

<p></p>

<p>Ellipse border - border-radius: 50%:</p>

<p></p>

61
Q

CSS Rounded Corners Properties

A

Property Description
border-radius A shorthand property for setting all the four border---radius properties
border-top-left-radius Defines the shape of the border of the top-left corner
border-top-right-radius Defines the shape of the border of the top-right corner
border-bottom-right-radius Defines the shape of the border of the bottom-right corner
border-bottom-left-radius Defines the shape of the border of the bottom-left corner

62
Q

CSS :hover Selector

A

Select and style a link when you mouse over it:

a:hover {
background-color: yellow;
}

The :hover selector is used to select elements when you mouse over them.

Tip: The :hover selector can be used on all elements, not only on links.

Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.

Note: :hover MUST come after :link and :visited (if they are present) in the CSS definition, in order to be effective!

63
Q

CSS Transitions

A

CSS transitions allows you to change property values smoothly, over a given duration.

Mouse over the element below to see a CSS transition effect:
n this chapter you will learn about the following properties:

transition
transition-delay
transition-duration
transition-property
transition-timing-function
64
Q

CSS Transitions- How to Use CSS Transitions?

A

To create a transition effect, you must specify two things:

the CSS property you want to add an effect to
the duration of the effect
Note: If the duration part is not specified, the transition will have no effect, because the default value is 0.

The following example shows a 100px * 100px red <div> element. The <div> element has also specified a transition effect for the width property, with a duration of 2 seconds:

Example
div {
  width: 100px;
  height: 100px;
  background: red;
  transition: width 2s;
}

The transition effect will start when the specified CSS property (width) changes value.

Now, let us specify a new value for the width property when a user mouses over the <div> element:

Example
div:hover {
  width: 300px;
}
Notice that when the cursor mouses out of the element, it will gradually change back to its original style.

div {
  width: 100px;
  height: 100px;
  background: red;
  transition: width 2s;
}

div:hover {
width: 300px;
}

<h1>The transition Property</h1>

<p>Hover over the div element below, to see the transition effect:</p>

<div></div>

<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>

</div></div></div>

65
Q

CSS Transitions-Change Several Property Values

A

The following example adds a transition effect for both the width and height property, with a duration of 2 seconds for the width and 4 seconds for the height:

div {
transition: width 2s, height 4s;
}

div {
  width: 100px;
  height: 100px;
  background: red;
  transition: width 2s, height 4s;
}

div:hover {
width: 300px;
height: 300px;
}

<h1>The transition Property</h1>

<p>Hover over the div element below, to see the transition effect:</p>

<div></div>

<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>

66
Q

CSS Transitions -Specify the Speed Curve of the Transition

A

The transition-timing-function property specifies the speed curve of the transition effect.

The transition-timing-function property can have the following values:

ease - specifies a transition effect with a slow start, then fast, then end slowly (this is default)
linear - specifies a transition effect with the same speed from start to end
ease-in - specifies a transition effect with a slow start
ease-out - specifies a transition effect with a slow end
ease-in-out - specifies a transition effect with a slow start and end
cubic-bezier(n,n,n,n) - lets you define your own values in a cubic-bezier function
The following example shows the some of the different speed curves that can be used:

Example
#div1 {transition-timing-function: linear;}
#div2 {transition-timing-function: ease;}
#div3 {transition-timing-function: ease-in;}
#div4 {transition-timing-function: ease-out;}
#div5 {transition-timing-function: ease-in-out;}
div {
  width: 100px;
  height: 100px;
  background: red;
  transition: width 2s;
}
#div1 {transition-timing-function: linear;}
#div2 {transition-timing-function: ease;}
#div3 {transition-timing-function: ease-in;}
#div4 {transition-timing-function: ease-out;}
#div5 {transition-timing-function: ease-in-out;}

div:hover {
width: 300px;
}

<h1>The transition-timing-function Property</h1>

<p>Hover over the div elements below, to see the different speed curves:</p>

<div>linear</div><br>
<div>ease</div><br>
<div>ease-in</div><br>
<div>ease-out</div><br>
<div>ease-in-out</div><br>

<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>

67
Q

CSS Transitions - Delay the Transition Effect

A

The transition-delay property specifies a delay (in seconds) for the transition effect.

The following example has a 1 second delay before starting:

Example
div {
transition-delay: 1s;
}

div {
  width: 100px;
  height: 100px;
  background: red;
  transition: width 3s;
  transition-delay: 1s;
}

div:hover {
width: 300px;
}

<h1>The transition-delay Property</h1>

<p>Hover over the div element below, to see the transition effect:</p>

<div></div>

<p><b>Note:</b> The transition effect has a 1 second delay before starting.</p>

<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>

68
Q

CSS Transitions

A

Transition + Transformation
The following example adds a transition effect to the transformation:

Example
div {
transition: width 2s, height 2s, transform 2s;
}

div {
  width: 100px;
  height: 100px;
  background: red;
  transition: width 2s, height 2s, transform 2s;
}

div:hover {
width: 300px;
height: 300px;
transform: rotate(180deg);
}

<h1>Transition + Transform</h1>

<p>Hover over the div element below:</p>

<div></div>

<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>

69
Q

CSS Transitions-More Transition Examples

A

The CSS transition properties can be specified one by one, like this:

Example
div {
  transition-property: width;
  transition-duration: 2s;
  transition-timing-function: linear;
  transition-delay: 1s;
}
or by using the shorthand property transition:

Example
div {
transition: width 2s linear 1s;
}

70
Q

CSS Transition Properties

A

The following table lists all the CSS transition properties:

Property Description
transition A shorthand property for setting the four transition properties into a single property
transition-delay Specifies a delay (in seconds) for the transition effect
transition-duration Specifies how many seconds or milliseconds a transition effect takes to complete
transition-property Specifies the name of the CSS property the transition effect is for
transition-timing-function Specifies the speed curve of the transition effect

71
Q

CSS Layout - Overflow

A

The CSS overflow property controls what happens to content that is too big to fit into an area.

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:

visible - 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
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).

72
Q

CSS Overflow example

A
#overflowTest {
  background: #4CAF50;
  color: white;
  padding: 15px;
  width: 50%;
  height: 100px;
  overflow: scroll;
  border: 1px solid #ccc;
}

<div>This text is really long and the height of its container is only 100 pixels. Therefore, a scrollbar is added to help the reader to scroll the content. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.</div>

73
Q

overflow: visible

A

By default, the overflow is visible, meaning that it is not clipped and it renders outside the 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.

div {
  width: 200px;
  height: 50px;
  background-color: #eee;
  overflow: visible;
}
74
Q

overflow: hidden

A

With the hidden value, the overflow is clipped, and the rest of the content is hidden:

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.
Example
div {
  overflow: hidden;
}
75
Q

overflow: scroll

A

overflow: scroll
Setting the value to scroll, the overflow is clipped and a scrollbar is added to scroll inside the box. Note that this will add a scrollbar both horizontally and vertically (even if you do not need it):

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.
Example
div {
  overflow: scroll;
}
76
Q

overflow: auto

A

The auto value is similar to scroll, but it adds scrollbars only when necessary:

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.
Example
div {
  overflow: auto;
}
77
Q

overflow-x and overflow-y

A

The overflow-x and overflow-y properties specifies whether to change the overflow of content just horizontally or vertically (or both):

overflow-x specifies what to do with the left/right edges of the content.
overflow-y specifies what to do with the top/bottom edges of the content.

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.
Example
div {
overflow-x: hidden; /* Hide horizontal scrollbar /
overflow-y: scroll; /
Add vertical scrollbar */
}

78
Q

All CSS Overflow Properties

A

Property Description
overflow Specifies what happens if content overflows an element’s box
overflow-x Specifies what to do with the left/right edges of the content if it overflows the element’s content area
overflow-y Specifies what to do with the top/bottom edges of the content if it overflows the element’s content area

79
Q

CSS Text Color

A

The color property is used to set the color of the text. The color is specified by:

a color name - like “red”
a HEX value - like “#ff0000”
an RGB value - like “rgb(255,0,0)”
Look at CSS Color Values for a complete list of possible color values.

The default text color for a page is defined in the body selector.

body {
color: blue;
}

h1 {
color: green;
}
Note: For W3C compliant CSS: If you define the color property, you must also define the background-color.

80
Q

Text Alignment

A

The text-align property is used to set the horizontal alignment of a text.

A text can be left or right aligned, centered, or justified.

The following example shows center aligned, and left and right aligned text (left alignment is default if text direction is left-to-right, and right alignment is default if text direction is right-to-left):

h1 {
text-align: center;
}

h2 {
text-align: left;
}

h3 {
text-align: right;
}

When the text-align property is set to “justify”, each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers):

div {
text-align: justify;
}

81
Q

Text Decoration

A

The text-decoration property is used to set or remove decorations from text.

The value text-decoration: none; is often used to remove underlines from links:

a {
text-decoration: none;
}

The other text-decoration values are used to decorate text:
h1 {
text-decoration: overline;
}

h2 {
text-decoration: line-through;
}

h3 {
text-decoration: underline;
}
Note: It is not recommended to underline text that is not a link, as this often confuses the reader.

82
Q

Text Transformation

A

The text-transform property is used to specify uppercase and lowercase letters in a text.

It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word:

The text-transform property is used to specify uppercase and lowercase letters in a text.

It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word:

p.uppercase {
text-transform: uppercase;
}

p.lowercase {
text-transform: lowercase;
}

p.capitalize {
text-transform: capitalize;
}

<p>This is some text.</p>

<p>This is some text.</p>

<p>This is some text.</p>

83
Q

p.capitalize {
text-transform: capitalize;
}

A

set style for p elements that have class as capitalize

<p>This is some text.</p>

84
Q

Text Indentation

A

The text-indent property is used to specify the indentation of the first line of a text:

p {
text-indent: 50px;
}
it is like leaving a space for the first line of the paragraph

85
Q

Letter Spacing

A

The letter-spacing property is used to specify the space between the characters in a text.

The following example demonstrates how to increase or decrease the space between characters:

h1 {
letter-spacing: 3px;
}

h2 {
letter-spacing: -3px;
}

86
Q

Line Height

A

The line-height property is used to specify the space between lines:

p.small {
line-height: 0.8;
}

p.big {
line-height: 1.8;
}

87
Q

Text Direction

A

The direction and unicode-bidi properties can be used to change the text direction of an element:

p {
direction: rtl;
unicode-bidi: bidi-override;
}

p.ex1 {
direction: rtl;
unicode-bidi: bidi-override;
}

<p>This is the default text direction.</p>

<p>This is right-to-left text direction.</p>

OUTPUT:
This is the default text direction.

rtl: makes it right to left but i was not able to paste it from w3schools, it is transforming it into normal text

bidi-override - changes this to siht

88
Q

Word Spacing

A

The word-spacing property is used to specify the space between the words in a text.

The following example demonstrates how to increase or decrease the space between words:

h1 {
word-spacing: 10px;
}

h2 {
word-spacing: -5px;
}

89
Q

Text Shadow

A

The text-shadow property adds shadow to text.

The following example specifies the position of the horizontal shadow (3px), the position of the vertical shadow (2px) and the color of the shadow (red):

h1 {
text-shadow: 3px 2px red;
}

Note: Internet Explorer 9 and earlier do not support the text-shadow property.

90
Q

Disable text wrapping inside an element

A

p {
white-space: nowrap;
}

it puts everything in one line with scroll bar

91
Q

Vertical alignment of an image

A

img.top {
vertical-align: text-top;
}

img.bottom {
vertical-align: text-bottom;
}

<p>An <img></img> image with a default alignment.</p>

<br></br>

<p>An <img></img> image with a text-top alignment.</p>

<br></br>

<p>An <img></img> image with a text-bottom alignment.</p>

92
Q

All CSS Text Properties

A

Property Description
color Sets the color of text
direction Specifies the text direction/writing direction
letter-spacing Increases or decreases the space between characters in a text
line-height Sets the line height
text-align Specifies the horizontal alignment of text
text-decoration Specifies the decoration added to text
text-indent Specifies the indentation of the first line in a text-block
text-shadow Specifies the shadow effect added to text
text-transform Controls the capitalization of text
text-overflow Specifies how overflowed content that is not displayed should be signaled to the user
unicode-bidi Used together with the direction property to set or return whether the text should be overridden to support multiple languages in the same document
vertical-align Sets the vertical alignment of an element
white-space Specifies how white-space inside an element is handled
word-spacing Increases or decreases the space between words in a text

93
Q

opacity

A

The opacity property sets the opacity level for an element.

The opacity-level describes the transparency-level, where 1 is not transparent at all, 0.5 is 50% see-through, and 0 is completely transparent.

Note: When using the opacity property to add transparency to the background of an element, all of its child elements become transparent as well. This can make the text inside a fully transparent element hard to read. If you do not want to apply opacity to child elements, use RGBA color values instead (See “More Examples” below).

CSS Syntax
opacity: number|initial|inherit;

Property Values
Value Description Play it
number Specifies the opacity. From 0.0 (fully transparent) to 1.0 (fully opaque)
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

div {
opacity: 0.5;
}

The opacity property adds transparency to the background of an element, and to all of its child elements as well. This makes the text inside a transparent element hard to read:

div.first {
opacity: 0.1;
}

div.second {
opacity: 0.3;
}

div.third {
opacity: 0.6;
}

94
Q

CSS Selectors

A

https://www.w3schools.com/cssref/css_selectors.asp

In CSS, selectors are patterns used to select the element(s) you want to style.

Use our CSS Selector Tester to demonstrate the different selectors.

Selector Example Example description
.class .intro Selects all elements with class=”intro”
.class1.class2 .name1.name2 Selects all elements with both name1 and name2 set within its class attribute
.class1 .class2 .name1 .name2 Selects all elements with name2 that is a descendant of an element with name1
#id #firstname Selects the element with id=”firstname”
* * Selects all elements
element p Selects all <p> elements
element.class p.intro Selects all </p><p> elements with class=”intro”
element,element div, p Selects all </p><div> elements and all <p> elements
element element div p Selects all </p><p> elements inside </p><div> elements
element>element div > p Selects all <p> elements where the parent is a </p><div> element
element+element div + p Selects all <p> elements that are placed immediately after </p><div> elements
element1~element2 p ~ ul Selects every <ul> element that are preceded by a <p> element
[attribute] [target] Selects all elements with a target attribute
[attribute=value] [target=_blank] Selects all elements with target=”_blank”
[attribute~=value] [title~=flower] Selects all elements with a title attribute containing the word “flower”
[attribute|=value] [lang|=en] Selects all elements with a lang attribute value starting with “en”
[attribute^=value] a[href^=”https”] Selects every <a> element whose href attribute value begins with “https”
[attribute$=value] a[href$=”.pdf”] Selects every </a><a> element whose href attribute value ends with “.pdf”
[attribute=value] a[href=”w3schools”] Selects every </a><a> element whose href attribute value contains the substring “w3schools”
:active a:active Selects the active link
::after p::after Insert something after the content of each <p> element
::before p::before Insert something before the content of each </p><p> element
:checked input:checked Selects every checked element
:default input:default Selects the default element
:disabled input:disabled Selects every disabled element
:empty p:empty Selects every </p><p> element that has no children (including text nodes)
:enabled input:enabled Selects every enabled element
:first-child p:first-child Selects every </p><p> element that is the first child of its parent
::first-letter p::first-letter Selects the first letter of every </p><p> element
::first-line p::first-line Selects the first line of every </p><p> element
:first-of-type p:first-of-type Selects every </p><p> element that is the first </p><p> element of its parent
:focus input:focus Selects the input element which has focus
:hover a:hover Selects links on mouse over
:in-range input:in-range Selects input elements with a value within a specified range
:indeterminate input:indeterminate Selects input elements that are in an indeterminate state
:invalid input:invalid Selects all input elements with an invalid value
:lang(language) p:lang(it) Selects every </p><p> element with a lang attribute equal to “it” (Italian)
:last-child p:last-child Selects every </p><p> element that is the last child of its parent
:last-of-type p:last-of-type Selects every </p><p> element that is the last </p><p> element of its parent
:link a:link Selects all unvisited links
:not(selector) :not(p) Selects every element that is not a </p><p> element
:nth-child(n) p:nth-child(2) Selects every </p><p> element that is the second child of its parent
:nth-last-child(n) p:nth-last-child(2) Selects every </p><p> element that is the second child of its parent, counting from the last child
:nth-last-of-type(n) p:nth-last-of-type(2) Selects every </p><p> element that is the second </p><p> element of its parent, counting from the last child
:nth-of-type(n) p:nth-of-type(2) Selects every </p><p> element that is the second </p><p> element of its parent
:only-of-type p:only-of-type Selects every </p><p> element that is the only </p><p> element of its parent
:only-child p:only-child Selects every </p><p> element that is the only child of its parent
:optional input:optional Selects input elements with no “required” attribute
:out-of-range input:out-of-range Selects input elements with a value outside a specified range
::placeholder input::placeholder Selects input elements with the “placeholder” attribute specified
:read-only input:read-only Selects input elements with the “readonly” attribute specified
:read-write input:read-write Selects input elements with the “readonly” attribute NOT specified
:required input:required Selects input elements with the “required” attribute specified
:root :root Selects the document’s root element
::selection ::selection Selects the portion of an element that is selected by a user
:target #news:target Selects the current active #news element (clicked on a URL containing that anchor name)
:valid input:valid Selects all input elements with a valid value
:visited a:visited Selects all visited links</p></a></p></ul></div></div></div></div>

95
Q

@keyframe - need to read

A

https://www.w3schools.com/cssref/css3_pr_animation-keyframes.asp

96
Q

CSS Combinators

A

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 (~)
97
Q

CSS selector Descendant Selector

A

The descendant selector matches all elements that are descendants of a specified element.

The following example selects all <p> elements inside </p><div> elements:
div p {
background-color: yellow;
}</div>

98
Q

CSS selector Child Selector

A

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 </p><div> element:

Example
div > p {
background-color: yellow;
}

div > p {
background-color: yellow;
}

<div>
  <p>Paragraph 1 in the div.</p>
  <p>Paragraph 2 in the div.</p>
  <p>Paragraph 3 in the div.</p> 
  <p>Paragraph 4 in the div.</p>
</div>

<p>Paragraph 5. Not in a div.</p>

<p>Paragraph 6. Not in a div.</p>

the style is not applied to paragraph 3, as it is not immediate child to div element</div>

99
Q

CSS selector Adjacent Sibling Selector

A

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 </p><div> elements:

Example
div + p {
background-color: yellow;
}

div + p {
background-color: yellow;
}

<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
</div>

<p>Paragraph 3. Not in a div.</p>

<p>Paragraph 4. Not in a div.</p>

the style applied to only paragraph 3</div>

100
Q

CSS selector General Sibling Selector

A

The general sibling selector selects all elements that are siblings of a specified element.

The following example selects all <p> elements that are siblings of </p><div> elements:

Example
div ~ p {
background-color: yellow;
}

div ~ p {
background-color: yellow;
}

<p>Paragraph 1.</p>

<div>
<p>Paragraph 2.</p>
</div>

<p>Paragraph 3.</p>

<code>Some code.</code>

<p>Paragraph 4.</p>

style applied to para 3,4 as these are the siblings after div element </div>

101
Q

All CSS Combinator Selectors

A

Selector Example Example description
element element div p Selects all <p> elements inside </p><div> elements
element>element div > p Selects all <p> elements where the parent is a </p><div> element
element+element div + p Selects all <p> elements that are placed immediately after </p><div> elements
element1~element2 p ~ ul Selects every <ul> element that are preceded by a <p> element</p></ul></div></div></div>

102
Q

CSS :indeterminate Selector

A

The :indeterminate selector selects form elements that are in an indeterminate state.

The :indeterminate selector can only be used on , , and elements.

Note: Checkboxes cannot be indeterminate with HTML - it is a property of the checkbox object, which can be set to true by JavaScript.

Radio buttons are indeterminate when all radio buttons with the same name value in the form are unchecked.

Version:	CSS3
CSS:
input:indeterminate {
  box-shadow: 0 0 1px 1px red;
}

HTML and javascript for setting indeterminate state:

input:indeterminate {
box-shadow: 0 0 1px 1px red;
}

<h1>The indeterminate Selector</h1>

<p>The checkbox below is in an indeterminate state (by JavaScript). If you click on it, it will change its state to "checked", and lose its red shadow color, as it is no longer indeterminate.</p>

<p>Note that an indeterminate checkbox has a "-" icon, rather than a checkmark or an empty box.</p>

Checkbox

// Make the checkbox indeterminate via JavaScript
var checkbox = document.getElementById("myCheckbox");
checkbox.indeterminate = true;
103
Q

!important

A

The !important property in CSS means that all subsequent rules on an element are to be ignored, and the rule denoted by !important is to be applied. This rule overrides all previous styling rules ​– the !important property increases its priority.

The !important property is mentioned immediately before the semicolon:

h1 {
background-color: red !important;
}

104
Q

CSS box-sizing Property

A

The box-sizing property allows us to include the padding and border in an element’s total width and height.

If you set box-sizing: border-box; on an element, padding and border are included in the width and heigh

.div1 {
  width: 300px;
  height: 100px;
  border: 1px solid blue;
  box-sizing: border-box;
}
.div2 {
  width: 300px;
  height: 100px;  
  padding: 50px;
  border: 1px solid red;
  box-sizing: border-box;
}

<div>Both divs are the same size now!</div>

<br></br>

<div>Hooray!</div>

105
Q

background properties

A
body {
  background-image: url('w3css.gif');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: center;
}
106
Q

CSS content Property

A

The content property is used with the ::before and ::after pseudo-elements, to insert generated content.

a::after {
content: “ (“ attr(href) “)”;
}

a::after {
content: “ (“ attr(href) “)”;
}

<h1>The content Property</h1>

<p>The content property is used to insert generated content.</p>

<p>Look at our:</p>

<p>
<a>CSS Tutorial</a><br></br>
<a>CSS Reference</a>
</p>

  • -
    https: //www.w3schools.com/cssref/tryit.asp?filename=trycss_content
107
Q

CSS pointer-events Property

A

The pointer-events property defines whether or not an element reacts to pointer events.

div.ex1 {
pointer-events: none;
}

div.ex2 {
pointer-events: auto;
}

108
Q

CSS cursor Property

A

The cursor property specifies the mouse cursor to be displayed when pointing over an element.

div {
cursor:grab;
}

109
Q

apply style for element type with class

A

span.alert-filter-link:hover {
color: black;
text-decoration: none;
}

applying style for span element that has alert-filter-link class and applying the style on mouse hover

110
Q

CSS Grid vs CSS Flexbox -Grid is Container-Based, Flexbox is Content-Based -if possible, avoid using flexbox to build the overall layout of your website.

A

In flexbox layout, the size of a cell (flex-item) is defined inside the flex-item itself, and in the grid layout, the size of a cell (grid-item) is defined inside the grid-container.

<div class="row">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
And we style this using flexbox like so:
.row {
    margin: 20px auto;
    max-width: 300px;
    display: flex;
}
.row > div {
    border: 1px dashed gray;
    flex: 1 1 auto; /* Size of items defined inside items */
    text-align: center;
    padding: 12px;
}
We defined the size of the cells inside the flex-item by setting flex: 1 1 auto;. The flex property is shorthand to set flex-grow, flex-shrink, and flex-basis properties in one statement; its default value is 0 1 auto. Notice the “row” div is the flex-container, and we don’t set the size of the items there. We set the size inside the flex-item.

When previewed in a browser we get a row of boxes, as you would expect:

screencap-1
Now let’s see how we can generate the same output using grid:

.row {
    margin: 20px auto;
    max-width: 300px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr; /* Size of items defined inside container */
}
.row div {
    border: 1px dashed gray;
    text-align: center;
    padding: 12px;
}
Above code will give us exactly the same output.

Notice, now we are defining the cell’s size using grid-template-columns inside the grid-container (.row), not the grid-item.

This is an important difference. It shows that the flexbox layout is calculated after its content is loaded whereas the grid layout is calculated regardless of the content inside it. So, if possible, avoid using flexbox to build the overall layout of your website.

111
Q

CSS Grid vs CSS Flexbox -Grid Has a “Gap” Property, Flexbox Doesn’t

A

You can argue that a major difference between flexbox and grid is that in the latter we can create gutters between grid-items using grid-column-gap, like so:

screencap-2
In order to achieve the same result in flexbox we would have to use padding and nested containers, or increase the width of the flex-container and use the justify-content property to spread the flex-items.

We have to take a circuitous route in flexbox because it doesn’t have a gap property. However, it is on the way; the CSS Box Alignment Module 3 contains CSS features relating to alignment of boxes in all layout modes: block layout, table layout, flex layout, and grid layout. The Box Alignment module collects properties from flexbox, grid, and multi-column which can be used consistently across all the layout models. Eventually we’ll be able to add gaps with row-gap and column-gap properties, but not yet.

112
Q

CSS Grid vs CSS Flexbox-Flexbox is One Dimensional, Grid is Two Dimensional

A

We’ve been arranging elements as rows and columns on the web since we used tables for layout. Both flexbox and grid are based on this concept. Flexbox is best for arranging elements in either a single row, or a single column. Grid is best for arranging elements in multiple rows and columns.

In other words, Flexbox is one dimensional, and Grid is two dimensional. Let’s look at a commonly used one dimensional layout – the social share buttons:

All the elements are in a single row. We can implement this using Flexbox like this:

<ul>
<li><a><i></i></a></li>
<li><a><i></i></a></li>
<li><a><i></i></a></li>
<li><a><i></i></a></li>
<li><a><i></i></a></li>
<li><a><i></i></a></li>
</ul>

.social-icons {
  display: flex;
  list-style: none;
  justify-content: space-around;
}
The justify-content property determines how the extra space of the flex-container is distributed to the flex-items. The space-around value distributes the space in such a way that the flex-items get placed evenly with equal amount of space around them.

Next, let’s take a look at a commonly used 2-dimensional layout:

We can’t implement this layout with a single row or a single column, we need multiple rows and columns to do that, and that’s where we use CSS Grids. Let’s make it using CSS Grid:

<div class="container">
  Header
  Main
  Aside
  Footer
</div>
and the CSS:
.container {
  max-width: 800px;
  margin: 2em auto;
  display: grid;
  grid-template-columns: 3fr 1fr;
  grid-template-rows: repeat(3,auto);
  grid-gap: 1rem;
}

.container header {
grid-area: 1/1/2/3;
}

.container main {
grid-area: 2/1/3/2;
}

.container aside {
grid-area: 2/2/3/3;
}

.container footer {
grid-area: 3/1/4/3;
}

.container > * {
  background-color: #ddd;
  padding: 1rem;
}
We are creating two columns using the grid-template-columns property, and three rows using grid-template-rows property. The repeat() function creates 3 rows with auto height.

Then, inside the grid-items (header, main, aside, and footer) we define how much area those grid-items will cover using the grid-area property.

113
Q

CSS Grid vs CSS Flexbox -Flexbox Wraps vs Grid Wraps

A

When the total width of items inside the container is greater than the width of the container, in that case both the layout models have the option to wrap the items to a new row. However, the way both handle wrapping is different.

Let’s look at that difference by building an sample layout. Create two rows and place 6 divs inside each row:

<h2>Flexbox</h2>
<div class="row-flex">
    <div>1 2 3  4 5 6 7 8 9 0</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
</div>
<h2>Grid</h2>
<div class="row-grid">
    <div>1 2 3  4 5 6 7 8 9 0</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
</div>
Now, we will use Flexbox to layout the first row and Grid for second:
/* Flexbox row styles */
.row-flex {
  margin: 40px auto;
  max-width: 600px;
  display: flex;
  flex-wrap: wrap;
}
.row-flex div {
  border: 1px dashed gray;
  flex: 1 1 100px;
  text-align: center;
  padding: 12px;
}
/* Grid row styles */
.row-grid {
  margin: 40px auto;
  max-width: 600px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
.row-grid div {
  border: 1px dashed gray;
  text-align: center;
  padding: 12px;
}
For the first row, we are using flex: 1 1 100px to give the flex-items a base width of 100px and allow it to grow and shrink.

We are also enabling wrapping of flex-items inside the flex-container by setting the flex-wrap property to wrap, its default value is nowrap.

For the second row, we are using the grid-template-columns property to create columns with minimum width 100px set by the minmax() function. We are using repeat() function to create columns repeatedly.

You can see the beauty of Grid and Flexbox lies in the ability to stretch and squeeze the items based on the amount of space available. Flexbox achieves this using flex-grow and flex-shrink properties, and Grid achieves this using a combination of minmax and auto-fill functions inside the grid-template-columns property.

However, look carefully at the cell 5 and cell 6 as they are pushed down. In the case of Flexbox, the cell 5 and 6 are not the same size as other cells when pushed down. While in case of Grid, they retain the same size as all other cells in the grid.

This happens because when a flex-item is wrapped and pushed in a new row, the Flexbox layout algorithm treats it as a part of a different flex-container. Hence the pushed item loses its context.

This behavior could be used in some use cases, for example, an email subscriber form:

Let’s build this subscriber form:

<div>

</div>

and give it some styles in our CSS:

.subscriber-form-container {
  max-width: 650px;
  margin: 40px auto;
  border: 1px dashed gray;
  box-sizing: border-box;
}
.subscriber-form-container form {
  display: flex;
  flex-wrap: wrap;
}
.subscriber-form-container form input {
  margin: 6px;
  padding: 0.4rem;
  box-sizing: border-box;
}
.subscriber-form-container form input{
  flex: 1 1 150px;
}
.subscriber-form-container form input[type="email"] {
  flex: 2 1 300px;
}
The flex property is the shorthand for three properties: flex-grow, flex-shrink, and flex-basis. We want the width of the “email” field to be double the width of other two input elements, and we achieve this by using its “flex-grow” and “flex-basis”.

The “flex-grow” property of input elements is set to “1”, but that of email input element is set to 2. So, when there is extra space available, the email input element will grow twice compared to other input elements.

Flexbox outperforms Grid in this use case. Yes, you could use some hack to get CSS Grid replicate this behavior using minmax() function, but Flexbox is well-suited for this kind of single dimensional layouts.

However, if you want a multi-dimensional layout with the wrapped elements maintaining their widths, for example, an image gallery, then Grid is the best choice:

One more thing, did you notice we are not using any media queries here. That’s because Flexbox and Grid layouts are built on concept of responsiveness and hence reduce the use of Media Queries.