This article will show you how you can use style sheet to make a div box align to left side of each other. In this article i have used css style sheet to align the div at the left of each other. So for this we add some div controls in the page.
- <div>Div Control 1</div>
- <div>Div Control 2</div>
- <div>Div Control 3</div>
- <div>Div Control 4</div>
- <br style="clear: left;" />
- <div>Div Control 5</div>
- <div>Div Control 6</div>
- <div>Div Control 7</div>
- <div>Div Control 8</div>
Now use the below css style sheet in the header of the page.
- .floatleft_div
- {
- float: left;
- width: 100px;
- height: 100px;
- background-color: green;
- text-align: center;
- border: 2px solid black;
- }
The above css style sheet used float left for making div control move to left of each other. In this width and height is used for make the div control look like a box.
Now assign the style to the div control.
- <div class="floatleft_div">Div Control 1</div>
- <div class="floatleft_div">Div Control 2</div>
- <div class="floatleft_div">Div Control 3</div>
- <div class="floatleft_div">Div Control 4</div>
- <br style="clear: left;" />
- <div class="floatleft_div">Div Control 5</div>
- <div class="floatleft_div">Div Control 6</div>
- <div class="floatleft_div">Div Control 7</div>
- <div class="floatleft_div">Div Control 8</div>
In above html tag i have assign the class to all the div controls. Check below the complete code of the page.
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication7.Csharpcorner.WebForm1" %>
-
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Flot Div Control Side By Side Using Css or Style Sheet in Asp.net</title>
- <style>
- .floatleft_div
- {
- float: left;
- width: 100px;
- height: 100px;
- background-color: green;
- text-align: center;
- border: 2px solid black;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div class="floatleft_div">Div Control 1</div>
- <div class="floatleft_div">Div Control 2</div>
- <div class="floatleft_div">Div Control 3</div>
- <div class="floatleft_div">Div Control 4</div>
- <br style="clear: left;" />
- <div class="floatleft_div">Div Control 5</div>
- <div class="floatleft_div">Div Control 6</div>
- <div class="floatleft_div">Div Control 7</div>
- <div class="floatleft_div">Div Control 8</div>
- </form>
- </body>
- </html>
In above
<br style="clear: left;" /> is used to make the div appear in new line of the page. Now run the page to check the output.