關于ecshop純DIV+CSS實現京東商城分類(不需jquery)適合,具體如下:
第一步:在你所用的模板的css文件中加上以下代碼
.my_left_category{
width:211px;
font-size:12px;
}
.my_left_category h1{
background-image:url(images/spring_06.jpg);
height:20px;
background-repeat:no-repeat;
font-size:14px;
font-weight:bold;
padding-left:15px;
padding-top:8px;
margin:0px;
color:#FFF;
}
.my_left_category .my_left_cat_list{
width:209px;
border-color:#ce2020;
border-style:solid;
border-width:0px 1px 1px 1px;
line-height:13.5pt;
}
.my_left_category .my_left_cat_list h2 {
margin:0px;
padding:3px 5px 0px 9px;
}
.my_left_category .my_left_cat_list h2 a{
color:#d6290b;
font-weight:bold;
font-size:14px;
line-height:22px;
}
.my_left_category .h2_cat{
width:209px;
height:26px;
background-image:url(images/my_menubg.gif);
background-repeat:no-repeat;
line-height:26px;
font-weight:normal;
color:#333333;
position:relative;
}
.my_left_category a{
font:12px;
text-decoration:none;
color:#333333;
}
.my_left_category a:hover{
text-decoration:underline;
color:#ff3333;
}
.my_left_category h3{
margin:0px;
padding:0px;
height:26px;
font-size:12px;
font-weight:normal;
display:block;
padding-left:8px;
}
.my_left_category h3 span{color:#999999; width:145px; float:right;}
.my_left_category h3 a{ line-height:26px;}
.my_left_category .h3_cat{
display:none;
width:204px;
position:absolute;
left:184px;
margin-top:-26px;
cursor:auto;
}
.my_left_category .shadow{
position:inherit;
background:url(images/shadow_04.gif) left top;
width:204px;
}
.my_left_category .shadow_border{
position:inherit;
width:200px;
border:1px solid #959595; margin-top:1px;
border-left-width:0px;
background:url(images/shadow_border.gif) no-repeat 0px 21px;
background-color:#ffffff;
margin-bottom:3px
}
.my_left_category .shadow_border ul{margin:0; padding:0; margin-left:15px}
.my_left_category .shadow_border ul li {
list-style:none;
padding-left:10px;
background-image:url(images/my_cat_sub_menu_dot.gif);
background-repeat:no-repeat;
background-position:0px 8px;
float:left;
width:75px;
height:26px;
overflow:hidden;
}
.my_left_category .active_cat{ z-index:99;background-position:0 -25px;cursor:pointer;}
.my_left_category .active_cat h3 { font-weight:bold}
.my_left_category .active_cat h3 span{ display:none;}
.my_left_category .active_cat div{display:block;}
第二步:模板文件夾的library/category_tree.lbi內容改為:
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<div class="my_left_category">
<h1>商品分類</h1>
<div class="my_left_cat_list">
{assign var="pre_item_level" value=-1}
<!--{foreach from=cat_list(0,0,false,3,false) item=cat}-->
{if $cat.level lt 2 && $pre_item_level gt 0}
</ul></div></div></div></div>
{/if}
{if $cat.level eq 0}
<h2><a href="{$cat.url}">{$cat.name|escape:html}</a></h2>
{elseif $cat.level eq 1}
<div class="h2_cat" onmouseover="this.className='h2_cat active_cat'" onmouseout="this.className='h2_cat'">
<h3><SPAN> - {$cat.cat_desc|escape:html}</SPAN><a href="{$cat.url}">{$cat.name|escape:html}</a></h3>
<div class="h3_cat">
<div class="shadow">
<div class="shadow_border">
<ul>
{elseif $cat.level eq 2}
<li><a href="{$cat.url}">{$cat.name|escape:html}</a></li>
{/if}
{assign var="pre_item_level" value=$cat.level}
<!--{/foreach}-->
{if $pre_item_level gt 0}
</ul></div></div></div></div>
{/if}
</div>
</div>
第三步:把用到的圖片拷貝到模板文件夾的images目錄
ok完成!
注:
京東的二級分類名稱旁邊列了2個三級分類名稱(灰色),作為三級分類的提示。參考其他網友的做法,這里使用二級類的描述字段cat_desc來實現,【用程序去調取二級類下的前兩個三級分類完全是化簡為煩的事情?!康@個效果要修改 /includes/lib_common.php 才生效的,當然,不修改也不會出錯,只是沒有顯示罷了。
修改方法:在/includes/lib_common.php 的cat_list函數中找到
$sql = "SELECT c.cat_id, c.cat_name,
修改為
$sql = "SELECT c.cat_id, c.cat_name, c.cat_desc,
補充一下:
在firefox等瀏覽器中,如果展開的部分被遮擋(由于父級容器overflow:hidden引起),在.my_left_category的樣式中加上 position:absolute即可。
新聞熱點
疑難解答