您的位置:

CSS Border Rounded

一、属性介绍

CSS Border Rounded属性,指的是通过添加border-radius属性来为元素边框添加圆角效果。border-radius可以控制边框的圆角大小,可以使用具体像素值,也可以使用百分比,甚至可以使用em、ex作为单位。

以下是设置了圆角效果的CSS属性:

border-top-left-radius
border-top-right-radius
border-bottom-left-radius
border-bottom-right-radius

分别控制元素四个角的圆角大小。如果我们想要一个元素四个角的圆角大小相同,只需要设置border-radius属性即可。

border-radius: 20px;

二、简单示例

下面是一个简单的示例,我们给一个div元素添加了圆角效果。

<div style="width:200px;height:100px;border:2px solid red;border-radius:25px;">
  <p>这是一个例子</p>
</div>

该div元素的宽为200px,高为100px,边框为2px的红色实线边框,圆角半径为25px。

三、多种圆角样式

在设置边框的圆角大小时,不仅仅只能设置一个具体数值,还可以设置多个数值,用/分隔,每个数值用空格隔开。

以下是示例代码:

border-radius: 20px 10px 30px 40px / 10px 30px 20px 40px;

这行代码设置了一个复合的border-radius值。值的顺序是顺时针排列的,从左上角开始。第一个数值指的是左上角的水平半径,第二个数值指的是左上角的垂直半径,以此类推。

四、椭圆形圆角

除了可以设置具体像素值之外,border-radius属性还可以使用百分比来设置圆角大小。如果上下左右四个角的半径是相等的,可以这样写:

border-radius: 50%;

这样可以得到一个正圆形的圆角效果,但如果四个角的半径不相等时,就会变成椭圆形。

以下是示例代码:

<div style="width:200px;height:100px;border:2px solid red;border-radius:50%;background-color:grey;">
  <p>这是一个例子</p>
</div>

五、不同背景色的圆角效果

我们可以在一个元素中设置多个背景色,比如使用线性渐变或径向渐变的背景。但这样会导致圆角效果失效。为了解决这个问题,我们可以使用伪元素:before和:after,再用盒模型的基本样式将其隐藏起来,并为这两个伪元素添加样式。

以下是示例代码:

<style>
  #rounded {
    width: 200px;
    height: 100px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(to right, red , orange);
  }
  #rounded:before, #rounded:after {
    position: absolute;
    content: '';
    width: 100%;
    height: 100%;
    border-radius: 20px;
    background: linear-gradient(to right, red , orange);
    z-index: -1;
  }
  #rounded:before {
    transform: rotate(45deg);
    top: -35%;
    left: -15%;
  }
  #rounded:after {
    transform: rotate(45deg);
    bottom: -35%;
    right: -15%;
  }
</style>

<div id="rounded">
  <p>这是一个例子</p>
</div>

上述代码中,我们将元素溢出的部分剪裁掉,再添加两个伪元素,使用border-radius属性来设置圆角大小,然后将它们旋转45度并分别放到元素的顶部左侧和底部右侧。这样就可以得到不同背景色的圆角效果。

六、总结

CSS Border Rounded属性可以为元素的边框添加圆角效果。可以设置四个角的半径大小,也可以使用复合值进行设置。此外还可以使用百分比来设置圆角大小,并且可以实现不同背景色的圆角效果。

CSS Border Rounded

2023-05-12
CSS HTML Border Rounded

2023-05-12
CSS圆角矩形详解

2023-05-18
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)