
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Changing Layouts Based on Screen Size using CSS
To change the layouts based on screen size in CSS, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } * { box-sizing: border-box; } .col { color: white; float: left; width: 25%; padding: 10px; } .colContainer:after { content: ""; display: table; clear: both; } @media screen and (max-width: 900px) { .col { width: 50%; } } @media screen and (max-width: 600px) { .col { width: 100%; } } </style> </head> <body> <h1>Changing layout on screen size using CSS</h1> <h2>Resize the screen to see the below divs resize themselves</h2> <div class="colContainer"> <div class="col" style="background-color: rgb(153, 29, 224);"> <h2>First col</h2> </div> <div class="col" style="background-color: rgb(12, 126, 120);"> <h2>Second col</h2> </div> <div class="col" style="background-color: rgb(207, 41, 91);"> <h2>Third col</h2> </div> <div class="col" style="background-color: rgb(204, 91, 39);"> <h2>Fourth col</h2> </div> </div> </body> </html>
Output
The above code will produce the following output −
- Related Articles
- Changing Column Width Based on Screen Size using CSS
- Changing Parameters on the screen in SAP
- Finding the height based on width and screen size ratio (width:height) in JavaScript
- HTML5 Canvas Font Size Based on Canvas Size
- Rotate the element based on an angle using CSS
- Hide content depending on screen size with Bootstrap
- Changing the look of Cursor using CSS
- Changing the Default Display Value using CSS
- Changing the Position of List Markers using CSS
- Filtering Images based on size attributes in Python?
- How to make an alert dialog fill 50% of screen size on Android devices using Kotlin?
- Display flex items horizontally on a specific screen size in Bootstrap
- Set Responsive Font Size using CSS
- Perform Animation on CSS font-size property
- How to Fix Overflow Issues in CSS Flex Layouts?

Advertisements