HTML Element Categories(html元素分类)

本文详细介绍了HTML中的不同类型的元素,包括块级元素、内联元素和列表项元素,并解释了它们的特点及使用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

It is important to be aware, when using HTML and style sheets that HTML elements are categorized into several categories. Some style properties apply to some categories of elements and not to others. The following types of elements exist:

  • Block - Include a line break before and after the element.
  • Inline - Included with the text as part of a line.
  • List Item - Elements that support providing a list of items. List item elements are block level elements.

Block HTML Elements

A block with centered contents is defined
NameDescriptionComment
ADDRESSSupplies contact information for the document-
BLOCKQUOTEUsed to quote in block form-
CENTERDepreciated-
DIVA container allowing specific style to be added to a block of text.-
DIRA container allowing specific style to be added to a block of text.-
FRAMESETA container allowing multiple frames (HTML documents) to be placed on a web browser.-
H1, H2, H3, H4, H5, H6Headings-
HRHorizontal rule-
ISINDEXAn input prompt for a single line of textDepreciated
NOFRAMESAlternate content for browsers that do not support frames.-
NOSCRIPTAlternate content for browsers that cannot run script programs-
PParagraph - Should not contain other block elements including tables, but may contain list elements-
PREPreformatted text is rendered with spaces and carriage returns as typed.-
TABLEUsed to present an ordered set of data. Table subelements work as block elements.Includes table sub elements
FORMUsed to present a form to the client. Form subelements work as block elements.-

List item elements are also considered to be block elements.


List-item Elements

NameDescriptionComment
DIRDirectory ListDepreciated
DLDefinition List-
LIList Item-
OLOrdered (numbered) List-
ULUnordered List-


Block/Inline HTML Elements

The elements in this list may be considered block or inline elements, depending on how they are used. They are considered inline elements if used inside a paragraph (P) or another inline element.

-
NameDescriptionPurposeComment
APPLETFor placing Java applets in the page.-(Depreciated)
BUTTONUsed to define a FORM submit, reset, or push button.--
DELUsed to indicate deleted contentPhraseBoth a block and inline element
IFRAMEInline frame-(Depreciated)
INSMarks inserted contentPhraseBoth a block and inline element
MAPEstablishes an image map to be used with an IMG or OBJECT element--
OBJECTUsed to include applets, images, videos and sound on the web page.--
SCRIPTDefines a script to be run on the client computer.--

Inline HTML Elements

