Home > Web Front-end > HTML Tutorial > Create Indian flag using HTML and CSS

Create Indian flag using HTML and CSS

WBOY
Release: 2023-08-28 10:25:03
forward
1093 people have browsed it

Create Indian flag using HTML and CSS

We know HTML and CSS are languages ​​used for the web and design, but we can do much more than just make web apps. For example, we can also use them to make an interesting project, which will require a deep knowledge of both languages.

So, our task at hand is to create the Indian flag using HTML and CSS. No matter what type of flag we want to create, there will be two parts: the first is the flagpole, and the second is the flag itself. As we know, it's actually pretty simple for us to add color to a rectangular DIV and make the tri-color part of the flag, the tricky part will be making the wheels.

So the approach is to use a container element to hold the entire logo. This will be in two parts: a pole and flag. The logo section will contain three elements, each representing their respective color from top to bottom. The middle element among these three elements will act as the container element for the wheel.

Let's move on to creating the logo.

External container

As we discussed, the outer container will hold the entire flag (flag and pole portion). We will use a div tag and give it a "container" class. There will be two divs nested within this div tag, one for the pole and one for the flag.

The problem now is that we want both div elements to be inline, so we will use the display:flex attribute to achieve this. After that, we will specify the width, height, and color of the element.

The html part of the code looks like -

<div class="container">
   <div class="polePart"></div>
   <div class="flagPart"></div>
</div>
Copy after login
The

CSS part will be -

.container {
   display: flex;
}
.polePart {
   height: 800px;
   width: 11.111px;
   background: brown;
   border-top-left-radius: 12px;
}
.flagPart {
   width: 450px;
   height: 300px;
   box-shadow: 0px 0px 90px 1px rgb(129, 115, 129);
   background-color: transparent;
   position: relative;
}
Copy after login

Add three colors

Now we will start adding the three colors of the tricolor. To do this we will use three nested divs inside the flagPart. We will then first give them the appropriate width and height, all equal to each other, and then assign them their respective background colors. The first div has a saffron background color, the middle div has a white background color, and the bottom div has a green background color.

HTML part

<body>
   <div class="topColor"></div>
   <div class="middleColor"></div>
   <div class="bottomColor"></div>
</body>
Copy after login

CSS part

.topColor {
   height: 100px;
   background-color: #ff9933
}
.middleColor {
   height: 100px;
   background-color: white
}
.bottomColor {
   height: 100px;
   background-color: green
}
Copy after login

Note that we don't need to specify the width of the inner divs because we want them to extend to the size of the parent div, which is the div with the middleColor class.

Add wheels

Now we will add the wheel in the middle section, we know there are 24 spokes in the wheel, that's why we will use 12 lines and angle them using CSS so that they form a circle.

Please note that this will only form spokes, for the circular part of the wheel we will use the "border-radius" property of the wheel container.

HTML part −

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Document</title>
</head>
<body>
   <div class="wheelPart">
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
      <span class="spokeLine"></span>
   </div>
</body>
</html>
Copy after login

CSS part −

.wheelPart {
   height: 99px;
   width: 99px;
   border: 1px solid darkblue;
   border
   -radius: 100px;
   position: relative;
   margin: 0 auto
}
.wheelPart .spokeLine {
   height: 100%;
   width: 1px;
   display: inline
   -block;
   position: absolute;
   left: 50%;
   background: darkblue;
}
.spokeLine:nth
-child(1) {
   transform: rotate(15deg)
}
.spokeLine:nth
-child(2) {
   transform: rotate(30deg)
}
.spokeLine:nth
-child(3) {
   transform: rotate(45deg)
}
.spokeLine:nth
-child(4) {
   transform: rotate(60deg)
}
.spokeLine:nth
-child(5) {
   transform: rotate(75deg)
}
.spokeLine:nth
-child(6) {
   transform: rotate(90deg)
}
.spokeLine:nth-child(7) {
   transform: rotate(105deg)
}
.spokeLine:nth-child(8) {
   transform: rotate(120deg)
}
.spokeLine:nth-child(9) {
   transform: rotate(135deg)
}
.spokeLine:nth-child(10) {
   transform: rotate(150deg)
}
.spokeLine:nth-child(11) {
   transform: rotate(165deg)
}
.spokeLine:nth-child(12) {
   transform: rotate(180deg)
}
Copy after login

We used the nth-child pseudo-class to rotate each row 15 degrees, because 12 rows rotated 15 degrees from the center will form 24 spokes. The nth child pseudo-class is used to match the number of child elements of a container specified in curly braces.

All we have created is a simple flag, but with advanced knowledge of CSS we can do much more. Using animation, we can make the flag look like it's flapping in the wind or moving on wheels, but we won't go into that in this article.

Example

The following is a complete working example of the above -

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Document</title>
   <style>
      .container {
         display: flex;
      }
      .polePart {
         height: 800px;
         width: 11.111px;
         background: brown;
         border-top-left-radius: 12px;
      }
      .flagPart {
         width: 450px;
         height: 300px;
         box-shadow: 0px 0px 90px 1px rgb(129, 115, 129);
         background-color: transparent;
         position: relative;
      }
      .topColor {
         height: 100px;
         background-color: #ff9933
      }
      .middleColor {
         height: 100px;
         background-color: white
      }
      .bottomColor {
         height: 100px;
         background-color: green
      }
      .wheelPart {
         height: 99px;
         width: 99px;
         border: 1px solid darkblue;
         border-radius: 100px;
         position: relative;
         margin: 0 auto;
      }
      .wheelPart .spokeLine {
         height: 100%;
         width: 1px;
         display: inline-block;
         position: absolute;
         left: 50%;
         background: darkblue;
      }
      .spokeLine:nth
      -child(1) {
         transform: rotate(15deg)
      }
      .spokeLine:nth
      -child(2) {
         transform: rotate(30deg)
      }
      .spokeLine:nth
      -child(3) {
         transform: rotate(45deg)
      }
      .spokeLine:nth
      -child(4) {
          transform: rotate(60deg)
      }
      .spokeLine:nth
      -child(5) {
         transform: rotate(75deg)
      }
      .spokeLine:nth
      -child(6) {
         transform: rotate(90deg)
      }
      .spokeLine:nth
      -child(7) {
         transform: rotate(105deg)
      }
     .spokeLine:nth
      -child(8) {
         transform: rotate(120deg)
      }
      .spokeLine:nth
      -child(9) {
         transform: rotate(135deg)
      }
      .spokeLine:nth-child(10) {
         transform: rotate(150deg)
      }
      .spokeLine:nth-child(11) {
         transform: rotate(165deg)
      }
      .spokeLine:nth-child(12) {
         transform: rotate(180deg)
      }
   </style>
</head>
<body>
   <div class="container">
      <div class="polePart"></div>
         <div class="flagPart">
         <div class="topColor"></div>
         <div class="middleColor">
            <div class="wheelPart">
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
               <span class="spokeLine"></span>
            </div>
         </div>
         <div class="bottomColor"></div>
      </div>
   </div>
</body>
</html>
Copy after login

in conclusion

In this article, we saw how to create the Indian flag, the tricolor, using HTML and CSS. We saw that we can use properties in CSS such as background-color, border, border-radius, transform, etc. to create a beautiful flag.

The above is the detailed content of Create Indian flag using HTML and CSS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template