Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
ue 橫向滾動(dòng)
<div class="slide-box">
<div class="slide-within">
<div class="slide-item" v-for="(item,index) in listData" :key="index">{{ index + item.label }}</div>
</div>
</div>
.slide-box {
margin-top: 200px;
overflow: hidden;
}
.slide-within {
display: -webkit-box;
overflow-x: scroll;
-webkit-overflow-scrolling: touch;
padding-bottom: 10px;
margin-bottom: -10px;
}
.slide-item {
width: 200px;
height: 200px;
border: 1px solid #ccc;
margin-right: 30px;
}
js 代碼
本篇文章主要給大家介紹一下如何使用html+css完成二級(jí)橫向以及豎向菜單導(dǎo)航制作;菜單導(dǎo)航是網(wǎng)站建設(shè)中最常用的一塊了,基本每個(gè)網(wǎng)站內(nèi)都會(huì)有個(gè)導(dǎo)航菜單,用鼠標(biāo)劃過(guò)還可以有下拉子菜單。
由上圖我們可以看出,該圖包含一個(gè)橫向?qū)Ш綏l,然后鼠標(biāo)經(jīng)過(guò)橫向?qū)Ш綏l之后,子導(dǎo)航顯示出來(lái)。
我們這里主要用到的知識(shí)點(diǎn)就是列表標(biāo)簽(ul、dl)的使用、浮動(dòng)(float)的使用、絕對(duì)定位(absolute)及鼠標(biāo)經(jīng)過(guò)(hover)的效果。
1、列表標(biāo)簽ul、dl(我們使用ul、dl來(lái)創(chuàng)建同類型的導(dǎo)航元素內(nèi)容,通過(guò)設(shè)置css樣式來(lái)達(dá)到圖片所示效果);
2、浮動(dòng)元素float(每個(gè)導(dǎo)航元素我們需要使用float:left;讓其左對(duì)齊,這里涉及到了我們之前講解的如何清除浮動(dòng)的影響);
3、絕對(duì)定位absolute(對(duì)于子導(dǎo)航我們要使用絕對(duì)定位來(lái)讓其浮動(dòng)在上級(jí)有定位元素的下方,不占據(jù)元素空間)
4、鼠標(biāo)經(jīng)過(guò)hover(使用css的鼠標(biāo)經(jīng)過(guò)元素(hover)效果,配合display的none(隱藏)和block(顯示)來(lái)實(shí)現(xiàn)子菜單的顯示與隱藏)
具體的實(shí)現(xiàn)html代碼以及css代碼就如下圖所示:
還有一個(gè)縱向菜單導(dǎo)航原理跟橫向的類似,只需簡(jiǎn)單調(diào)整一下css代碼即可。
html代碼跟橫向一樣,這里就不再貼圖,具體的實(shí)現(xiàn)圖片效果以及css代碼就如下圖所示:
好了,本篇文章就給大家說(shuō)到這里,大家自己動(dòng)手寫一下看能不能寫出一樣的頁(yè)面效果出來(lái),也可以找一些類似的頁(yè)面自己練習(xí)一下,有需要源碼的可以直接私信我即可。
每日金句:每天收獲小進(jìn)步,積累起來(lái)就是大進(jìn)步;每天收獲小幸福,積攢起來(lái)便成大幸福。喜歡我的文章的小伙伴記得關(guān)注一下哦,每天將為你更新最新知識(shí)。
果
.pure-table-wrapper-div {
overflow-x: scroll;
}
table.pure-table th:first-child,
table.pure-table td:first-child {
position: sticky;
left: 0;
z-index: 1;
background-color: aliceblue;
}
.pure-table-wrapper-div:
這個(gè)類名應(yīng)用于包裹表格的 div 元素。它的樣式規(guī)則如下:
overflow-x: scroll;: 當(dāng)內(nèi)容寬度超出容器寬度時(shí),顯示水平滾動(dòng)條。這允許用戶在需要時(shí)水平滾動(dòng)查看表格的所有列。
示例 HTML 結(jié)構(gòu):
<div class="pure-table-wrapper-div"> <table class="pure-table"> <!-- 表格內(nèi)容 --> </table> </div>
table.pure-table th:first-child, table.pure-table td:first-child: 這兩個(gè)選擇器分別針對(duì) .pure-table 類的表格中的第一個(gè)表頭單元格(<th>)和第一個(gè)數(shù)據(jù)單元格(<td>)。
它們定義的樣式規(guī)則如下:
position: sticky;: 使用黏性定位。黏性定位元素在滾動(dòng)時(shí)會(huì)根據(jù)設(shè)置的 top、bottom、left 或 right 屬性值在特定位置 "粘附"。在本例中,由于定義了 left: 0;,這些元素會(huì)在左側(cè)邊緣粘附。 left: 0;: 在元素滾動(dòng)到視口左側(cè)邊緣時(shí)使其粘附。與 position: sticky; 結(jié)合使用。
z-index: 1;: 設(shè)置元素的堆疊順序。值越大,元素越靠前。在這種情況下,將第一個(gè)單元格設(shè)置為 z-index: 1 可確保它在其他表格單元格之上。
background-color: aliceblue;: 為匹配的單元格設(shè)置背景顏色。這可以增強(qiáng)視覺(jué)效果,使粘附的單元格與其他單元格區(qū)分開(kāi)。
這段 CSS 代碼的主要目的是實(shí)現(xiàn)表格的水平滾動(dòng),并固定第一列,使其在水平滾動(dòng)時(shí)保持可見(jiàn)。同時(shí),為第一列的單元格設(shè)置了背景顏色以增強(qiáng)視覺(jué)效果。
總的來(lái)說(shuō)是:
使用 position: sticky; 來(lái)固定第一列。在 table.pure-table th:first-child 中設(shè)置了 position: sticky; 和 left: 0;,并將 z-index 設(shè)為 1,以確保第一列在滾動(dòng)時(shí)會(huì)固定在屏幕上方。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="./purecss@3.0.0.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文檔</title>
<style>
.pure-table-wrapper-div {
overflow-x: scroll;
}
table.pure-table th:first-child,
table.pure-table td:first-child {
position: sticky;
left: 0;
z-index: 1;
background-color: aliceblue;
}
</style>
</head>
<body>
<div class="pure-table-wrapper-div">
<table class="pure-table">
<thead>
<tr>
<th>#</th>
<th>品牌</th>
<th>型號(hào)</th>
<th>隨機(jī)字符串</th>
<th>說(shuō)明</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>本田</td>
<td>雅閣</td>
<td>2009-QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td>這是一段中文說(shuō)明文字。</td>
</tr>
<tr>
<td>2</td>
<td>豐田</td>
<td>凱美瑞</td>
<td>2012-QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td>這是一段中文說(shuō)明文字。</td>
</tr>
<tr>
<td>3</td>
<td>現(xiàn)代</td>
<td>領(lǐng)動(dòng)</td>
<td>2010-QWERTYUIOPASDFGHJKLZXCVBNM</td>
<td>這是一段中文說(shuō)明文字。</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
要去除表格中最后一列中文的換行效果,可以使用 CSS 的 white-space 屬性,將其設(shè)置為 nowrap,這樣文字就不會(huì)自動(dòng)換行了。
添加了以下 CSS 樣式:
table.pure-table td:last-child,
table.pure-table th:last-child {
white-space: nowrap;
}
這樣,最后一列中文就不會(huì)自動(dòng)換行了。其中 table.pure-table td:last-child 和 table.pure-table th:last-child 選擇器用于指定表格中的最后一列單元格,white-space: nowrap; 則是將 white-space 屬性設(shè)置為 nowrap,禁止其自動(dòng)換行。
position: sticky 是 CSS 中的一種定位方式,可以實(shí)現(xiàn)元素在滾動(dòng)時(shí)固定在屏幕上,直到其滾動(dòng)到指定位置。相對(duì)于 position: fixed,position: sticky 有以下優(yōu)點(diǎn)和缺點(diǎn):
優(yōu)點(diǎn):
缺點(diǎn):
綜上所述,position: sticky 是一種靈活且易用的定位方式,具有很多優(yōu)點(diǎn),但在兼容性和性能方面有一些缺點(diǎn)需要注意。如果要在項(xiàng)目中使用 position: sticky,需要在兼容性和性能方面進(jìn)行綜合考慮,以確保其正常運(yùn)行和良好的用戶體驗(yàn)。
.pure-table-wrapper-div {
overflow-x: scroll;
margin-left: 5em;
}
table.pure-table tr td:first-child,
table.pure-table tr th:first-child {
position: absolute;
width: 5em;
left: 0;
}
這段 CSS 代碼主要是為了實(shí)現(xiàn)固定表格首列和橫向滾動(dòng)效果,并且在表格首列添加了固定的寬度。
首先,.pure-table-wrapper-div 是一個(gè)包裹表格的 div 元素,通過(guò)設(shè)置 overflow-x: scroll,實(shí)現(xiàn)了橫向滾動(dòng)的效果。同時(shí),通過(guò)設(shè)置 margin-left: 5em,在左側(cè)添加了 5em 的空白,使得表格不會(huì)緊貼在頁(yè)面最左側(cè),美觀性更好。
接著,table.pure-table tr td:first-child 和 table.pure-table tr th:first-child 選擇器用于選中表格中的第一列單元格,使用 position: absolute 將其從文檔流中脫離,并使用 width: 5em 指定其寬度為 5em,然后通過(guò) left: 0 將其固定在表格最左側(cè)。
這樣,表格的首列就被固定在了左側(cè),不會(huì)隨著表格的滾動(dòng)而移動(dòng),同時(shí)也添加了固定的寬度,使得表格整體更加美觀和易讀。
總的來(lái)說(shuō),這段 CSS 代碼實(shí)現(xiàn)了表格的固定首列和橫向滾動(dòng)效果,同時(shí)也為表格首列添加了固定的寬度,提高了表格的可讀性和美觀性。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="./purecss@3.0.0.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style>
.pure-table-wrapper-div {
overflow-x: scroll;
margin-left: 5em;
}
table.pure-table tr td:first-child,
table.pure-table tr th:first-child {
position: absolute;
width: 5em;
left: 0;
}
</style>
<div class="pure-table-wrapper-div">
<table class="pure-table">
<thead>
<tr>
<th>#</th>
<th>Make</th>
<th>Model</th>
<th>隨機(jī)數(shù)</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Honda</td>
<td>Accord</td>
<td>2009-QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td>2</td>
<td>Toyota</td>
<td>Camry</td>
<td>2012-QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
<tr>
<td>3</td>
<td>Hyundai</td>
<td>Elantra</td>
<td>2010-QWERTYUIOPASDFGHJKLZXCVBNM</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
CSS 中的 position: absolute 定位方式可以讓元素脫離文檔流,并相對(duì)于它的最近的非 static 定位祖先元素進(jìn)行定位。相對(duì)于其他定位方式,position: absolute 有以下優(yōu)點(diǎn)和缺點(diǎn):
優(yōu)點(diǎn):
缺點(diǎn):
綜上所述,position: absolute 是一種靈活且強(qiáng)大的定位方式,可以實(shí)現(xiàn)很多獨(dú)特的布局效果,但需要注意它可能會(huì)對(duì)頁(yè)面布局和元素位置產(chǎn)生影響。在使用時(shí),需要根據(jù)具體情況進(jìn)行綜合考慮,并在保證頁(yè)面布局和元素位置正確的前提下,盡可能地利用其優(yōu)點(diǎn)實(shí)現(xiàn)更好的頁(yè)面效果。
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。