html - 如何用纯css将三 Angular 形 "^"放在菜单栏下拉内容框的顶端?

标签 html css

我想将 css 制作的三 Angular 形放在子菜单内容框的顶端,如下图所示。

enter image description here

.menuH
{
background: -moz-linear-gradient(top, #858585 0%, #808080 24%, #727272 49%, #5f5f5f 51%, #707070 79%, #939393 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#858585), color-stop(24%,#808080), color-stop(49%,#727272), color-stop(51%,#5f5f5f), color-stop(79%,#707070), color-stop(100%,#939393)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #858585 0%,#808080 24%,#727272 49%,#5f5f5f 51%,#707070 79%,#939393 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #858585 0%,#808080 24%,#727272 49%,#5f5f5f 51%,#707070 79%,#939393 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #858585 0%,#808080 24%,#727272 49%,#5f5f5f 51%,#707070 79%,#939393 100%); /* IE10+ */
background: linear-gradient(to bottom, #858585 0%,#808080 24%,#727272 49%,#5f5f5f 51%,#707070 79%,#939393 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#858585', endColorstr='#939393',GradientType=0 ); /* IE6-8 */
    background-color:#d3d3d3;
    height: 36px;
    border: 1px solid #BBB;
    position:fixed;/*! for IE htc*/
    z-index:4;/*H2*/
    font-family: Arial, Helvetica, sans-serif;
    list-style: none;
    padding: 0;
}

.menuH li
{
    padding: 0;
    /*margin: 0;
    display: block; TODO: I am testing them if they can be removed. If can, remove them.*/
    float: left;
    height: 36px;
    position: relative;/*move it into .menuH if you want submenu to be positioned relative to the whole menu instead of this li element*/
}
.menuH li:hover, .menuH li.onhover
{
    background:#FFFFFF; 
}

ul.menuH a
{
    padding: 0 25px;
    line-height: 36px; /*Note: keep this value the same as the height of .menuH and .menuH li */
    font-size: 12px;
    font-weight: bold;
    color:#CCC;
    display: block;
    outline: 0;
    text-decoration: none;

}

.menuH ul a.arrow
{
    width: 0; 
    height: 0; 
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;

    border-bottom: 5px solid black;
}



.menuH a:hover
{
    color:#666;
}



/*Used to align a top-level item to the right*/        
.menuH .menuRight
{
    float: right;
    margin-right: 0px;
}



/*######sub level###########*/


ul.menuH ul
{
    width:200px;
    position: absolute;
    left: -9999px;
    border: 1px solid #DDD;
    border-top: 0; 
    background: #FFF;    
    text-align: left;
    list-style: none; margin: 0;  
    /*Following 1px(padding-right) will determine how much it is overlapped by the sub-sub-menu */
    padding: 0 1px 10px 0;   
}

.menuH li li
{
    float: none;
    white-space:nowrap;
    height: 26px;
}
.menuH li li:hover, .menuH li li.onhover
{
    background:#f7f7f7;
}
.menuH ul a
{
    padding: 0 20px;
    line-height: 26px;
    font-size: 0.9em;
    font-weight: normal;
    color:#666;
    text-align: left;
}

.menuH ul a:hover
{
    color:#333;
}

.menuH li:hover ul, .menuH li.onhover ul
{
    left: -1px;/*Use this property to change offset of the dropdown*/
    top: auto;
}

.menuH li:hover .dropToLeft, .menuH li.onhover .dropToLeft
{
    left: auto;
    right: -1px;
    top: auto;
}
.menuH ul ul
{
    border-top: 1px solid #DDD;
}

.menuH li:hover ul ul, .menuH li:hover ul ul ul, .menuH li:hover ul ul ul ul,
.menuH li.onhover ul ul, .menuH li.onhover ul ul ul, .menuH li.onhover ul ul ul ul
{
    left: -9999px;
    top:0;
}

.menuH li li:hover ul, .menuH li li li:hover ul, .menuH li li li li:hover ul,
.menuH li li.onhover ul, .menuH li li li.onhover ul, .menuH li li li li.onhover ul
{
    left: 200px;
}

/*####### special effects ##########*/

.decor1 
{
    -moz-border-radius: 3px; /* Firefox */
    -webkit-border-radius: 3px; /* Safari and Chrome */
    border-radius: 3px; /* Opera 10.5+, future browsers, and now also our behavior htc file */

    -moz-box-shadow: 0px 1px 4px #eee; /* Firefox */
    -webkit-box-shadow: 0px 1px 4px #eee; /* Safari and Chrome */
    box-shadow: 0px 1px 4px #eee; /* Opera 10.5+, future browsers and IE6+ using our behavior htc file */

}
.menuH ul 
{
    -moz-border-radius: 0px 0px 4px 4px;
    -webkit-border-radius: 0px 0px 4px 4px;
    border-radius: 0px 0px 4px 4px;

    -moz-box-shadow: 0px 6px 6px #CCC;
    -webkit-box-shadow: 0px 6px 6px #CCC;
    box-shadow: 0px 6px 6px #CCC;  

    /*for older IE browsers, the htc file fix will disable this feature when box-shadow was also applied.*/
    filter:alpha(opacity=90);


    /* Gradient background */
    background: -moz-linear-gradient(top, #FFFFFF, #EEEEEE);
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FFFFFF), to(#EEEEEE)); 
}

如何使用此菜单 css 在子菜单的顶端获得三 Angular 形?我已经尝试了很多,但没有得到问题中上图所示的三 Angular 形。

编辑:我的Jsfiddle代码如下 http://jsfiddle.net/8p9hu6hd/18/

最佳答案

您可以将 CSS 属性添加到 <div>在内容框上方。
这是 HTML:

<div id="triangle"></div>

这是CSS

#triangle {
    width: 0;
    height: 0;

    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 100px solid red;
}

在此处阅读有关 CSS 几何形式的更多信息:
http://css-tricks.com/examples/ShapesOfCSS/

关于html - 如何用纯css将三 Angular 形 "^"放在菜单栏下拉内容框的顶端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25382767/

相关文章:

html - 边界半径和填充在 IE11 中不起作用

php - 如何在 php 和 html 上隐藏 div

html - 缺失的前导元素

html - 在 Internet Explorer 中对齐 iframe

jquery - 如果 div 有 2 个其他类,如何添加类

css - 具有 2 行和内联形式的 Bootstrap 4 导航栏

html - CSS:设置div的背景颜色填充

javascript - 为什么这个不能运行?

打印时 HTML 将表格推到下一页

html - CSS 动画(翻转)不适用于 Iphone/Safari