How to create Skewed Background with hover effect using HTML and CSS?
Last Updated :
29 Jul, 2024
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 in the second section, we decorate the structure.
Creating structure:
In this section, we will create the structure by using only simple HTML codes.
HTML Code: By using the HTML <section> tag we will create the section for our skewed background which will have a HTML <div> tag inside of it.
HTML
<!DOCTYPE html>
<html>
<head>
<meta>
<title>
Skewed Background using HTML and CSS
</title>
</head>
<body>
<section>
<div class="content">
<h2>GeeksforGeeks</h2>
</div>
</section>
</body>
</html>
Designing structure:
In this section we will decorate the pre-created structure with the help of CSS.
CSS Code: In this section first we will use some CSS properties to design the background and then we will use the skew property of the CSS which skews an element along the x and Y axis by the given angles.
CSS
<style>
body {
margin: 0;
padding: 0;
font-family: serif;
}
section:hover {
background: linear-gradient( green , yellow);
}
section {
display: flex;
background: green;
height: 350px;
justify-content: center;
align-items: center;
transform: skew(0deg, -10deg) translateY(-120px);
}
.content {
margin: 0;
padding: 0;
position: relative;
max-width: 900px;
transform: skew(0deg, 10deg);
text-align: center;
}
.content h2 {
color: #fff;
font-size: 80px;
}
</style>
Final Code:
It is the combination of the above two code sections by combining the above two sections we can achieve the skewed background.
Program:
HTML
<!DOCTYPE html>
<html>
<head>
<meta>
<title>
Skewed Background using HTML and CSS
</title>
</head>
<style>
body {
margin: 0;
padding: 0;
font-family: serif;
}
section:hover {
background-image: linear-gradient(to left, green , yellow);
transition-time: 5s;
}
section {
display: flex;
background: green;
height: 350px;
justify-content: center;
align-items: center;
transform: skew(0deg, -10deg) translateY(-120px);
}
.content {
margin: 0;
padding: 0;
position: relative;
max-width: 900px;
transform: skew(0deg, 10deg);
text-align: center;
}
.content h2 {
color: #fff;
font-size: 80px;
}
</style>
<body>
<section>
<div class="content">
<h2>GeeksforGeeks</h2>
</div>
</section>
</body>
</html>
Output:
Similar Reads
How to create a skewed background using CSS ? A skewed background design enhances a website's visual appeal with dynamic, angled elements. By using CSS transform: skew() along with ::before and ::after pseudo-elements, you can easily create a slanted effect, adding a modern and engaging look to your site's layout.ApproachHTML Structure - Sectio
2 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
3 min read
How to Create a Sliding Background Effect Using CSS ? A sliding background effect in CSS creates a smooth, continuous movement of a webpageâs background image, typically in a horizontal or vertical direction. It gives a dynamic, animated feel by using properties like background-position and animation, enhancing visual engagement without additional Java
2 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
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
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
4 min read