How to divide text into two column layout using HTML and CSS?


In HTML, we have division element that can be used to create a column partition section on the webpage. To fill the text inside the div box it has used the paragraph element. Then styling the properties of HTML elements by using internal CSS. This type of example is used to display the differentiation question and when it has been designed through code for a better look.

Syntax

The following syntax is used in the example −

<div></div>

The div element specifies a division or section in the HTML page.

<p>…..write some text….</p>

The p element defines the paragraph where the user can write some text on it.

Properties Used

The following properties are used in the example −

  • margin − This property defines the margin of an element.

  • padding − This property is used for defining the space between the border and its content.

  • width − We can define the width of the div element using this property.

  • float − This property defines the left or right position of the div element.

  • background-color − Define the background color of the element.

  • color − Define the color of the text.

  • font-weight − Define the bold styling of the text.

  • text-align − This property sets the horizontal alignment of the text.

  • border-radius − Define the radius of the border corner.

Example

In this example, we will create two division elements that represent the layout of two columns. Then fill the text in both columns by using paragraph elements. To design the webpage of two column layout we will use internal CSS to sets the properties of all the elements.

<!DOCTYPE html>
<html>
<head>
   <title>Two column layout using HTML and CSS</title>
   <style>
      #container{
      width: 450px; }
      .col-1{
      width: 200px; float: left; color: green; font-weight: bold;
      text-align: center; margin: 10px; border-radius: 20px; background: yellow; }
      .col-2{
      width: 200px; float: right; color: green; font-weight: bold;
      text-align: center; margin: 10px; border-radius: 20px; background: orange; }	
      p{ font-size: 20px; }
   </style>
</head>
<body>
   <h1> Two Column Layout Using CSS </h1>
   <div id = "container">
      <div class = "col-1">
         <h1 class = "heading">COLUMN 1</h1>
         <p class = "paragraph">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
      </div>
      <div class =  "col-2">
         <h1 class = "heading">COLUMN 2</h1>
         <p class="paragraph">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
      </div>
   </div>
</body>
</html>

Conclusion

The above output represents the two columns layout using the division element and the use of paragraph element to fill the text into it. To set all the properties of HTML elements it has used internal CSS. This type of code is normally used to build the design of differentiation-based questions or a comparison based on two different things.

Updated on: 08-Jun-2023

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements