`

The 3 ways that HTML elements can be displayed

    博客分类:
  • css
阅读更多

All HTML elements are naturally displayed in one of the following ways:

Block
Takes up the full width available, with a new line before and after (display:block; )
Inline
Takes up only as much width as it needs, and does not force new lines (display:inline; )
Not displayed
Some tags, like <meta /> and <style> are not visible (display:none; )

Block example

<p> tags and <div> tags are naturally displayed block-style.

(I say "naturally" because you can override the display style by setting the CSS display property e.g. display:inline; .)

A block-display element will span the full width of the space available to it, and so will start on a new line in the flow of HTML. The flow will continue on a new line after the block-display element.

Here I've started a paragraph and now I'm going to insert a <div>

new div inside my paragraph

and then continue the text here...

 

See how the <div> jumped in and took over the full width of the space?

Common HTML elements that are naturally block-display include:

<div>
Your general-purpose box
<h1> ... <h6>
All headings
<p>
Paragraph
<ul>, <ol>, <dl>
Lists (unordered, ordered and definition)
<li>, <dt>, <dd>
List items, definition list terms, and definition list definitions
<table>
Tables
<blockquote>
Like an indented paragraph, meant for quoting passages of text
<pre>
Indicates a block of preformatted code
<form>
An input form

Inline example

Inline-display elements don't break the flow. They just fit in with the flow of the document.

So here I've got a paragraph going on, and I'm going to add a <span> tag that has a yellow background and italic text . See how it just fits right in with the flow of the text?

More elements are naturally inline-style, including:

<span>
Your all-purpose inline element
<a>
Anchor, used for links (and also to mark specific targets on a page for direct linking)
<strong>
Used to make your content strong, displayed as bold in most browsers, replaces the narrower <b> (bold) tag
<em>
Adds emphasis, but less strong than <strong>. Usually displayed as italic text, and replaces the old <i> (italic) tag
<img />
Image
<br>
The line-break is an odd case, as it's an inline element that forces a new line. However, as the text carries on on the next line, it's not a block-level element.
<input>
Form input fields like and
<abbr>
Indicates an abbr. (hover to see how it works)
<acronym>
Working much like the abbreviation, but used for things like this TLA .

You change the display property of any elements

Although each HTML element has its natural display style, you can over-ride these in CSS.

This can be very useful when you want your page to look a particular way while using semantically-correct HTML.

Examples

Say you want to provide a list of items, but you don't want a big bulleted list. You just want to say that you're going to the store to buy:

  • some fizzy drinks,
  • a chainsaw,
  • and some nylon stockings.

 

Or maybe you want a nice toolbar, which is stricly a list (of links) and so should be marked up as a <ul> .

Here's the code

 
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">FAQs</a></li>
<li><a href="#">Contact us</a></li>
</ul>
 

Here's how it looks as a normal list

Just adding the class "toolbar"...

 
<style type="text/css">
.toolbar li {
display:inline;
background-color:#eee;
border:1px solid;
border-color:#f3f3f3 #bbb #bbb #f3f3f3;
margin:0;
padding:.5em;
zoom: 1;
}
</style>

<ul class="toolbar">
<li><a href="#">Home</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">FAQs</a></li>
<li><a href="#">Contact us</a></li>
</ul>
 

Here's how it looks with the CSS styles applied

分享到:
评论

相关推荐

    ILI9341-single-chip

    ILI9341 is a 262,144-color single-chip SOC driver for a-... The specified window area can be updated selectively, so that moving picture can be displayed simultaneously independent of still picture area.

    CListViewEx

    • The background of the sorted column can be displayed in a different color (like the detailed view of Windows XP Explorer). • The header of the sorted column can display an arrow that indicates ...

    CANopen 、DeviceNet Master Simulator

    The CANopen Master Simulator is an easy to use software for data exchange with CANopen ... Input data can be read, output data can be written and the status of the DeviceNet Dongle can be displayed.

    3DVIA Composer V6R2014

    The results can be saved in native format 3DVia Composer automatically added along with a free viewer or exported to a common standard data formats such as PDF, HTML, AVI and SVG. 3DVia Composer - ...

    微软内部资料-SQL性能优化5

    Keeping your clustered key value small increases the number of index rows that can be placed on an index page and decreases the number of levels that must be traversed. This minimizes I/O. As we’ll ...

    ActiveDocument

    If the application is executed without the "/embedding" switch, a dialog box will be displayed that has options for registering the server and creating a working file. When Register Server is selected...

    Android图表--achartengine

    All the above supported chart types can contain multiple series can be displayed with the X axis horizontally default or vertically and support many other custom features The charts can be built as a ...

    lpc900_pwm

    LPC932 EXAMPLE: CREATING A PWM SIGNAL USING A TIMER IN MODE 6 by Christian Kulig, Philips Semiconductor 12/06/...connected to any of the LEDs, nevertheless the PWM can be displayed with a oscilloscope.

    C 语言编缉神经网络工具

    can't be solved any other way known to the authors. THE BACK-PROPAGATION NNT: BATCHNET This release contains both source and executable code for a "standard" three layer back-propagation neural ...

    iphone h.264 live encode 实时 硬编码

    Transition code must then wait for the old instance to be closed so that the remaining NALUs can be read from the mdat atom without reading past the end of that atom into the subsequent metadata....

    Java邮件开发Fundamentals of the JavaMail API

    If you're viewing this document online, you can click any of the topics below to link directly to that section. 1. Tutorial tips 2 2. Introducing the JavaMail API 3 3. Reviewing related ...

    HANA FAQ (frequently asked question)

    38. Are there any special SAP HANA options that can be purchased on top of the standard SAP HANA edition? 39. Where can I find central information about SAP HANA host and service startups and ...

    Rapid Development - Taming Wild Software Schedules - Part1

    The author says that software can be optimized for any of several goals: lowest defect rate, lowest cost, or shortest development, etc... Software Engineering is then about achieving tradeoffs, and ...

    DBGridPro new

    DBGridPro features list RAD-Studio technologies support TDBGridPro is one of the basic components ... Ultimately, the Designer guarantees that you can build an UI that reflects the appearance you need.

    HTML5.and.CSS3.Building.Responsive.Websites.pdf

    Make responsive media that is optimized for the specific device on which it's displayed, allowing images, videos, and other elements be fully appreciated Make typography that's fluidly responsive, so ...

    Rapid Development - Part3

    The author says that software can be optimized for any of several goals: lowest defect rate, lowest cost, or shortest development, etc... Software Engineering is then about achieving tradeoffs, and ...

    Android代码-Tickmate

    You are able to quantify your habits and the accumulated data can be displayed for the past weeks or months to track changes over time. This way, it may help you to get over your old habits or embody...

Global site tag (gtag.js) - Google Analytics