Responsive Web
Responsive Web
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<h2>Responsive Image</h2>
<p>"max-width:100%" prevents the image from getting bigger than its original size. However, if
you make the browser window smaller, the image will still scale down.</p>
<p>Resize the browser window to see the effect.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
<p style="font-size:5vw;">Resize the browser window to see how the text size scales.</p>
<p style="font-size:5vw;">Use the "vw" unit when sizing the text. 10vw will set the size to 10% of the viewport width.</p>
<p>Viewport is the browser window size. 1vw = 1% of viewport width. If the viewport is 50cm wide, 1vw is 0.5cm.</p>
</body>
</html>
The box-sizing property can be used to adjust this behavior:
content-box gives you the default CSS box-sizing behavior. If you set an
element's width to 100 pixels, then the element's content box will be 100
pixels wide, and the width of any border or padding will be added to the final
rendered width, making the element wider than 100px.
border-box tells the browser to account for any border and padding in the
values you specify for an element's width and height. If you set an element's
width to 100 pixels, that 100 pixels will include any border or padding you
added, and the content box will shrink to absorb that extra width. This
typically makes it much easier to size elements.
Media Query
@media(min-width: 1200px) {
//PASTE CSS CODE
}
@media(min-width: 992px) and (max-width: 1199)
{
}
@media(min-width: 768px) and (max-width: 991)
{
}
@media(max-width: 767px) {
}
CSS GRID
The CSS Grid Layout Module offers a grid-based layout system, with
rows and columns, making it easier to design web pages without having
to use floats and positioning.
<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
<div class="grid-item">7</div>
<div class="grid-item">8</div>
<div class="grid-item">9</div>
</div>
<style>
.grid-container {
display: grid;
Set a size for the 4 columns:
grid-template-columns: auto auto auto;
background-color: red; .grid-container {
padding: 10px; display: grid;
} grid-template-columns: 80px 200px auto 40px;
}
.grid-item {
background-color: rgba(255, 255, 255, 0.8);
border: 1px solid rgba(0, 0, 0);
padding: 20px;
font-size: 30px;
text-align: center;
}
</style>
Grid Columns
Grid Rows
Grid Gaps
You can adjust the gap size by using one of
the following properties:
grid-column-gap
grid-row-gap
grid-gap
An HTML element becomes a grid container when its display property is
set to grid or inline-grid.
Grid Lines
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
@keyframes mymove {
0% {top: 0px;}
100% {top: 200px;}
}
Definition and Usag
The animation is created by gradually changing from one set of CSS styles to another.
During the animation, you can change the set of CSS styles many times.
Specify when the style change will happen in percent, or with the keywords "from" and "to",
which is the same as 0% and 100%. 0% is the beginning of the animation, 100% is when the
animation is complete.
Tip: For best browser support, you should always define both the 0% and the 100% selectors.
Add many keyframe selectors in one
animation:
@keyframes mymove {
0% {top: 0px;}
25% {top: 200px;}
50% {top: 100px;}
75% {top: 200px;}
100% {top: 0px;}
}
Change many CSS styles in one animation:
@keyframes mymove {
0% {top: 0px; background: red; width: 100px;}
100% {top: 200px; background: yellow; width: 300px;}
}
Many keyframe selectors with many CSS
styles:
@keyframes mymove {
0% {top: 0px; left: 0px; background: red;}
25% {top: 0px; left: 100px; background: blue;}
50% {top: 100px; left: 100px; background: yellow;}
75% {top: 100px; left: 0px; background: green;}
100% {top: 0px; left: 0px; background: red;}
}
CSS Flexbox
Flexbox Elements
To start using the Flexbox model, you need to first define a flex
container.
<div class="flex-
container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<style>
.flex-container {
display: flex;
background-color: DodgerBlue;
}
The flex container becomes flexible by setting the display
.flex-container > div { property to flex:
background-color: #f1f1f1;
margin: 10px;
padding: 20px;
font-size: 30px;
}
</style>
The flex container properties are:
flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content
flex-direction
.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):
The flex-wrap Property
The flex-wrap property specifies whether the flex items should wrap or not.
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: DodgerBlue;
}
.flex-container > div {
background-color: #f1f1f1;
The nowrap value specifies that the flex items will not wrap
width: 100px; (this is default):
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
</style>
The flex-flow Property
The flex-flow property is a shorthand property for setting both the flex-
direction and flex-wrap properties.
.flex-container {
display: flex;
flex-flow: row wrap;
}
justify-content Property
order
flex-grow
flex-shrink
flex-basis
flex
align-self
The order Property
The order property specifies the order of the flex items.
style> <body>
.flex-container {
display: flex; <h1>The order Property</h1>
align-items: stretch;
background-color: #f1f1f1; <p>Use the order property to sort the flex items as you
} like:</p>
The flex-grow property specifies how much a flex item will grow relative
to the rest of the flex items.
<div class="flex-container">
<div style="flex-grow: 1">1</div>
<div style="flex-grow: 1">2</div>
<div style="flex-grow: 8">3</div>
</div>
Make the third flex item grow eight times faster than the other flex
items:
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.
<div class="flex-container">
<div>1</div>
<div>2</div>
<div style="flex-shrink: 2">3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>