The Wayback Machine - https://web.archive.org/web/20240825100540/https://www.geeksforgeeks.org/how-to-create-floating-box-effect-using-html-and-css/
Open In App

How to Create Floating Box Effect using HTML and CSS ?

Last Updated : 14 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

HTML Code: In this section, we have created the basic structure of the body. Here, we have used a <div> tag containing class attribute to render the floating box on the screen.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,
                   initial-scale=1.0">
    <title>Floating Box</title>
</head>
<body>
    <h1>GeeksForGeeks</h1>
    <div class="geeks"></div>
</body>
</html>


CSS Code: In this section, we have used some CSS property to design floating box and assign some styles on them. The following steps describe the CSS properties: 

  • Step 1: First we have done some basic styling like providing a background, creating a box, and aligning everything to the center of the page.
  • Step 2: Now, use the after selector to create a thin line below the box that we have created and then use blur function to give it the shadow effect.

Tip: Try use a darker color and a low value for blur function for shadow. If not, you might end up making your shadow transparent. 

CSS




<style>
    body {
        background: green;
    }
 
    h1 {
        display: flex;
        justify-content: center;
        color: white;
        font-size: 40px;
    }
 
    .geeks {
        width: 400px;
        height: 250px;
        background: white;
        position: absolute;
        top: 16%;
        left: 35%;
        border-radius: 20px;
    }
 
    .geeks::after {
        content: "";
        position: absolute;
        bottom: -30px;
        background: rgb(43, 42, 42);
        width: 90%;
        height: 4px;
        left: 3%;
        border-radius: 50%;
        filter: blur(3px);
    }
</style>


Complete Code: It is the combination of the above two codes. 

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width,initial-scale=1.0">
    <title>Floating Box</title>
    <style>
        body {
            background: green;
        }
        h1 {
            display:flex;
            justify-content: center;
            color: white;
            font-size: 40px;                   
            }
 
        .geeks {
            width:400px;
            height:250px;
            background: white;
            position: absolute;
            top:16%;
            left:35%;
            border-radius: 20px;
        }
 
        .geeks::after {
            content: "";
            position: absolute;
            bottom: -30px;
            background: rgb(43, 42, 42);
            width: 90%;
            height:4px;
            left:3%;
            border-radius:50%;
            filter: blur(3px);
        }
    </style>
</head>
 
<body>
    <h1>GeeksForGeeks</h1>
    <div class="geeks"></div>
</body>
 
</html>


Output: 

 



Similar Reads

