您的位置:

CSS border属性详解——打造精美网页边框效果

在网页设计中,边框的使用是非常重要的,可以美化页面并将内容分隔开。而CSS中,border属性则为我们提供了一种简单而易用的方式来控制边框的样式、粗细、颜色等属性。在这篇文章中,我们将详细介绍CSS border属性,并通过实例代码来展示如何创建不同类型的边框样式。

一、border-style属性

border-style属性用于定义边框的样式。常用的样式值包括solid、dashed、dotted、double、groove、ridge、inset和outset等,分别对应不同的边框样式。以下是常见样式的示例代码:
// 定义红色实线边框
border: 2px solid #ff0000;

// 定义蓝色虚线边框
border: 3px dashed #0000ff;

// 定义黑色点线边框
border: 2px dotted #000000;

// 定义黄色双线边框
border: 4px double #ffff00;

// 定义立体的深灰色边框
border: 6px groove #333333;

// 定义立体的浅灰色边框
border: 6px ridge #cccccc;

// 定义向内的白色边框
border: 4px inset #ffffff;

// 定义向外的蓝色边框
border: 4px outset #0000ff;

二、border-width属性

border-width属性用于定义边框的粗细,常用的取值包括px、em、rem等。以下是示例代码:
// 定义2像素粗的边框
border: 2px solid #000000;

// 定义3像素粗的边框
border: 3px solid #000000;

// 定义1.5em粗的边框
border: 1.5em solid #000000;

三、border-color属性

border-color属性用于定义边框的颜色,常用的取值包括十六进制颜色码、颜色名称等。以下是示例代码:
// 定义黑色边框
border: 2px solid #000000;

// 定义红色边框
border: 2px solid #ff0000;

// 定义绿色边框
border: 2px solid green;

// 定义蓝色边框
border: 2px solid #0000ff;

四、border-radius属性

border-radius属性用于定义边框的圆角半径,使得边框更加柔和。以下是示例代码:
// 定义所有角都为15像素半径的圆角
border-radius: 15px;

// 定义左上角和右下角为25像素半径的圆角
border-radius: 25px 0 25px 0;

// 定义上边框两个角为15像素半径的圆角
border-top-left-radius: 15px;
border-top-right-radius: 15px;

五、实例代码演示

下面是一些实际应用中的样例代码,来展示border属性的实际效果:
// 创建一个黑色圆角边框,边框宽度为3像素
div{
    border: 3px solid #000000;
    border-radius: 15px;
}

// 创建一个蓝色点线边框,边框宽度为2像素
h1{
    border: 2px dotted #0000ff;
}

// 创建一个白色实线边框,宽度为1像素,圆角为5像素
button{
    border: 1px solid #ffffff;
    border-radius: 5px;
}

// 创建一个红色粗线框,深度立体效果
img{
    border: 6px groove #ff0000;
}

总结

边框是网页设计不可或缺的一部分,而CSS border属性则为我们提供了非常丰富和多样化的边框样式。通过对border-style、border-width、border-color和border-radius等属性的灵活应用,我们可以轻松地打造出各种精美的边框效果。希望这篇文章对你有所帮助,也欢迎在评论区留下你的问题和建议。
CSS border属性详解——打造精美网页边框效果

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)