Creating HTML blocks using DIV tag

<div></div> tag is a powerful element in HTML. It helps in organizing HTML code in different blocks. We can hide/unhide blocks using javascript or php. We can also overwrite the contents of <div> tag using javascript by setting innerHTML property of div.

div tags are also useful for setting the layout of html document. We can have either fixed or liquid (responsive layout) by setting various style properties of div tag.

In the following simple example, <div> tag is used to display two blocks of text on web page.

<body>

<div>
BLOCK1: Near the beginning of his career, Einstein thought that Newtonian mechanics was no longer enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field. This led him to develop his special theory of relativity. He realized, however, that the principle of relativity could also be extended to gravitational fields, and with his subsequent theory of gravitation in 1916, he published a paper on general relativity. He continued to deal with problems of statistical mechanics and quantum theory, which led to his explanations of particle theory and the motion of molecules. He also investigated the thermal properties of light which laid the foundation of the photon theory of light. In 1917, Einstein applied the general theory of relativity to model the large-scale structure of the universe
</div>


<div>
BLOCK2: Near the beginning of his career, Einstein thought that Newtonian mechanics was no longer enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field. This led him to develop his special theory of relativity. He realized, however, that the principle of relativity could also be extended to gravitational fields, and with his subsequent theory of gravitation in 1916, he published a paper on general relativity. He continued to deal with problems of statistical mechanics and quantum theory, which led to his explanations of particle theory and the motion of molecules. He also investigated the thermal properties of light which laid the foundation of the photon theory of light. In 1917, Einstein applied the general theory of relativity to model the large-scale structure of the universe
</div>

</body>

 

Add a Comment

Your email address will not be published. Required fields are marked *