带图像的Html下拉菜单

时间:2014-03-31 12:54:37

标签: html css menu

我正在尝试在HTML中构建一个类似于图像的菜单。我不知道该怎么做。我想过ul这是最常见的,但是我将如何画线呢?

如何构建我知道的菜单。问题是图像和水平线。

Menu

1 个答案:

答案 0 :(得分:2)

Demo Fiddle

您可以使用:before:after psuedo元素绘制直线和箭头,这是一个基本示例:

HTML

<ul>
    <li>
        <img src='http://openclipart.org/people/TzeenieWheenie/TzeenieWheenie_Small_blue_i_info_button.svg' />Item
        <ul>
            <li>Sub Item</li>
        </ul>
    </li><li>
        <img src='http://openclipart.org/people/TzeenieWheenie/TzeenieWheenie_Small_blue_i_info_button.svg' />Item
        <ul>
            <li>Sub Item</li>
        </ul>
    </li>
</ul>

CSS

ul, li {
    list-style:none;
    margin:0;
    padding:0;
}
ul {
    background: rgb(238, 238, 238);
    /* Old browsers */
    /* IE9 SVG, needs conditional override of 'filter' to 'none' */
    background: url(data:image/svg+xml;
    base64, PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNjY2NjY2MiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
    background: -moz-linear-gradient(top, rgba(238, 238, 238, 1) 0%, rgba(204, 204, 204, 1) 100%);
    /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(238, 238, 238, 1)), color-stop(100%, rgba(204, 204, 204, 1)));
    /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgba(238, 238, 238, 1) 0%, rgba(204, 204, 204, 1) 100%);
    /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgba(238, 238, 238, 1) 0%, rgba(204, 204, 204, 1) 100%);
    /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgba(238, 238, 238, 1) 0%, rgba(204, 204, 204, 1) 100%);
    /* IE10+ */
    background: linear-gradient(to bottom, rgba(238, 238, 238, 1) 0%, rgba(204, 204, 204, 1) 100%);
    /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#cccccc', GradientType=0);
    /* IE6-8 */
    padding:0 20px;
    border-bottom:1px solid green;
}
li {
    display:inline-block;
    position:relative;
    padding:40px;
    cursor:pointer;
    font-family:arial;
}
li img {
    width:30px;
    height:30px;
    display:block;
    margin:-30px 0 40px 0;
}
li:before {
    display:inline-block;
    content:'';
    top:50px;
    left:0;
    width:100%;
    border-top:1px solid #808080;
    position:absolute;
}
li:after {
    display:none;
}
li:hover:after {
    display:inline-block;
    content:'';
    top:50px;
    left:40%;
    width: 0px;
    height: 0px;
    border-style: solid;
    border-width: 10px 10px 0 10px;
    border-color: green transparent transparent transparent;
    position:absolute;
}
ul li:hover ul {
    display:block;
}
ul ul {
    display:none;
    position:absolute;
    top:140px;
    left:0px;
    background:rgba(255, 255, 255, .5);
    border:0;
    padding:0;
}
ul ul li:before, ul ul li:after {
    display:none;
}
ul ul li {
    display:block;
    font-family:tahoma;
    font-size:12px;
    color:green;
    padding:10px 30px;
    width:100px;
    font-weight:bold;
    border-bottom:1px solid #c0c0c0;
    text-transform:uppercase;
}