Understanding Block-Level Elements

Description

block value creates a block-level element, whick creates a new line before and after the element,

Example

The p element, which marks a paragraph, includes the block value for the display property in its default style convention, but you may apply this value to any element.


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
p {<!--   ww  w  . j a  v  a  2s . c o m-->
  border: medium solid black
}

span {
  display: block;
  border: medium double black;
  margin: 2px;
}
</style>
</head>
<body>
  <p>This is a test.</p>
  <p>This is a test.
    <span>This is a test</span>.
    This is a test.
  </p>
</body>
</html>

Click to view the demo

A span element which is by default an inline element and can also have block style.

Example 2

You can see the different between the block and inline element in the following code.


<html>
<body>
  <h1>Block-Level Elements</h1>
  <p>
    <strong>Block-level elements</strong> start on a new line. The
    <code>&lt;h1&gt;</code>
    and<!--from  w w  w  .j a  va2s  .  co m-->
    <code>&lt;p&gt;</code>
    elements will not sit on the same line.
  </p>

  <p>The inline elements flow with the rest of the text.</p>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table