HTML CSS Exercise: Create columns with CSS3
Solution:
HTML Code :
<!doctype html><!-- Document type declaration -->
<html><!-- Opening HTML tag -->
<head><!-- Head section containing metadata -->
<title>HTML CSS Exercise - Create columns with css3</title><!-- Title of the HTML document -->
<style type="text/css"> /*Opening style tag for CSS with type attribute */
.container{ /* Style for container class */
width: 960px; /* Width of the container */
margin: 0 auto; /* Centering the container horizontally */
}
/* Creating columns: */
.container p{ /* Style for paragraphs inside container class */
-moz-columns:5; /* Number of columns for Mozilla Firefox */
-webkit-columns:5; /* Number of columns for WebKit browsers */
columns:5; /* Number of columns */
}
</style><!-- Closing style tag -->
</head><!-- Closing head tag -->
<body><!-- Body section of the HTML document -->
<div class="container"><!-- Container div -->
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius.</p><!-- Paragraph content -->
</div><!-- Closing container div -->
</body><!-- Closing body tag -->
</html><!-- Closing HTML tag -->
Explanation:
- The HTML structure consists of a container div with a paragraph inside.
- CSS is used to style the container and create multiple columns for the paragraph text.
- .container class sets the width of the container and centers it horizontally.
- .container p class applies column formatting to the paragraphs inside the container.
- Vendor prefixes are used to ensure browser compatibility for the column property.
- The paragraph text will be split into five columns across modern browsers.
Live Demo :
See the Pen create-css3-columns-answer by w3resource (@w3resource) on CodePen.
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/html-css-exercise/create-css3-columns-answer.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics