BootStrap自适应Table表格固定左边第一列

前端之家收集整理的这篇文章主要介绍了BootStrap自适应Table表格固定左边第一列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

有个页面引用了BootStrap前端框架,这个页面是一个table,要放在手机上浏览。这个table的左侧第一列是要固定的。所谓第一列固定,就是在横向滚动的时候第一列一直显示在最左侧。网上查了下方法,现将具体的操作步骤记录下来,方便需要的朋友进行查看。

一、js文件里加入如下代码

Crayon-5c891c9a5032f786714382" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">JavaScript
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891c9a5032f786714382-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a5032f786714382-2">2
Crayon-num" data-line="Crayon-5c891c9a5032f786714382-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a5032f786714382-4">4
Crayon-num" data-line="Crayon-5c891c9a5032f786714382-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a5032f786714382-6">6
Crayon-num" data-line="Crayon-5c891c9a5032f786714382-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a5032f786714382-8">8
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891c9a5032f786714382-1">Crayon-t">varCrayon-h"> Crayon-sy">$Crayon-v">tableCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-sy">(Crayon-s">'.table'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a5032f786714382-2">Crayon-t">varCrayon-h"> Crayon-sy">$Crayon-v">fixedColumnCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">$Crayon-v">tableCrayon-sy">.Crayon-e">cloneCrayon-sy">(Crayon-sy">)Crayon-sy">.Crayon-e">insertBeforeCrayon-sy">(Crayon-sy">$Crayon-v">tableCrayon-sy">)Crayon-sy">.Crayon-e">addClassCrayon-sy">(Crayon-s">'fixed-column'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891c9a5032f786714382-3">
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a5032f786714382-4">Crayon-sy">$Crayon-v">fixedColumnCrayon-sy">.Crayon-e">findCrayon-sy">(Crayon-s">'th:not(:first-child),td:not(:first-child)'Crayon-sy">)Crayon-sy">.Crayon-e">removeCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891c9a5032f786714382-5">
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a5032f786714382-6">Crayon-sy">$Crayon-v">fixedColumnCrayon-sy">.Crayon-e">findCrayon-sy">(Crayon-s">'tr'Crayon-sy">)Crayon-sy">.Crayon-st">eachCrayon-sy">(Crayon-t">functionCrayon-h"> Crayon-sy">(Crayon-v">iCrayon-sy">,Crayon-h"> Crayon-v">elemCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891c9a5032f786714382-7">Crayon-h">Crayon-sy">$Crayon-sy">(Crayon-r">thisCrayon-sy">)Crayon-sy">.Crayon-e">heightCrayon-sy">(Crayon-sy">$Crayon-v">tableCrayon-sy">.Crayon-e">findCrayon-sy">(Crayon-s">'tr:eq('Crayon-h"> Crayon-o">+Crayon-h"> Crayon-v">iCrayon-h"> Crayon-o">+Crayon-h"> Crayon-s">')'Crayon-sy">)Crayon-sy">.Crayon-e">heightCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a5032f786714382-8">Crayon-sy">}Crayon-sy">)Crayon-sy">;

二、样式文件里加入如下代码

Crayon-5c891c9a50338552964321" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">CSS
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891c9a50338552964321-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a50338552964321-2">2
Crayon-num" data-line="Crayon-5c891c9a50338552964321-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a50338552964321-4">4
Crayon-num" data-line="Crayon-5c891c9a50338552964321-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a50338552964321-6">6
Crayon-num" data-line="Crayon-5c891c9a50338552964321-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a50338552964321-8">8
Crayon-num" data-line="Crayon-5c891c9a50338552964321-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891c9a50338552964321-10">10
Crayon-num" data-line="Crayon-5c891c9a50338552964321-11">11
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891c9a50338552964321-1">.fixed-column Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a50338552964321-2">Crayon-h">Crayon-e ">positionCrayon-sy">:Crayon-h"> Crayon-i ">absoluteCrayon-sy">;
Crayon-line" id="Crayon-5c891c9a50338552964321-3">Crayon-h">Crayon-e ">displayCrayon-sy">:Crayon-h"> Crayon-i ">inline-blockCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a50338552964321-4">Crayon-h">Crayon-e ">widthCrayon-sy">:Crayon-h"> Crayon-i ">autoCrayon-sy">;
Crayon-line" id="Crayon-5c891c9a50338552964321-5">Crayon-h">Crayon-e ">border-rightCrayon-sy">:Crayon-h"> Crayon-i ">1pxCrayon-h"> Crayon-i ">solidCrayon-h"> Crayon-i ">#dddCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a50338552964321-6">Crayon-sy">}
Crayon-line" id="Crayon-5c891c9a50338552964321-7">Crayon-n">@media(min-width:768px) Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a50338552964321-8">Crayon-h">.fixed-column Crayon-sy">{
Crayon-line" id="Crayon-5c891c9a50338552964321-9">Crayon-h">Crayon-e ">displayCrayon-sy">:Crayon-h"> Crayon-i ">noneCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891c9a50338552964321-10">Crayon-h">Crayon-sy">}
Crayon-line" id="Crayon-5c891c9a50338552964321-11">Crayon-sy">}

大功告成,打开手机浏览器,查看效果

原文链接:https://www.f2er.com/bootstrap/238335.html

猜你在找的Bootstrap相关文章