`
leonzhx
  • 浏览: 786709 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Zz CSS Block vs Inline CSS Display Styles

    博客分类:
  • Web
 
阅读更多

The original articles are here : http://www.webdesignfromscratch.com/html-css/css-block-and-inline/

 

HTML elements can be displayed either in block or inline style.

The difference between these is one of the most basic things you need to know in order to use CSS effectively.

If you’d like to master CSS, here are the books I’d recommend!

The 3 ways that HTML elements can be displayed

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

分享到:
评论

相关推荐

    base zz zz zz zz

    base zz zz zz zz zz base zz zz zz zz zz base zz zz zz zz zz base zz zz zz zz zz

    CSS3 API中文版帮助文档CHM

    **CSS3 API中文版帮助文档CHM**是一个非常实用的资源,它包含了关于CSS3(层叠样式表第三版)的API详细信息,适合开发者在没有网络连接的情况下查阅。这个CHM(Compiled Help Manual)文件是一种Windows平台上的离线...

    jquery-ui.css、jquery-ui.js下载

    在本文中,我们将详细探讨`jquery-ui.css`和`jquery-ui.js`这两个关键文件,并讨论如何在项目中有效地使用它们。 首先,`jquery-ui.css`是jQuery UI的核心样式文件,它包含了所有组件的默认样式和主题。这个文件...

    Html+div+CSS布局

    资源中包含html+CSS+div的布局练习,其中包括固定布局、流式布局、浮动布局、定位布局等布局方式的练习Demo,另外还对CSS中的一些特殊的属性进行了练习,包括position、float、display等属性,对每一个属性和布局的...

    mui的js和css资源

    1. **CSS样式库**:MUI的CSS部分提供了丰富的预定义样式,包括各种UI组件如按钮、表单、导航、滑块、对话框等,使得开发者可以快速搭建界面。这些样式遵循一致的设计语言,确保了应用的视觉一致性。 2. **...

    使用postcss-px2rem插件把px转变为rem,并配合给html根元素设置fontsize,来实现页面的自适应效果

    PostCSS是一个工具,它可以解析、修改、然后生成CSS,允许开发者使用未来CSS语法,或者像`px2rem`这样的自定义转换。在项目中安装`postcss-px2rem`后,只需配置相应的转换规则,如转换阈值、保留的小数位数等,即可...

    如何用css实现动画效果.md

    如何用css实现动画效果 简单的描述了动画的一些属性,以及如何用css实现简单的动画效果 介绍了创建动画所需要的关键帧@keyframes 规则(关键帧),以及其详细的属性介绍和用法,并对动画的多种属性进行了介绍,并指明了其...

    纯CSS3动画打造的菜单

    在前端开发领域,CSS3是不可或缺的一部分,它极大地丰富了网页的视觉效果和用户体验。"纯CSS3动画打造的菜单"这一主题,旨在探讨如何利用CSS3的强大特性,设计出富有动态感和交互性的菜单,尤其在移动端的应用,能够...

    ZZ561401.CAB

    ZZ561401.CAB ZZ561401.CAB ZZ561401.CAB

    js特效脚本含源码和说明jQuery&CSS图形下拉菜单

    在JavaScript和Web开发领域,jQuery和CSS经常被用于创建交互式和吸引人的用户界面,其中下拉菜单是一种常见的设计元素。这个"js特效脚本含源码和说明jQuery&CSS图形下拉菜单"的资源提供了实现这一功能的具体方法。...

    wincc AX NF ZZ

    wincc SIMATIC WinCC是第一个使用最新的32位技术的过程监视系统,具有良好的开放性和灵活性。 从面市伊始,用户就对SIMATIC WinCC印象深刻。

    [浓缩精华]CSS开发人员必备的参考手册之三

    ### CSS开发人员必备的参考手册之三 #### 概述 在CSS开发过程中,了解并掌握各种属性的应用是至关重要的。本手册旨在为CSS开发者提供一份实用、全面且易于理解的手册,帮助开发者更好地理解和应用CSS中的关键概念...

    易生菌2.0.zip

    2. zz460.css、stylezz1.css:同样,"zz"和"stylezz1"可能是项目或模块的内部命名约定,它们可能包含了特定功能或元素的样式规则。 3. 2.6.0.css:这个文件名暗示了一个版本号,可能代表这是一个升级到2.6.0版本的...

    zz_layer.rar

    支多层缩写(1-3代表1,2,3层),实现类似PADS的z命令的快速显示多层效果。zz_layer.il是源代码,install.bat是安装的 使用举例:zz 1-3 4 126 127 层号定义,与PADS类似:1~120是etch ...Display 125(top) 124(bot)

    zz809.com留言本

    《zz809.com留言本》是一款基于网络的互动交流平台,源于柏图留言本BTB 1.2版本,并经过管理员zz809的定制和优化。这个平台旨在为用户提供一个简便、实用的在线留言功能,使得用户可以方便地在网站上发表评论、交流...

    超出NLO QCD的高横向动量的ZZ产生

    我们研究了四轻子最终状态ℓ+ℓ-ℓ+ℓ-的产生,这些状态主要由一对弱电Z玻色子ZZ产生。 使用LoopSim方法,我们合并ZZ和ZZ + jet的NLO QCD结果,并获得ZZ产生的近似NNLO预测。 还包括对ZZ过程的精确胶子融合环平方的...

    zz CAD快速计算长度插件

    在CAD中想要快速测量长度,在CAD工具栏找到加载应用程序,再点击加载 加载成功后在输入栏输入“zz”(不分大小写)在选择你需要测量的线段即可。

    Zz归零.LSP

    cad标高归零,好用的

    ZZ_MODIFIED_GEEBINF.ENS.zip endnote的样式文件

    标题中的“ZZ_MODIFIED_GEEBINF.ENS.zip”是一个压缩包文件,主要包含一个名为“ZZ_MODIFIED_GEEBINF.ENS”的文件。这个文件是一种特殊格式,用于定义EndNote的引用样式。EndNote是一款强大的文献管理软件,广泛应用...

    中医大夫助理信息系统 zz-doctor

    《中医大夫助理信息系统 zz-doctor 深度解析》 中医大夫助理信息系统“zz-doctor”是一款基于Android平台的应用程序,旨在为中医医生提供智能化、便捷化的诊疗辅助工具。通过深入剖析这款应用的源码,我们可以了解...

Global site tag (gtag.js) - Google Analytics