How to create Responsive Floating Elements using CSS ? Last Updated : 24 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The Responsive Floating Elements are useful for adaptable layouts on different devices. It ensures a seamless user experience by adjusting the size and arrangement of cards based on the screen size. The float property is employed to arrange the cards horizontally, making them responsive on various devices. PreviewApproachCreate the basic structure of the web page using different HTML elements like <h1>, <p>, <div>, <img>, and <h2> elements.Make a three-card layout with an image, title and description. The heading and paragraph have green text colour and are centred. Also, the content is organized using a container (float-container) that has a maximum width of 1200px and is centered with auto margins. The float: left property is applied to the .float-item class. This property is used to make the elements align horizontally, allowing them to appear side by side.Apply media queries for responsiveness, initially, each .float-item takes up the full width of its container, but when the screen width is at least 600px, the width is adjusted to 48%, and on larger screens (900px or more), the width is further reduced to 31%, maintaining three items in a rowExample: Implemenatation to show responsive floating elements using CSS. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { background-color: rgb(237, 237, 180); } h1 { color: green; text-align: center; } p { font-size: 30px; text-align: center; } .float-container { width: 100%; max-width: 1200px; margin: 0 auto; overflow: hidden; } .float-item { float: left; width: 100%; margin: 0 10px; box-sizing: border-box; background-color: #d3c5c5; padding: 20px; margin-bottom: 20px; border-radius: 8px; text-align: center; } @media screen and (min-width: 600px) { .float-item { width: 48%; } } @media screen and (min-width: 900px) { .float-item { width: 31%; height: 400px; } } .card-img { max-width: 100%; height: auto; border-radius: 50%; } .card-title { font-size: 1.5rem; margin: 10px 0; } .card-paragraph { font-size: 1rem; } </style> <title>Responsive Floating Elements</title> </head> <body> <h1>GeeksforGeeks</h1> <p>Responsive Floating Elements</p> <div class="float-container"> <div class="float-item"> <!-- Box Card 1 --> <img class="card-img" src= "https://media.geeksforgeeks.org/auth-dashboard-uploads/read.png" alt="Card Image"> <h2 class="card-title"> Learn Data Structures and Algorithms | DSA Tutorial </h2> <p class="card-paragraph"> DSA is defined as a combination of two separate yet interrelated topics – Data Structure and Algorithms. DSA is one of the most important skills that every computer science student. It is often seen that people with good knowledge of these technologies. </p> </div> <div class="float-item"> <!-- Box Card 2 --> <img class="card-img" src= "https://media.geeksforgeeks.org/auth-dashboard-uploads/practice.png" alt="Card Image"> <h2 class="card-title">SDE Sheet</h2> <p class="card-paragraph"> Preparing for placements and dont know where to start ? GFG has used their years of experience and put together this list for you. It is a compilation of the most popular DSA problems ranging from topics like arrays, hashing, tree, graph etc. The list contains problems across easy, medium, hard difficulty. </p> </div> <div class="float-item"> <!-- Box Card 3 --> <img class="card-img" src= "https://media.geeksforgeeks.org/auth-dashboard-uploads/learn.png" alt="Card Image"> <h2 class="card-title"> Complete Machine Learning & Data Science Program </h2> <p class="card-paragraph"> A 360-degree Learning experience designed for geeks who wish to get hands-on Data Science. Mentored by industry experts; learn to apply DS methods and techniques, and acquire analytical skills. So Master the Art of Data Science Now! </p> </div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to hide elements in responsive layout using CSS ? S shivanigupta18rk Follow Improve Article Tags : Web Technologies Web Templates Similar Reads How to create a Responsive Inline Form using CSS ? When the browser window is resized, the labels and inputs will stack on top of each other for smaller screens. To create a responsive inline form using CSS, use a container with flexible styling, such as Flexbox or Grid, to arrange form elements horizontally. Utilize media queries to adjust the layo 3 min read How to hide elements in responsive layout using CSS ? CSS provides powerful tools to create responsive websites that adapt to different screen sizes and devices. One of the key techniques for creating responsive designs is media queries, introduced in CSS3. Media queries allow you to apply styles based on the characteristics of the device, such as its 3 min read How to Create a Responsive Image Grid using CSS? A responsive image grid is a layout technique used to display images in a grid-like structure that adjusts dynamically based on the screen size to ensure that the grid looks good and functions well across various devices and screen resolutions. Below are the approaches to creat a responsive image gr 3 min read How to Create a Responsive Image Gallery using CSS? Creating a responsive image gallery using CSS is a common task in web development. A responsive gallery adjusts to different screen sizes and ensures that images look good on devices ranging from mobile phones to desktop monitors. In this article, we will explore different approaches to creating a r 3 min read How to fix weird behaviors of floating elements using CSS ? In this article, we will see the use of the floating property of CSS and fix its weird behavior. CSS float is one of the most important properties. It arranges the block element in a line "Left" or "Right" according to their size but the default value of the float is "none" ( The block element will 3 min read How to Create Floating Box Effect using HTML and CSS ? The floating box effect is a classical example of a custom box-shadow technique. In this technique, we create realistic-looking shadows without using the box-shadow property that is provided by the CSS. Approach: The approach is to use after selector to use create shadow using the blur function. HTM 2 min read Like