您的位置:

CSS empty cell

CSS空单元格(empty cell)主要是用来指定在表格中空单元格的样式。通过这个属性,您甚至可以将空单元格变成一个有颜色的背景,这样整个表格会更加地美观。

一、使用empty-cell属性

empty-cell属性主要有两个取值:show和hide。其中show是默认值,表示显示空单元格。而hide则表示隐藏空单元格。

可以用下面的 CSS 代码段来使用empty-cell属性并设定含有空单元格的表格的单元格周围的边框不跨越空行、空列:

table {
   empty-cells: hide;           /*隐藏空单元*/
   border-collapse: collapse;  /*合并边框*/
}
 

这段代码中的 empty-cells 属性是用来隐藏单元格的,当然你也可以设置为show,就是显示空单元格。

二、配合background-color属性

使用background-color属性将前景颜色设为与背景颜色相同的单元格难以被辨别,可以看一个例子:

table {
   empty-cells: show;
   border-collapse: collapse;
}
td.empty {
   background-color: #FF0000;
}
 
  
  
1 2 3
4 5 7
8 9 10 11

在上面的例子中,第二行第三列为空单元格(没有填写具体内容),使用了empty-cells属性,并配合background-color属性设置了单元格的背景色。这样的话,空单元格就变成了红色背景,而不会被忽略。

三、配合::before伪元素添加内容

有时,您可能希望在空白单元格中添加一些文本或符号,以强调他们。这时可以利用CSS中的::before伪元素,将内容添加到空的单元格中:

table {
   empty-cells: show;
   border-collapse: collapse;
}
td.empty::before {
   content: "N/A";
}
 
  
  
1 2 3
4 5 7
8 9 10 11

在上面的例子中,我们使用CSS中的::before伪元素来插入文本"N/A"到单元格中。这样空白的单元格就变成了"N/A",看起来就不太尴尬。

总结

通过本文,我们可以看到在表格布局中,如果有一些空单元格十分尴尬,使用empty-cell属性,我们可以将空单元格的边框设为跨过(hide)或不跨过(show)默认边框的位置。我们也可以利用CSS中的::before伪元素,将文本添加到空的单元格中。

CSS empty cell

2023-05-12
CSS Empty Cells

2023-05-12
CSS边框笔记

2023-05-12
CSS文字居中详解

2023-05-22
使用CSS实现表格布局的技巧

2023-05-12
CSS Vertical Align

2023-05-12
前端学习笔记

2023-05-12
如何使用 CSS 表格布局优化网页内容呈现

2023-05-12
CSS字体垂直居中详解

2023-05-17
使用CSS实现垂直对齐

2023-05-12
重学java笔记,java笔记总结

2022-11-23
js中cell(js中cellspacing)

本文目录一览: 1、javascript中cell的用法 2、js如何获取表格中某一行的单元格数 3、谁能解释下这段js代码的意思 4、js insertcell 怎么跨列 5、js中cell可以显示

2023-12-08
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)