您的位置:

HTML表格CSS样式指南

HTML表格CSS样式指南

更新:

HTML表格是前端开发中经常使用的重要元素,通过合理的CSS样式设置,能够提高表格的可读性、美观度以及用户体验。下面从多个方面对HTML表格的CSS样式做详细阐述。

一、表格基本样式

1、设置表格样式

table{
    border-collapse: collapse;   /*合并边框*/
    width: 100%;                /*设置宽度为100%*/
    margin: 10px 0;             /*设置上下边距为10px*/
}

2、设置单元格样式

td,th{
    border: 1px solid #ccc;     /*设置边框*/
    text-align: center;         /*居中对齐*/
    padding: 8px;               /*设置内边距为8px*/
}
th{
    background-color: #f2f2f2;  /*设置表头背景色*/
}

二、表格额外样式

1、交替行背景色

tr:nth-child(odd){
    background-color: #f2f2f2;  /*设置奇数行的背景色*/
}

2、鼠标悬停行背景色

tr:hover{
    background-color: #e2e2e2;  /*鼠标悬停时的背景色*/
}

3、单元格跨列和跨行

         /*设置横向跨2列*/
         /*设置纵向跨2行*/

三、响应式表格

1、表格自适应

table{
    width: 100%;
    overflow-x: auto;           /*水平滚动条*/
    -webkit-overflow-scrolling: touch;   /*兼容iOS弹性滚动*/
}

2、隐藏表头

.table-header{
    display: none;
}
@media screen and (min-width: 768px){
    .table-header{
        display: table-header-group;
    }
}

注意:上面的代码中,".table-header"是隐藏表头的class名称,当屏幕宽度大于等于768px时,表头才会显示出来。

四、总结

通过对HTML表格CSS样式的详细阐述,我们可以得出以下结论:对表格样式的设置能够提高表格的可读性、美观度以及用户体验。除了基本样式外,我们还可以设置交替行背景色、鼠标悬停行背景色、单元格跨列和跨行,以及实现响应式表格的自适应和隐藏表头等特殊样式。当然,不同的页面需求会有不同的表格样式设置,只有根据实际需求进行合理设置,才能达到最佳效果。

HTML表格CSS样式指南

HTML表格是前端开发中经常使用的重要元素,通过合理的CSS样式设置,能够提高表格的可读性、美观度以及用户体验。下面从多个方面对HTML表格的CSS样式做详细阐述。 一、表格基本样式 1、设置表格样式

2023-12-08
cssjs钟表样式(js表格样式)

本文目录一览: 1、JS调用CSS样式表问题(功能鼠标经过文本域是文本域边框颜色发生变化『给出能够实现功能的源码』) 2、JS中改变CSS样式的问题 3、css怎么样制作钟表 4、如何用JS修改已加载

2023-12-08
优雅的表格样式设计 | CSS HTML表格类

2023-05-12
CSS HTML表格圆角

2023-05-12
CSS HTML列表样式类型

2023-05-12
CSS HTML鼠标样式

2023-05-12
表格样式

2023-05-12
htmljs编程笔记(html代码笔记)

本文目录一览: 1、html代码和JS代码有什么区别 2、如何在html中调用js函数 3、JavaScript学习笔记之数组基本操作示例 4、HTML5初学者笔记 5、《web前端笔记7》js字符—

2023-12-08
CSS和HTML实现圆角表格

2023-05-12
CSS Border in HTML

2023-05-12
htmljs设置css,HTML表格设置

2022-11-25
CSS HTML圆角表格

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)