CSS Flashcards
CSS display Property
p. ex1 {display: none;}
p. ex2 {display: inline;}
p. ex3 {display: block;}
p. ex4 {display: inline-block;}
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>
Before CSS Flexbox
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.
Flexbox Elements
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>
Parent Element (Container)
The flex container becomes flexible by setting the display property to flex:
.flex-container {
display: flex;
}
The flex container properties are:
flex-direction flex-wrap flex-flow justify-content align-items align-content
flex container - The flex-direction Property
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;
}
flex container - The flex-wrap Property
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;
}
flex container - The flex-flow Property
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; }
flex container - The justify-content Property -Horizontal alignment
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; } ----
flex container - The align-items Property - vertical alignment
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>
flex container - The align-content Property -vertical alignment when there are multiple lines
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; }
flex container- Perfect Centering
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; }
Flex container -Child Elements (Items) or Flex items
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>
flex item properties - The order Property
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>
flex item properties -The flex-grow Property
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>
flex item properties -The flex-shrink Property
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>
flex item properties - The flex-basis Property
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>
flex item properties -The flex Property
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>
flex item properties -The align-self Property
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>
styling div element within a class .flex-container>div
.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>
Flex container - Flex items - align self property
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>
CSS Flexbox Properties
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
CSS2 Introduced Media Types
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.
CSS3 Introduced Media Queries
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).
Resize the browser window to see the effect!
The media query will only apply if the media type is screen and the viewport is 480px wide or wider.
Resize the browser window to see the effect!
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.
element: ``` p { margin-top: 100px; margin-bottom: 100px; margin-right: 150px; margin-left: 80px; }
```element be inherited from the parent element (
Use of the inherit value
Let the left margin be inherited from the parent element:
This paragraph has an inherited left margin (from the div element).
element has a bottom margin of 50px and the element has a top margin set to 20px.
Common sense would seem to suggest that the vertical margin between the and the 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;
}
and the 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;
}
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.
Heading 1
Heading 2
The border-radius Property
Rounded corners for an element with a specified background color:
Rounded corners!
Rounded corners for an element with a border:
Rounded corners!
Rounded corners for an element with a background image:
Rounded corners!
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.The border-radius Property
Four values - border-radius: 15px 50px 30px 5px:
Three values - border-radius: 15px 50px 30px:
Two values - border-radius: 15px 50px:
One value - border-radius: 15px:
The border-radius Property
Elliptical border - border-radius: 50px / 15px:
Elliptical border - border-radius: 15px / 50px:
Ellipse border - border-radius: 50%:
The transition Property
Hover over the div element below, to see the transition effect:
Note: This example does not work in Internet Explorer 9 and earlier versions.
The transition Property
Hover over the div element below, to see the transition effect:
Note: This example does not work in Internet Explorer 9 and earlier versions.
The transition-timing-function Property
Hover over the div elements below, to see the different speed curves:
``````
Note: This example does not work in Internet Explorer 9 and earlier versions.
The transition-delay Property
Hover over the div element below, to see the transition effect:
Note: The transition effect has a 1 second delay before starting.
Note: This example does not work in Internet Explorer 9 and earlier versions.
Transition + Transform
Hover over the div element below:
Note: This example does not work in Internet Explorer 9 and earlier versions.
This is some text.
This is some text.
This is some text.
This is some text.
This is the default text direction.
This is right-to-left text direction.
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 sihtAn image with a default alignment.
An image with a text-top alignment.
An image with a text-bottom alignment.
elements element.class p.intro Selects all
elements with class="intro" element,element div, p Selects all
elements element element div p Selects all
elements inside
elements where the parent is a
elements that are placed immediately after
- element that are preceded by a
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 element whose href attribute value begins with "https"
[attribute$=value] a[href$=".pdf"] Selects every element whose href attribute value ends with ".pdf"
[attribute*=value] a[href*="w3schools"] Selects every 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 element
::before p::before Insert something before the content of each 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 element that has no children (including text nodes)
:enabled input:enabled Selects every enabled element
:first-child p:first-child Selects every element that is the first child of its parent
::first-letter p::first-letter Selects the first letter of every element
::first-line p::first-line Selects the first line of every element
:first-of-type p:first-of-type Selects every element that is the first 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 element with a lang attribute equal to "it" (Italian)
:last-child p:last-child Selects every element that is the last child of its parent
:last-of-type p:last-of-type Selects every element that is the last element of its parent
:link a:link Selects all unvisited links
:not(selector) :not(p) Selects every element that is not a element
:nth-child(n) p:nth-child(2) Selects every element that is the second child of its parent
:nth-last-child(n) p:nth-last-child(2) Selects every 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 element that is the second element of its parent, counting from the last child
:nth-of-type(n) p:nth-of-type(2) Selects every element that is the second element of its parent
:only-of-type p:only-of-type Selects every element that is the only element of its parent
:only-child p:only-child Selects every 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
elements inside
elements that are children of a
Paragraph 1 in the div.
Paragraph 2 in the div.
Paragraph 3 in the div.
Paragraph 4 in the div.
Paragraph 5. Not in a div.
Paragraph 6. Not in a div.
the style is not applied to paragraph 3, as it is not immediate child to div elementelements that are placed immediately after
Paragraph 1 in the div.
Paragraph 2 in the div.
Paragraph 3. Not in a div.
Paragraph 4. Not in a div.
the style applied to only paragraph 3elements that are siblings of
Paragraph 1.
Paragraph 2.
Paragraph 3.
Some code.
Paragraph 4.
style applied to para 3,4 as these are the siblings after div elementelements inside
elements where the parent is a
elements that are placed immediately after
- element that are preceded by a
element
The indeterminate Selector
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.
Note that an indeterminate checkbox has a "-" icon, rather than a checkmark or an empty box.
Checkbox ``` // Make the checkbox indeterminate via JavaScript var checkbox = document.getElementById("myCheckbox"); checkbox.indeterminate = true; ```The content Property
The content property is used to insert generated content.
Look at our:
- - https: //www.w3schools.com/cssref/tryit.asp?filename=trycss_content