How to create an accordion hover effect with box-shadows in CSS ?
The purpose of this article is to use box shadows for creating an accordion hover effect. Approach: The CSS box-shadow property is used to draw shadows around an element. CSS box-shadow property has the following syntax. Syntax: box-shadow : x-offset y-offset blur-radius spread-radius colorExample 1:  [GFGTABS] HTML &lt;!DOCTYPE html&gt; &lt;html
2 min read
How to Create an Image Overlay Fade in Box Effect on Hover ?
The image overlay fade in box effect on hover is a visual effect where a box fades in over an image when the user hovers their mouse over the image. It can be used to display additional information about the image or simply add a stylish touch to your website. ApproachCreate an HTML document and create the image container element with the class ima
2 min read
How to Create Liquid Filling Effect on Text using HTML and CSS ?
The liquid fill text animation can be done using CSS | ::before selector. We will use key frames to set height for each frame of animation. Please make sure you know about both CSS | ::before selector and CSS | @keyframes Rule before try this code.The basic styling of the text can be done differently that totally depends on you how you want your te
3 min read
How to create paper corner fold effect on hover by using HTML and CSS?
The folding effect is quite attractive on the website, may you have seen on some websites when you hover on the paging layout it gets folded on the corner. The folding corner effect can be achieved by using HTML and CSS only. The below sections will guide you on how to create the animation. In this article, we will divide the article into two secti
3 min read
How to Create an Effect to Change Button Color using HTML and CSS ?
The color-changing effect of a button is very common but what we are going to do a slightly advanced version of this effect. The background will change like a clip effect rotating at some particular angle. Approach: The approach is to provide two or three background and then rotating them on different angles. HTML Code: In this section, we will use
3 min read
How to Create Animated Navigation Bar with Hover Effect using HTML and CSS ?
The Navigation bar or navbar or menu-bar is the most important component of any web or mobile application. The user can only navigate from one page to another page through this menu. It is usually provided at the top of the website to provide a better UX (user experience). Approach: The approach is to create a navbar first and then animate a line b
3 min read
How to create followspot effect using HTML CSS and jQuery ?
The follow-spot effect (spotlight effect) is an effect that can be easily implemented using jQuery. The effect is quite popular for the opening or front banner design for any website. Approach: The approach is to use circle CSS on the mouse movement effect using the mousemove() function provided by jQuery. HTML Code: The HTML code is used to design
2 min read
How to Create Engraved Text Effect using HTML and CSS ?
The engraved text effect is an effect that you can use in your websites as a heading or a sub-heading to make it look more pleasing and attractive. Approach: The engraved text effect can be easily generated using HTML and CSS. First we will create a basic text using HTML and then by using the CSS text-shadow property we will generate the desired ef
2 min read
How to Create Text Reveal Effect for Buttons using HTML and CSS ?
Buttons are the most important user interface component for any website. It is very important to design the buttons in a creatively unique way. The text-reveal effect for a button is used when it is used to reveal some offer or exciting content for enhancing the user experience. Approach: The approach is to cover the button with a strip of the same
2 min read
How to create reflection effect using HTML and CSS ?
The reflection effect is one of the coolest effects that one can use in his/her website. It is a type of informal effect so it is highly recommended not to use it any professional project. You can use it in your personal projects and maybe your portfolio to show your creativity. In this effect, we try to imitate a realistic reflection effect like i
3 min read
Create a Gradient Text Effect using HTML and CSS
This article will show the approach to add a gradient effect on text using the background-clip CSS property. The final output of text using this effect is shown below. The CSS properties that would be used are flexbox, background-clip, and -webkit-background-clip and the background. HTML Section: This section contains the HTML markup that will cont
3 min read
How to create Neumorphism Effect using HTML and CSS ?
Neumorphism (neomorphism) is a modern way of styling web-elements of any web-page and providing a 3D effect. This animation effect can be easily generated by using HTML and CSS. Box-shadow property of CSS can be used to implemented Neumorphism. It is used to add a dark shadow to one side and a light shadow to the other side of the given element. HT
2 min read
How to create windows loading effect using HTML and CSS ?
In this article, we are going to create a window loading effect before the lock screen appears using HTML and CSS. Glimpse of the Windows Loading Effect: Approach: Create an HTML file that contains HTML div in which we are giving the loader effect.Then we create 5 span elements which are used for creating inline elements.Then we have to use @keyfra
4 min read
How to create Image Folding Effect using HTML and CSS?
In this article, we are going to create an image folding effect below the main image. This is a simple project, we can achieve our target only by using HTML and CSS. Approach: Create the main div in which we are creating 4 list tags.Use of nth-child() selector property to give different styles to different list items. HTML Code: First, we create an
2 min read
Create a Reverse Scrolling Effect using HTML and CSS
Creating an attractive UI with a reverse scroll effect can be an engaging design. The Reverse Scrolling effect facilitates a unique and visually interactive experience for users, which breaks the conventional top-down scrolling system to which the user is accustomed. In this article, we'll create a basic reverse-scrolling effect on the webpage with
2 min read
How to create text-reveal effect using HTML and CSS ?
Text-reveal is a type of effect in which all the alphabets of the text are revealed one by one in some animated way. There are uncountable ways to animate text for this effect. It is up to your creativity how you want the text to reveal. We will look at a basic and easy way to get started. Table of Content Using keyframesUsing Clip-pathUsing keyfra
3 min read
How to create multilayered text effect using HTML and CSS?
Multilayered Text Effect is one of the most used text effects in the web design world. As a designer or front-end developer one should know how to create a Multilayered Text Effect. Today we will be looking at one of the simplest and easy methods to create Multiple Layers of Text effect. Approach: To achieve this Text effect, we will be using the t
3 min read
Create a Letter-Spacing Animation Effect using HTML and CSS
In this article, we are going to create a letter-spacing animation using CSS. Letter spacing is the available space between the letters in a particular word, we will walk through each step to achieve this animation effect for our web page. Approach: Initially, letter-spacing will be -15px.At 20%, letter-spacing will be 10px.Finally, at 100% letter-
2 min read
How to create Glowing Star effect using HTML and CSS?
The glowing star effect is one of the coolest effects that is used for dark themed websites. It is known as star effect because it has small glowing balls animated in different ways which looks like stars. This effect can be used for image slider, loader, and maybe as an showcase UI element. Approach: The approach is to create small balls using uno
3 min read
How to create Skewed Background with hover effect using HTML and CSS?
The skewed background or you can say an angel color shade background can be created by using HTML and CSS. This background can be used as a cover pic of your website that will be attractive. In this article, we will create a simple skewed background. We will divide the article into two sections in the first section we will create the structure and
2 min read
Create a 3D Text Effect using HTML and CSS
The 3D text effect is one of the most used text effects in the web design world. As a designer or front-end developer, one should know how to create a 3D text effect. Today we will be looking at one of the simplest and easiest methods to create text in a 3D look with HTML and CSS. ApproachCreate an HTML file and include a &lt;h1&gt; tag with your d
2 min read
How to Create Loading Blur Text Animation Effect using HTML and CSS ?
The blur text animation is known as the Smoky effect and it is used to give our text a blurry animation. The text blurs linearly in one direction and then reappears. Approach: The approach of this article is quite simple. We are animating the blur effect using the blur() function. Then we are using n-th child property to apply the animation delay.
3 min read
How to create shock wave or explosion effect using HTML and CSS ?
The shock wave effect is also known as the explosion effect. It is one of the simple CSS effects. For a beginner, it is one of the best examples to learn the concept of pseudo-elements. The pseudo-element that we are using is hover. I recommend you to go through it before jumping into the code to understand it better. For the briefing, hover is use
3 min read
How to create a Spotlight Effect using HTML and CSS ?
In this article, we are going to create a spotlight effect over the image when we hover over it. This is mainly based on HTML, CSS and JavaScript. The below steps have to be followed to create this effect. HTML Section: In this section, we will create a container elements for the background image and the mouse pointer. The CSS and JavaScript files
4 min read
How to set input box to be a floating number in ReactJS ?
When working with forms in ReactJS, you may encounter scenarios where you need to accept floating-point numbers as input from users. We will set an input box to accept floating numbers in ReactJS and handle the validation of the entered values. PrerequisitesReact JS NPM and Node.jsApproach If we want to set the input box to be a floating number the
2 min read
How to create Responsive Floating Elements using CSS ?
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
3 min read
How Create a Text Box Where User Can't Type Inside the Text Box ?
To create a text box where the user can't type inside the text box, we have different approaches. In this article, we are going to learn how to create a text box where the user can't type inside the text box in JavaScript. Below are the approaches to creating a text box where the user can't type inside the text box: Table of Content Using Readonly
3 min read
How to Create an Animated Search Box using HTML and CSS ?
The task is to create an Animated Search Box using HTML and CSS. The search bar is one of the most important components of the website. Basically, it is used for connecting people with websites. In the face of complicated web content, users express their needs by searching keywords, expecting to obtain accurate information and quick result. Approac
2 min read
How to create Popup Box using HTML, CSS and JavaScript ?
In this article, we will see how to create a pop-up box with the help of HTML, CSS, and JavaScript. Here we will create a Popup box that is functional through the Popup button, when is clicked the Popbox appears on the screen with the title and close button. PrerequisitesHTMLCSSJavaScriptApproachCreate the Popup structure using HTML tags, Some tags
3 min read
Create A Custom Select Menu with Search Box using HTML CSS and JavaScript
This article will show you how to create a custom select menu with a search box using HTML, CSS, and JavaScript. First, we create an option list for the select box, and we can search for text in the text input box. The search result displays the matched option value. Additionally, we have added a "clear" button to remove your latest search. Approac
5 min read