NameDescriptionPurposeComment
AAnchor--
ABBRDenotes an abbreviationPhrase-
ACRONYMDenotes an acronym.--
AREADefine a map region in an image.Inside the MAP element-
BBoldFont-
BASEFONTAllows font changes-Depreciated
BDOOverrides text direction with values of ltr (left to right) or rtl (right to left).--
BIGSets size of text to bigFont-
BRBreakTreated special by style sheets.-
CITEUsed to mark titles of articles or other publications.Phrase-
CODEDenotes computer program code.Phrase-
DFNDenotes a definition.Phrase-
EMDenotes emphasisPhrase-
FONTAllows font changes.-(Depreciated)
ISets text to italicsFont-
IMGAllows placement of a graphical image in the page.--
INSDenotes inserted text.Phrase-
KBDDenotes information typed from the keyboard.Phrase-
PARAMUsed to add additional parameters to the object or applet elements.--
QUsed for short quotations--
SStrike through textFontDepreciated
SAMPDenotes a sample.Phrase-
SMALLSets text size to smallFont-
SPANA container used to set special style to specific areas of the page.--
STRIKESets text to have a line struck through itFont-
STRONGDenotesPhrase-
SUBSubscript--
SUPSuperscript--
TEXTAREAA form for multiline text input.--
TTSets text style to monospaced teletypeFont-
USets text underlinedFontDepreciated
VARDenotes a variablein a program.Phrase-
<think>我们正在讨论的是使用HTML+CSS+JavaScript构建在线商城网站的方法和示例。根据用户的需求,他们想了解如何创建这样的商城网站,并希望得到方法或示例。参考引用[1]中提到了一个基于HTML+CSS+JavaScript的OPPO手机商城示例(6页),这是一个典型的课程大作业或毕业设计项目。考虑到用户可能需要一个简单的指导,我将介绍一个基本的构建步骤,并提供一个简单的示例代码结构。由于我们无法展示整个6页的商城,但可以给出一个简化的单页示例,包括常见的商城元素(如商品展示、购物车等)。###步骤概述:1.**规划页面结构**:通常包括页眉(导航栏、搜索框)、商品展示区、页脚等。2.**使用HTML构建页面骨架**:定义各个区块。3.**使用CSS美化页面**:布局、颜色、字体等样式设计。4.**使用JavaScript添加交互功能**:如购物车操作、动态内容加载等。###示例代码(一个简单的商品列表页):以下是一个简单的商品展示页面的代码,包括商品卡片和基本的样式。####HTML部分(index.html)```html<!DOCTYPEhtml><htmllang="zh-CN"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>手机商城</title><linkrel="stylesheet"href="style.css"></head><body><!--导航栏--><nav><divclass="logo">手机商城</div><divclass="cart">购物车(<spanid="cart-count">0</span>)</div></nav><!--商品展示--><divclass="products"><divclass="product-card"><imgsrc="phone1.jpg"alt="手机1"><h3>手机型号1</h3><p>¥2999</p><buttononclick="addToCart('手机型号1')">加入购物车</button></div><divclass="product-card"><imgsrc="phone2.jpg"alt="手机2"><h3>手机型号2</h3><p>¥3999</p><buttononclick="addToCart('手机型号2')">加入购物车</button></div><!--更多商品卡片--></div><scriptsrc="script.js"></script></body></html>```####CSS部分(style.css)```cssbody{font-family:Arial,sans-serif;margin:0;padding:0;background-color:#f4f4f4;}nav{display:flex;justify-content:space-between;background-color:#333;color:white;padding:10px20px;}nav.logo{font-size:24px;}nav.cart{cursor:pointer;}.products{display:flex;flex-wrap:wrap;justify-content:center;padding:20px;}.product-card{background-color:white;border:1pxsolid#ddd;border-radius:5px;padding:15px;margin:10px;width:200px;text-align:center;}.product-cardimg{max-width:100%;height:auto;}button{background-color:#007bff;color:white;border:none;padding:8px15px;border-radius:3px;cursor:pointer;}button:hover{background-color:#0056b3;}```####JavaScript部分(script.js)```javascriptletcartCount=0;functionaddToCart(productName){cartCount++;document.getElementById('cart-count').textContent=cartCount;alert(`已将${productName}加入购物车!`);}```###说明:-这个示例包含了商城的核心元素:商品展示和购物车功能。-商品以卡片形式展示,包含图片、名称、价格和加入购物车按钮。-点击加入购物车按钮,购物车数量会增加,并弹出提示。###扩展建议:1.**多页面设计**:可以增加商品详情页、购物车页面、结算页面等。2.**后端交互**:如果需要存储商品信息和订单,可以使用后端语言(如PHP、Node.js)和数据库。3.**响应式布局**:使用媒体查询(MediaQuery)适配不同设备屏幕。希望这个简单的示例能帮助用户快速入门。在实际项目中,可能需要更复杂的设计和功能。[^1]:参考自HTML+CSS+JavaScript制作的OPPO手机商城课程设计。###相关问题1.如何实现一个响应式的商品展示网格布局?2.如何用JavaScript实现购物车的完整功能(包括添加、删除、修改数量)?3.如何将商城网站与后端进行数据交互(如商品数据、订单提交)?</think> ### 使用HTML创建商城网站的方法与示例 要创建HTML商城网站,需要**综合运用HTML+CSS+JavaScript**实现页面结构、样式设计和交互功能。以下是核心方法和示例: --- ### 🛠️ 一、基础商城网站开发流程 1. **规划设计** - 确定商城类型(综合/垂直)和核心页面(首页、商品列表、详情页、购物车、结算页) - 参考流程图: $$ \text{首页} \rightarrow \text{商品列表} \rightarrow \text{详情页} \rightleftharpoons \text{购物车} \rightarrow \text{结算} $$ 2. **HTML结构搭建** ```html <!-- 示例:商品卡片结构 --> <div class="product-card"> <img src="phone.jpg" alt="商品图"> <h3>OPPO Reno7</h3> <p class="price">¥2999</p> <button class="add-cart">加入购物车</button> </div> ``` 3. **CSS样式设计** - 使用`Flexbox`/`Grid`布局商品列表 - 响应式设计关键代码: ```css @media (max-width: 768px) { .product-card { width: 100%; } } ``` 4. **JavaScript交互实现** - 购物车功能逻辑: ```javascript // 加入购物车示例 document.querySelector('.add-cart').addEventListener('click', () => { cartCount++; updateCartIcon(cartCount); }); ``` --- ### 📱 二、商城核心页面示例(基于OPPO商城参考) #### 首页布局结构 ```html <header> <nav><!-- 导航栏 --></nav> </header> <main> <section class="banner"><!-- 轮播广告 --></section> <section class="categories"><!-- 商品分类 --></section> <section class="products"><!-- 商品展示 --></section> </main> <footer><!-- 页脚信息 --></footer> ``` #### 商品详情页关键交互 ```html <div class="product-detail"> <div class="gallery"><!-- 商品图片 --></div> <div class="info"> <h2>商品名称</h2> <div class="price">¥2999</div> <div class="sku-select"><!-- 规格选择 --></div> <button>立即购买</button> </div> </div> ``` --- ### 🔗 三、完整资源推荐 1. **开源商城模板** - [eStore - HTML电子商务模板](https://colorlib.com/wp/template/estore/) - 特点:响应式设计 + 购物车功能 2. **学习资源** - MDN Web文档:[HTML表格结构](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/table) - W3Schools:[JavaScript购物车教程](https://www.w3schools.com/js/js_shopping_cart.asp) 3. **实际案例参考** - OPTO手机商城(参考引用[1])的三大核心特点: 1. 商品分页展示(6页设计) 2. 瀑布流布局商品列表 3. 浮动式购物车面板 --- ### 💡 四、进阶建议 1. **结合框架开发** - 使用[Bootstrap](https://getbootstrap.com/)快速搭建响应式布局 - 集成[jQuery]实现Ajax商品加载 2. **必备功能实现** - 本地存储购物车数据:`localStorage.setItem('cart', JSON.stringify(items))` - 表单验证(收货地址/支付信息) 3. **性能优化** - 图片懒加载:`<img loading="lazy">` - CSS/JS文件压缩 > 提示:实际开发中建议采用[MVC模式](https://developer.mozilla.org/zh-CN/docs/Glossary/MVC)分离业务逻辑,提高代码可维护性。[^1] --- ### ❓ 相关问题 1. 如何实现商城的商品搜索功能? 2. 移动端商城需要注意哪些特殊设计? 3. HTML商城如何集成第三方支付接口? 4. 如何优化商城页面的加载速度?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值