您的位置:

深入浅出:background-repeat属性

一、background-repeat属性默认值

在CSS中,背景图片可以通过background-image属性进行设置,但是图片大小通常与元素大小不匹配,这时候就需要使用background-repeat属性来对背景图片进行重复或平铺。background-repeat属性控制背景图片在元素内被平铺的方式。

background-repeat属性的默认值是repeat,表示背景图片在元素上下左右方向均平铺重复。

   background-repeat: repeat; /* 默认值 */

二、background-clip属性

background-clip属性设置元素背景的绘制区域。默认情况下,背景绘制区域从border-box的外边缘开始,直到内边缘之间的区域。如果border-box被裁切,那么背景将不会在裁切区域中绘制。background-clip属性决定哪一部分的背景需要被绘制。

background-repeat属性与background-clip属性关联。如果background-clip设置为padding-box,而background-repeat的值为repeat或space,则图片将在padding-box内平铺,以防止图片重复裁剪。如果background-clip设置为border-box,则图片将在border-box内平铺。

   /* 在text节点内绘制背景图像且仅在元素的padding框之内 */
   background-clip: padding-box;
   /* 元素内的背景图像将在border区域内平铺 */
   background-clip: border-box;

三、background-repeat属性的其他设置

除了默认的repeat重复平铺背景图片外,background-repeat属性还有以下几个设置。

1、no-repeat(不平铺)

no-repeat表示背景图片在元素内只显示一次,不进行重复。

   background-repeat: no-repeat;

2、repeat-x(水平平铺)

repeat-x表示背景图片仅在水平方向上平铺重复,垂直方向上则不进行重复。

   background-repeat: repeat-x;

3、repeat-y(垂直平铺)

repeat-y表示背景图片仅在垂直方向上平铺重复,水平方向上则不进行重复。

   background-repeat: repeat-y;

4、space和round(重复间距)

space和round也是平铺重复背景图片,但是与repeat不同的是,它们会在图片之间留有一定的间距,同时调整图片大小。

space表示背景图片平均地进行平铺展开,同时调整图片尺寸使其与最佳宽度相同。round表示背景图片在元素区域内平铺展开,同时调整图片尺寸使其充满整个元素区域。

   background-repeat: space;
   background-repeat: round;

小结

在CSS中,background-repeat属性有重复平铺、水平平铺、垂直平铺、不平铺、重复间距等设置。同时,background-repeat属性与background-clip属性关联,可以对背景图片进行更精细的控制。

深入浅出:background-repeat属性

2023-05-22
深入了解CSS属性background-repeat

2023-05-20
CSS属性:background-repeat的使用方法

2023-05-12
深入解析HTML中的background

2023-05-21
深度探究HTML Background属性

2023-05-21
深入解析background-color的应用

2023-05-19
CSS background repeat

2023-05-12
CSS Repeat Background Title详解

2023-05-12
CSS Background Repeat in HTML

2023-05-12
深入理解background平铺

2023-05-20
CSS Background-Repeat

2023-05-12
深入理解background缩写

2023-05-20
CSS background-repeat详解

2023-05-18
Repeat-X:我们最常见的CSS背景属性

2023-05-23
CSS background-repeat 属性 - 控制背

2023-05-12
深入了解background-imageurl

2023-05-21
深入探究background用法

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