您的位置:

CSS Border 属性详解

一、border 属性的概述

网页设计中,边框是不可或缺的部分,能够让网页变得更加醒目。CSS 提供了 border 属性,用于设置 HTML 元素的边框样式、宽度和颜色等,打造出各种形态的边框。这里,我们就从边框的基础属性开始介绍。

二、border-style 属性的使用

边框样式是所有边框属性中最基础的属性,通过它可以设置边框的样式。默认样式为 none。常用的边框样式有 solid、dashed、dotted、double、groove、ridge、inset、outset 等等。常见的代码如下:

.box{
    border-style: dotted;  /* dotted 表示点状边框 */
}

三、border-color 属性的使用

border-color 属性用于设置边框的颜色,可以使用具体的颜色名称或十六进制颜色值。该属性也支持设置不同边框颜色,可以简写,也可以单独设置某一条边框的颜色。常见的代码如下:

.box{
    border-style: solid;  /* solid 表示实线边框 */
    border-color: #ccc;  /* 边框颜色为灰色 */
}

.box{
    border-style: solid;  /* solid 表示实线边框 */
    border-top-color: #ccc;  /* 上边框颜色为灰色 */
    border-right-color: #000;  /* 右边框颜色为黑色 */
    border-bottom-color: #333;  /* 下边框颜色为深灰色 */
    border-left-color: #f00;  /* 左边框颜色为红色 */
}

四、border-width 属性的使用

border-width 属性用于设置边框的宽度,可以使用具体的像素值、百分比或关键词 thin、medium、thick 定义。同样,该属性也支持单独设置某一条边框的宽度,可以简写,也可以只设置某些属性。常见的代码如下:

.box{
    border-style: solid;  /* solid 表示实线边框 */
    border-color: #ccc;  /* 边框颜色为灰色 */
    border-width: 2px;  /* 边框宽度为2像素 */
}

.box{
    border-top-width: 1px;  /* 上边框宽度为1像素 */
    border-width: 1px 3px 5px;  /* 上边框1px,右侧边框3像素,下边框5像素,左侧边框3像素 */
}

五、border-radius 属性的使用

border-radius 属性用于设置 HTML 元素的圆角。通过改变圆角半径,可以为元素设置不同的圆角。支持单独和统一设置每一个圆角。常见的代码如下:

.box{
    border-style: solid;  /* solid 表示实线边框 */
    border-color: #ccc;  /* 边框颜色为灰色 */
    border-width: 2px;  /* 边框宽度为2像素 */
    border-radius: 5px;  /* 统一设置元素的圆角半径为5像素 */
}

.box{
    border-style: solid;  /* solid 表示实线边框 */
    border-color: #ccc;  /* 边框颜色为灰色 */
    border-width: 2px;  /* 边框宽度为2像素 */
    border-radius: 5px 10px 15px 20px;  /* 分别设置左上、右上、右下、左下四个角的圆角半径 */
}

六、border-image 属性的使用

border-image 属性可以通过设置边框图片和宽度来替换传统的实线边框。它通过指定边框图片地址、切割方式、边框图片的宽度和高度等来绘制边框。常见的代码如下:

.box{
    border-image: url(border.png) 30 round;  /* 设置边框图片 */
    border-width: 30px;  /* 边框宽度为30像素 */
    border-color: #ccc;  /* 边框颜色为灰色 */
    border-style: solid;  /* solid 表示实线边框 */
}
以上是 CSS Border 属性的详细讲解,通过边框属性的设置,可以轻松地打造出各种不同的边框效果。
CSS border color属性详解

2023-05-12
CSS Border 属性详解

2023-05-12
详解CSS border-image属性

2023-05-20
CSS border-spacing 属性

2023-05-12
CSS Border属性

2023-05-12
CSS dashed属性详解

2023-05-16
CSS Border Bottom常用属性详解

2023-05-19
CSS Border in HTML

2023-05-12
详解CSS中的BorderStyle属性

2023-05-18
了解CSS box-sizing属性

2023-05-12
CSS Bottom属性详解

2023-05-19
CSS border-color属性

2023-05-12
CSS HTML DIV Border标题

2023-05-12
CSS Border Images

2023-05-12
CSS边框笔记

2023-05-12
CSS Border Examples

2023-05-12
when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: ${item.id} [in template "article/detail/index.ftl" at line 48, column 106] ---- Java stack trace (for programmers): ---- freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:481) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:401) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:370) at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:104) at freemarker.core.DollarVariable.accept(DollarVariable.java:63) at freemarker.core.Environment.visit(Environment.java:371) at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321) at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271) at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244) at freemarker.core.Environment.visitIteratorBlock(Environment.java:645) at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108) at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94) at freemarker.core.Environment.visit(Environment.java:335) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.process(Environment.java:314) at freemarker.template.Template.process(Template.java:383) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:332) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:266) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:220) at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:181) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1431) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1106) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at com.software.filter.HttpSpiderIdentifyFilter.doFilter(HttpSpiderIdentifyFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) at java.base/java.lang.VirtualThread.run(VirtualThread.java:309)