css_reponsive_web
Responsive Web Design
Responsive web design is broken down into three main components, including flexible layouts, media queries, and flexible media.
flexible layouts
The first part, flexible layouts, is the practice of building the layout of a website with a flexible grid, capable of dynamically resizing to any width. Flexible grids are built using relative length units, most commonly percentages or em units. These relative lengths are then used to declare common grid property values such as width, margin, or padding.
Relative length units, specifically related to the viewport size of the browser or device. These new units include vw, vh, vmin, and vmax
- vw viewports width
- vh viewports height
- vmin Minimum of the viewport’s height and width
- vmax Maximum of the viewport’s height and width
1 | .container { |
media queries
flexible media
Rules
- Do NOT use large fixed width elements
- Do NOT let the content rely on a particular viewport width to render well
- Use CSS media queries to apply different styling for small and large screens
- Always Design for Mobile(small device) First, This will make the page display faster on smaller devices
- Hide Elements With Media Queries(hide something for small device)
- Different Images for Different Devices
Example1
2
3
4
5
6
7
8
9
10
11
12
13
14
15.menu {
// use percent of container not fixed width like width: 500px etc
width: 25%;
float: left;
}
.main {
width: 75%;
float: left;
}
// If the max-width property is set to 100%, the image will scale down if it has to, but never scale up to be larger than its original size, same thing for video as well.
img {
max-width: 100%;
height: auto;
}
Mobile First
1 | /* For mobile phones: */ |
Typical device
1 | /* Extra small devices (phones, 600px and down) */ |