Table of Contents
一、CSS边框基础知识
二、Html原始边框与CSS边框对照
三、border边框语法
四、CSS单独设置左边框、右边框、上边框、下边框
五、常用推荐边框样式
六、css border边框用处
七、css边框应用案例代码
八、css边框border总结
十一、css边框border设置技巧
Home Web Front-end HTML Tutorial css border_html/css_WEB-ITnose

css border_html/css_WEB-ITnose

Jun 24, 2016 am 11:17 AM

CSS border用于设置HTML元素(如div)的边框,包括边框的宽度、颜色和样式。本文章向码农介绍CSS border边框属性详细内容,感兴趣的码农可以参考一下。

CSS 边框即CSS border-border边框样式颜色、边框样式、边框宽度的语法结构与应用案例教程篇

 

一、CSS边框基础知识

CSS 边框即CSS border是控制对象的边框边线宽度、颜色、虚线、实线等样式CSS属性。同时大家可以进入码农教程提供CSS手册查看border。

 

二、Html原始边框与CSS边框对照

Html表格控制边框:

border="1" bordercolor="#000000"
Copy after login

说明:控制表格边框宽度为1px,css颜色为黑色,默认为实线样式边框。

三、border边框语法

1、四个边框

border-left 设置左边框,一般单独设置左边框样式使用
border-right 设置右边框,一般单独设置右边框样式使用
border-top 设置上边框,一般单独设置上边框样式使用
border-bottom 设置下边框,一般单独设置下边框样式使用,有时可将下边框样式作为css下划线效果应用。

2、四边相同边框border简写

#manong{border:1px solid #00F}
Copy after login

设置了manong对象盒子1px像素蓝色实线边框

3、边框三个样式

通常我们可以对边框设置宽度(厚度)、边框样式、边框颜色这三个属性与参数。

1)、边框颜色:border-color:#000

2)、边框厚度(宽度):border-width:1px

使用数字+单位设置边框厚度宽度,如1px(边框厚度宽度为1像素),边框必须为正数字,大于0的数值。否则设置边框border样式无效。

3)、border边框样式:border-style:solid

边框样式值如下:

none :  无边框。与任何指定的border-width值无关
hidden :  隐藏边框。IE不支持
dotted :  在MAC平台上IE4+与WINDOWS和UNIX平台上IE5.5+为点线。否则为实线(常用)
dashed :  在MAC平台上IE4+与WINDOWS和UNIX平台上IE5.5+为虚线。否则为实线(常用)
solid :  实线边框(常用)
double :  双线边框。两条单线与其间隔的和等于指定的border-width值
groove :  根据border-color的值画3D凹槽
ridge :  根据border-color的值画菱形边框
inset :  根据border-color的值画3D凹边
outset :  根据border-color的值画3D凸边

四、CSS单独设置左边框、右边框、上边框、下边框

以缩写方式写上、下、左、右边框单独CSS样式设置方法

1、1px黑色虚线上边框

border-top:1px dashed #000

2、1px黑色实线下边框

border-bottom:1px solid #000

3、1px黑色虚线左边框

border-left:1px dashed #000

4、1px黑色实线右边框

border-right:1px solid #000

五、常用推荐边框样式

我们通常使用主流浏览器兼容边框样式有:

1、实线边框:solid

Border:1px solid #000 设置对象1px(像素)宽厚的黑色实线边框。

2、虚线边框:dashed

Border:1px dashed #000 设置对象1px(像素)宽厚的黑色虚线边框。

六、css border边框用处

设置对象边框样式,设置单独上边框、下边框、左边框、右边框样式,实现美化美观。边框起到分割、规划布局作用。

七、css边框应用案例代码

描述:为了观察案例效果我们设置一个css宽度为200px,css高度1px,红色实线边框的DIV盒子

CSS代码:

#manong{height:100px;width:200px;border:1px solid #F00}
Copy after login

HTML代码对应片段:

<div id="manong">我的高度为100px,宽度为200px</div>
Copy after login

八、css边框border总结

我们使用CSS设置边框border样式,一般我们使用简写表达式进行设置对象边框border样式,这样节约代码简化代码作用。无论是单独设置一个边的边框还是四边边框,我们都尽量缩写方式简写CSS边框代码,CSS 边框优化简写,常见对对象设置CSS样式使用属性代码:border:1px solid #000;。

十一、css边框border设置技巧

如左右下有边框并且样式为黑色1PX宽度实线边框,而上边没有边框。

CSS 代码:

border:1px solid #000; border-top:none;
Copy after login

注意border:1px solid #000; 和border-top:none;前后顺序不能调换。因为CSS读取有从上到下、从左到右读取原理,而先设置了整个边框样式,后再加上声明顶部上边边框为“none”没有意思,即实现该实例要的样式。从而无需分别设置下、左、右,从而节约一定代码。

相关阅读:

css 教程

html教程

css 参考手册

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

See all articles