服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > ecshop教程 >

ecshop纯DIV+CSS实现京东商城分类(不需jquery)适合

时间:2010-11-21 10:56来源: 作者: 点击:
ecshop纯DIV+CSS实现京东商城分类

第一步:在你所用的模板的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即可。

(责任编辑:最模板)
顶一下
(2)
40%
踩一下
(3)
60%
------分隔线----------------------------
栏目列表
热点内容