您的位置:

CSS背景图片平铺

一、CSS背景图片平铺填满

如果想要让背景图片填满整个元素,只需设置CSS属性“background-size: cover;”即可,此时背景图片会按比例缩放,以填满整个元素。


background-image: url('image.png');
background-size: cover;

但是需要注意的是,如果图片比例和容器比例不同,会有部分裁剪掉。如果想要保证整张图片完整显示,可以设置CSS属性“background-size: contain;”。


background-image: url('image.png');
background-size: contain;

二、CSS背景图片平铺造成间隙

CSS背景图片平铺时会有一个问题,就是如果两个背景图片相接的时候,可能会出现间隙。这是因为不同浏览器对于像素处理的方式不同,造成了像素的精度误差。解决这个问题有几个方法:

1、为背景图片添加半透明边框,这样背景图片就会重叠在一起,遮住了间隙。


background-image: url('image.png');
border: 1px solid rgba(0, 0, 0, 0.5);

2、使用CSS3的“background-clip: padding-box;”属性,可以让背景图片不会超出元素的边框,从而避免了间隙问题。


background-image: url('image.png');
background-clip: padding-box;

三、CSS背景图怎么平铺带间隔

有时候我们需要让背景图片重复出现,但是每个背景图片之间留有一定的空隙。我们可以通过CSS属性“background-repeat: space;”实现,在浏览器支持的情况下,它会让背景图片自动等间隔重复。


background-image: url('image.png');
background-repeat: space;

四、背景图片平铺CSS

当我们不需要让背景图片重复变化的时候,只需要设置CSS属性“background-repeat: no-repeat;”即可。此时背景图片只会出现一次。


background-image: url('image.png');
background-repeat: no-repeat;

五、HTML背景图片平铺

在HTML中也可以指定背景图片。只需要使用style属性即可:



   

六、CSS背景图片铺满

如果想要让背景图片在水平和垂直方向上都铺满整个元素,可以使用CSS属性“background-size: 100% 100%;”


background-image: url('image.png');
background-size: 100% 100%;

七、CSS背景图片大小设置

可以根据自己的需要设置背景图片的大小,直接设置CSS属性“background-size: 宽度 高度;”。宽度和高度可以使用像素或百分比。


background-image: url('image.png');
background-size: 300px 200px;

八、CSS背景图片自适应

有时候我们需要让背景图片随着元素自适应,可以设置CSS属性“background-size: auto;”。


background-image: url('image.png');
background-size: auto;

九、CSS背景图片拉伸

可以使用CSS属性“background-size: stretch;”让背景图片铺满整个元素,但是如果背景图片比例和容器比例不同,图片会被拉伸变形。


background-image: url('image.png');
background-repeat: no-repeat;
background-size: stretch;

十、CSS背景图片居中选取

可以使用CSS属性“background-position: center;”让背景图片在元素中居中显示。


background-image: url('image.png');
background-repeat: no-repeat;
background-position: center;
CSS背景图片平铺

2023-05-20
CSS图片平铺的详解

2023-05-20
HTML背景图片不重复平铺

2023-05-20
如何在CSS中实现背景图平铺效果

2023-05-12
如何在CSS中添加背景图片

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

2023-05-12
如何设置背景图片CSS样式

2023-05-12
使用background-image在CSS中添加背景图片

2023-05-12
img平铺

2023-05-19
背景图片位置调整

2023-05-12
CSS设置背景图片技巧详解

2023-05-12
如何让CSS中的重复背景图片更好地展示?

2023-05-12
如何用CSS添加背景图片 - 教程

2023-05-12
如何使用CSS将背景图片居中?

2023-05-12
如何在CSS中使用重复背景图片?

2023-05-12
如何为网页元素添加背景图片

2023-05-12
小程序背景图片自适应完整指南

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