JS+DIV+CSS排版布局實(shí)現(xiàn)美觀的選項(xiàng)卡效果
本文實(shí)例講述了JS+DIV+CSS排版布局實(shí)現(xiàn)美觀的選項(xiàng)卡效果。分享給大家供大家參考。具體如下:
這是一個(gè)基于JavaScript的簡(jiǎn)單選項(xiàng)卡代碼,陪新手練習(xí)一下Div+CSS排版的技巧,本選項(xiàng)卡可以繼續(xù)美化修飾完善,選項(xiàng)卡在目前在眾多網(wǎng)站上應(yīng)用廣泛,確實(shí)是一個(gè)很不錯(cuò)的網(wǎng)頁布局方法。
運(yùn)行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/js-div-css-pbbj-nav-demo/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>DIV CSS排版</title>
<style type="text/css">
<!--
body,ul{margin:0; padding:0; list-style:none; font:12px "宋體";}
.test {
width:500px;
margin:20px auto;
height:150px;
background:url("images/9zrgo3.jpg") repeat-x 0 33px;
}
.test ul li {
float:left;
padding:2px 1px 6px 1px;
background: url("images/11abdrs.jpg") no-repeat 0 0;
}
.test ul li a {
color:#000;
width:95px;
text-decoration:none;
display:block;
height:27px;
line-height:31px;
text-align:center;
overflow:hidden;
}
.test ul li a:hover{
color:#30F;
background:#FFF url("images/2vi1df8.jpg") repeat-x 0 0px;
}
.test ul li.yes {padding:0;border:none;}
.test ul li.yes a {
color:#30F;
width:112px;
height:35px;
line-height:40px;
display:block;
font-weight:bold;
margin-bottom:-5px;
background: url("images/27zgcqc.jpg") no-repeat 0px 0;
overflow:hidden;
}
.content {
line-height:50px;
text-align:center;
font-size:20px;
color:red;
height:112px;
border:#F8BE05 2px solid;
border-top:none;
clear:both;
background:#ECED78;
}
.no { display:none;}
-->
</style>
<script type="text/javascript" language="javascript">
function test_item(n){
var menu = document.getElementById("menu");
var menuli = menu.getElementsByTagName("li");
for(var i = 0; i< menuli.length;i++){
menuli[i].className= "";
menuli[n].className="yes";
document.getElementById("test"+ i).className = "no";
document.getElementById("test"+ n).className = "content";
}
}
</script>
</head>
<body>
<div class="test">
<ul id="menu">
<li class="yes" onclick="javascript:test_item(0);"><a href="#" onfocus="this.blur()">首頁</a></li>
<li onclick="javascript:test_item(1);"><a href="#" onfocus="this.blur()">連接一</a></li>
<li onclick="javascript:test_item(2);"><a href="#" onfocus="this.blur()">連接二</a></li>
<li onclick="javascript:test_item(3);"><a href="#" onfocus="this.blur()">連接三</a></li>
<li onclick="javascript:test_item(4);"><a href="#" onfocus="this.blur()">連接四</a></li>
</ul>
<div class="content" id="test0">
首頁內(nèi)容
</div>
<div id="test1" class="no">
連接一內(nèi)容
</div>
<div id="test2" class="no">
連接二內(nèi)容
</div>
<div id="test3" class="no">
連接三內(nèi)容
</div>
<div id="test4" class="no">
連接四內(nèi)容
</div>
</div>
</body>
</html>
希望本文所述對(duì)大家的JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
javascript Deferred和遞歸次數(shù)限制實(shí)例
你知道Deferred和遞歸次數(shù)限制嗎?如果還不知道,可以看看下面的實(shí)例,很好,適合新手朋友們2014-10-10
JS實(shí)現(xiàn)的數(shù)字格式化功能示例
這篇文章主要介紹了JS實(shí)現(xiàn)的數(shù)字格式化功能,結(jié)合實(shí)例形式分析了javascript針對(duì)數(shù)字與字符的相關(guān)運(yùn)算處理技巧,需要的朋友可以參考下2017-02-02
layui 根據(jù)后臺(tái)數(shù)據(jù)動(dòng)態(tài)創(chuàng)建下拉框并同時(shí)默認(rèn)選中的實(shí)例
今天小編就為大家分享一篇layui 根據(jù)后臺(tái)數(shù)據(jù)動(dòng)態(tài)創(chuàng)建下拉框并同時(shí)默認(rèn)選中的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-09-09
讓bootstrap的carousel支持滑動(dòng)滾屏的實(shí)現(xiàn)代碼
這篇文章主要介紹了讓bootstrap的carousel支持滑動(dòng)滾屏的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-11-11
js 靜態(tài)動(dòng)態(tài)成員 and 信息的封裝和隱藏
一下用面向?qū)ο蟮南嚓P(guān)概念來解釋js中的仿面向?qū)ο?,因?yàn)閖s中不像其他語言,不存在面向?qū)ο笳Z言的相關(guān)特性2011-05-05
微信小程序?qū)崿F(xiàn)比較功能的方法匯總(五種方法)
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)比較功能的方法,本文給大家列舉出五種方式,每種方法通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
使用JavaScript和HTML實(shí)現(xiàn)一個(gè)精美的計(jì)算器
計(jì)算器是我們?nèi)粘I钪薪?jīng)常使用的工具之一,可以幫助我們進(jìn)行簡(jiǎn)單的數(shù)學(xué)運(yùn)算,在本博文中,我將使用JavaScript編寫一個(gè)漂亮的計(jì)算器,并添加加減乘除功能,感興趣的同學(xué)可以自己動(dòng)手嘗試一下2023-09-09
微信小程序?qū)崿F(xiàn)虎年春節(jié)頭像制作
春節(jié)來臨之際,看到有網(wǎng)友分享了網(wǎng)頁版的虎年頭像制作工具。本文將為大家介紹一個(gè)虎年春節(jié)頭像制作小程序,文中的示例代碼講解詳細(xì),需要的可以參考一下2022-02-02

