您的位置:

如何实现圆角边框效果

一、CSS实现圆角边框

CSS3提供了border-radius属性,可以实现圆角边框的效果。这个属性可以控制边框的四个角的圆角半径,其属性值可以是一个或多个。考虑到兼容性问题,可以使用浏览器引擎特性来写出相应的代码,如下所示:

.selector {
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px;
}

这个代码段实现了一个10px的圆角边框效果。其中,-moz-border-radius和-webkit-border-radius是过去和现在用来支持Firefox和Chrome浏览器的前缀。border-radius是CSS3标准写法。通过使用这三个属性,可以针对不同的浏览器支持圆角边框效果。

二、CSS实现多重圆角边框效果

如果想要实现多重边框,那么可以在一个div上使用多个box-shadow。box-shadow可以用来在元素下方添加边框阴影。例如下面的代码段可以实现两层不同颜色的边框:

.selector {
    box-shadow: 
        0 0 0 10px #f00, 
        0 0 0 15px #00f;
}

其中,第一个参数是水平位移量,第二个参数是向上位移量,第三个参数是模糊半径,第四个参数是边框宽度,第五个参数是颜色。传入多组参数即可实现多重边框。

三、CSS实现半透明圆角边框效果

为了实现半透明的圆角边框样式,可以使用伪元素":before"和":after",并且使用绝对定位来创建一个空心的容器。如下所示:

.selector {
    position: relative;
}
.selector:before, .selector:after {
    content: "";
    display: block;
    position: absolute;
    top: -15px; 
    bottom: -15px; 
    left: -15px;
    right: -15px;
    box-shadow: inset 0 0 0 15px rgba(255, 0, 0, 0.5), 
        inset 0 0 0 20px rgba(0, 0, 255, 0.5); 
    z-index: -1;
    border-radius: 20px;
}

在这个代码段里,通过使用box-shadow属性绘制了圆角边框的阴影,通过设置z-index为-1,使其位于元素的下层,并通过border-radius设置圆角半径实现圆角边框。同时,通过绝对定位和top/bottom/left/right属性将伪元素定位于容器内部。

四、SVG实现圆角边框效果

SVG也可以实现圆角边框效果。SVG是一门XML语言,它可以让我们创建点阵图和矢量图。在创建SVG圆角边框之前,应该先了解path元素。path元素的d属性可以用来描述一条路径。例如下面是一个简单的path元素:

  
  

  

在SVG中,圆弧路径使用"A"命令描述。下面的代码段展示了如何使用SVG绘制圆角边框效果:

  
  
  

  

在这个代码段中,使用了一个rect元素来创建一个长方形,并将rx和ry属性设置为20,以实现20px的圆角半径。通过填充none和设置描边颜色和宽度,创建一个透明的矩形描边,其颜色为红色。

五、Canvas实现圆角边框效果

Canvas也可以实现圆角边框效果。canvas是HTML5新增的元素,可以在其中进行绘图。下面的代码展示了如何使用canvas绘制圆角边框效果:

  
<script>
  var canvas = document.getElementById('myCanvas');
  var ctx = canvas.getContext('2d');
  ctx.lineWidth = 10;
  ctx.strokeStyle = '#f00';
  ctx.lineJoin = 'round';
  ctx.strokeRect(50, 50, 100, 100);
</script>

在这个代码段中,首先获取了canvas元素和画布上下文,并通过设置lineWidth和strokeStyle属性来绘制透明的描边,最后使用strokeRect方法绘制一个矩形。通过设置lineJoin属性为“round”,可以实现圆角边框的效果。

如何实现圆角边框效果

2023-05-12
如何实现CSS边框的圆角

2023-05-12
如何使用CSS创建圆角边框效果

2023-05-12
如何使用CSS创建圆角边框效果

2023-05-12
如何实现圆角边框的CSS样式

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)