您的位置:

常见的CSS页面分页属性及其使用

一、首尾省略号

当分页数量特别多的时候,为了能让页面更为简洁明了,我们可以使用首尾省略号来缩略显示分页数量,而不用在页面上一一列出每个页码。这种方式需要借助CSS的overflow:hidden属性来实现。在分页容器的宽度已经确定的情况下,增加一定的宽度,将多余的页码隐藏。同时,为了使最左侧和最右侧的页码不被隐藏,也需要将其设置为一直显示。

.page {
    width: 500px; /* 分页容器宽度 */
    overflow: hidden;
}

.page ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.page li {
    float: left;
    margin-right: 5px;
}

.page li:first-child {
    margin-right: 10px; /* 最左侧页码增加宽度,使其一直显示 */
}

.page li:last-child {
    margin-right: 10px; /* 最右侧页码增加宽度,使其一直显示 */
}

.page li.ellipsis {
  width: auto; /* 首尾省略号 */
  margin: 0 5px;
  padding: 0 5px;
}

二、滚动分页

当分页数量更多的时候,可以考虑使用滚动的方式来呈现分页,用户通过滑动来选择不同的分页。这种方式可以借助CSS的overflow-y属性来实现。我们需要先将分页信息全部显示出来,然后设置分页容器的固定高度,通过overflow-y:hidden将超出部分隐藏,再通过JS或鼠标控制滚动条的滚动,从而进行不同分页的选择。

.page {
    height: 300px; /* 分页容器高度 */
    overflow-y: hidden;
}

.page ul {
    margin: 0;
    padding: 0;
    list-style: none;
    height: 100%;
}

.page li {
    margin: 10px;
}

.page li.active {
    background-color: #ccc; /* 激活的分页背景色 */
}

三、分页大小设置

当数据量特别大,或用户需要自定义每页显示的数据量时,我们可以提供分页大小设置的功能。这种方式可以使用select标签来实现,用户可以通过下拉选择框来设置每页显示的数据量,然后触发重新加载分页数据的操作。

.page-size {
    margin: 10px;
}

.page-size select {
    margin: 0 5px;
}

四、分页样式自定义

在一些特殊的场景下,我们需要根据具体的需求来对分页进行样式的自定义。这种方式可以借助CSS的伪类以及灵活运用class来实现。在这里以修改分页页码颜色为例:

.page li {
    display: inline-block;
    margin-right: 5px;
    padding: 0 5px;
    border-radius: 5px;
}

.page li.active {
    background-color: #ccc;
}

.page li a {
    color: #333;
}

.page li:hover a{
    color: #fff;
    background-color: #333;
}
常见的CSS页面分页属性及其使用

2023-05-12
CSS中的页面分页特性

2023-05-12
CSS页面分页

2023-05-12
CSS Sticky - 让页面元素“粘”在页面上的神奇属性

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