您的位置:

CSS HTML 边框样式

一、什么是 CSS HTML 边框样式

CSS HTML 边框样式指的是通过 CSS 样式表来设置 HTML 元素边框的属性,如边框宽度、边框样式、边框颜色等。使用边框样式可以为 HTML 元素添加装饰和定义外观,提高页面的美观性和可读性。下面是 CSS HTML Border Style 的代码示例:

<style>
  div {
    border: 1px solid black;  /*设置边框样式*/
    border-radius: 5px;    /*设置边界半径*/
    padding: 10px;       /*设置内边距*/
    background-color: #f2f2f2;  /*设置背景色*/
  }
</style>

<div>
  <p>这是一个带边框和圆角的 div 元素</p>
</div>

二、CSS HTML 边框样式的属性详解

1. 边框宽度

边框宽度使用 border-width 属性进行设置,可以设置成像素值、百分比值或者预定义值。如果想要分别设置元素上下左右四个方向的边框宽度,可以使用 border-top-width、border-right-width、border-bottom-width 和 border-left-width 属性分别设置。下面是一个设置不同边框宽度的代码示例:

<style>
  /*设置四个方向的边框宽度*/
  #box {
    border-top-width: 2px;    
    border-right-width: 4px;  
    border-bottom-width: 6px; 
    border-left-width: 8px;   
  }
</style>

<div id="box">
  <p>这是一个带不同边框宽度的 div 元素</p>
</div>

2. 边框样式

边框样式使用 border-style 属性进行设置,可以设置成实线、虚线、点线、双实线等多种样式。如果想要分别设置元素上下左右四个方向的边框样式,可以使用 border-top-style、border-right-style、border-bottom-style 和 border-left-style 属性分别设置。下面是一个设置不同边框样式的代码示例:

<style>
  /*设置四个方向的边框样式*/
  #box {
    border-top-style: solid;  
    border-right-style: dotted;
    border-bottom-style: dashed;
    border-left-style: double; 
  }
</style>

<div id="box">
  <p>这是一个带不同边框样式的 div 元素</p>
</div>

3. 边框颜色

边框颜色使用 border-color 属性进行设置,可以设置成颜色名、十六进制颜色值、RGB 颜色值等多种颜色形式。如果想要分别设置元素上下左右四个方向的边框颜色,可以使用 border-top-color、border-right-color、border-bottom-color 和 border-left-color 属性分别设置。下面是一个设置不同边框颜色的代码示例:

<style>
  /*设置四个方向的边框颜色*/
  #box {
    border-top-color: red;  
    border-right-color: green;
    border-bottom-color: blue;
    border-left-color: #ffa500; 
  }
</style>

<div id="box">
  <p>这是一个带不同边框颜色的 div 元素</p>
</div>

4. 圆角边框

圆角边框使用 border-radius 属性进行设置,可以将元素的边角变成圆角。可以设置成像素值、百分比值或者预定义值。下面是一个设置圆角边框的代码示例:

<style>
  #box {
    border: 3px dashed #ccc;
    border-radius: 20px; 
    padding: 20px;
    background-color: #f2f2f2;
  }
</style>

<div id="box">
  <p>这是一个带圆角边框的 div 元素</p>
</div>

三、常用 CSS HTML 边框样式

1. 实线边框

实线边框可以使用 border-style 属性的 solid 值来设置,如下所示:

<style>
  #box {
    border: 1px solid red;
  }
</style>

<div id="box">
  <p>这是一个实线边框的 div 元素</p>
</div>

2. 虚线边框

虚线边框可以使用 border-style 属性的 dashed 值来设置,如下所示:

<style>
  #box {
    border: 1px dashed blue;
  }
</style>

<div id="box">
  <p>这是一个虚线边框的 div 元素</p>
</div>

3. 圆角边框

圆角边框可以使用 border-radius 属性来设置,如下所示:

<style>
  #box {
    border: 1px solid #ccc;
    border-radius: 10px;
  }
</style>

<div id="box">
  <p>这是一个圆角边框的 div 元素</p>
</div>

4. 阴影边框

阴影边框可以使用 box-shadow 属性来设置,如下所示:

<style>
  #box {
    box-shadow: 5px 5px 5px #888888;
    padding: 20px;
    background-color: #f2f2f2;
  }
</style>

<div id="box">
  <p>这是一个阴影边框的 div 元素</p>
</div>

5. 渐变边框

渐变边框可以使用 linear-gradient() 函数来设置,如下所示:

<style>
  #box {
    border: 3px solid;
    border-image: linear-gradient(to bottom, #00ffff, #ff00ff) 1;
    padding: 20px;
    background-color: #f2f2f2;
  }
</style>

<div id="box">
  <p>这是一个渐变边框的 div 元素</p>
</div>

四、总结

CSS HTML 边框样式是前端开发中常用的样式之一,通过设置边框样式可以为 HTML 元素添加装饰和定义外观,提高页面的美观性和可读性。在实际应用中需要灵活运用不同的边框样式,以达到预期的效果。希望本文对您有所帮助。

CSS HTML 边框样式

2023-05-12
CSS HTML 边框样式

2023-05-12
CSS边框笔记

2023-05-12
CSS边框样式为HTML元素提供设计

2023-05-12
CSS HTML 边框类型

2023-05-12
为HTML元素添加边框——CSS样式装饰

2023-05-12
CSS与HTML边框

2023-05-12
CSS HTML: 圆角边框

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)