Responsive Layouts
The responsive layout module of CSS includes the following properties.
5.1 Using flexbox property
In this approach, we will use CSS display property to make the page responsive. Display layouts like flexbox, inline, blocks, and grids can be used to make the design responsive. CSS flexbox property auto adjusts the content (no. of columns in a row) according to the screen width as shown in the output gif.
Syntax
.container{
display: flexbox;
}
Example: In this example, we will use display type flexbox to show adjust items automatically according to the screen size.
<!DOCTYPE html>
<html>
<head>
<title>w3wiki</title>
<style>
body {
background-color: aqua;
}
.gfg {
font-size: 5vw;
font-weight: bold;
color: green;
text-align: center;
}
button {
width: 300px;
font-size: larger;
}
.container {
display: flexbox;
}
</style>
</head>
<body>
<div class="gfg">w3wiki</div>
<div class="container">
<button>HTML</button>
<button>CSS</button>
<button>JavaScript</button>
</div>
</body>
</html>
Output
Note: Sometimes, this method doesn’t show the correct output on Google Chrome.
5.2 Using CSS Grids
This approach uses a CSS display grid to create a 2D layout along with other grid options. It allows us to decide the number of columns we want to keep and instead of rearranging the columns like Flexbox, it adjusts the content within individual column elements.
Syntax
.container{
display: grid;
/* To define colums*/
grid-template-columns: 1fr 1fr;
}
Example: In this example, CSS Grid layout is used to arrange contents in 2D form, i.e., rows and columns.
<!DOCTYPE html>
<html>
<head>
<title>w3wiki</title>
<style>
body {
background-color: aqua;
}
.gfg {
font-size: 5vw;
font-weight: bold;
color: green;
text-align: center;
}
.container {
font-size: x-large;
text-align: center;
display: grid;
grid-template-columns: 1fr 1fr;
}
.grid-item {
background-color: rgb(220, 208, 232);
border: 2px solid rgb(70, 54, 84);
}
</style>
</head>
<body>
<div class="gfg">w3wiki</div>
<div class="container">
<div class="grid-item">HTML</div>
<div class="grid-item">CSS</div>
<div class="grid-item">JavaScript</div>
<div class="grid-item">Bootstrap</div>
</div>
</body>
</html>
Output
Note: Sometimes, this method doesn’t show the correct output on Google Chrome.
5.3 Using CSS MultiColumn
It is similar to grids. CSS MulotiColumn allows developers to choose the properties like no. of columns, width, gap, etc. for each column. These values remain unchanged but the content inside the columns adjusts.
Syntax
.container{
column-count: 3; /* Number of columns*/
column-gap: 20px; /* Gap between columns*/
column-width: 200px; /* Width of each column*/
/* Other column properties*/
}
Example: This example uses CSS MultiColumn for content division into a specific number of columns.
<!DOCTYPE html>
<html>
<head>
<title>w3wiki</title>
<style>
body {
background-color: aqua;
}
.gfg {
font-size: 5vw;
font-weight: bold;
color: green;
text-align: center;
}
.container {
font-size: x-large;
text-align: left;
column-count: 3;
column-gap: 5%;
}
</style>
</head>
<body>
<div class="gfg">w3wiki</div>
<div class="container">
<div>
HTML stands for HyperText Markup Language.
It is used to design web pages using a
markup language. HTML is a combination of
Hypertext and Markup language. Hypertext
defines the link between web pages. A markup
language is used to define the text document
within the tag which defines the structure
of web pages. This language is used to
annotate (make notes for the computer) text
so that a machine can understand it and
manipulate text accordingly. Most markup
languages (e.g. HTML) are human-readable.
The language uses tags to define what
manipulation has to be done on the text.
</div>
</div>
</body>
</html>
Output
HTML Responsive Web Design allows websites to adapt to various screen sizes, ensuring a seamless user experience across devices. By using HTML and responsive techniques, designers and developers can create websites that look great whether viewed on a desktop or a smartphone. This flexibility enhances accessibility and usability, making browsing a breeze for all users. In essence, HTML Responsive Web Design is crucial for ensuring that websites remain functional and visually appealing regardless of the device being used.
HTML Responsive Web Design
HTML Responsive Web Design is a smart way of designing web pages to look great on any device. It’s all about making HTML elements adjust themselves, like resizing or hiding, based on the device’s screen size. This ensures that no matter if someone’s using a phone, tablet, or computer, the web pages will always look good.
We will show you various examples of how to create an HTML responsive web design that adapts perfectly to different screen sizes.