【问题标题】:CSS - positioning navigation titleCSS - 定位导航标题
【发布时间】:2014-05-20 22:27:35
【问题描述】:

我想知道如何定位导航标题,以便我的下拉菜单可以工作.. 下图是我完美定位的一个链接,通过 padding-left 分隔,设置为 80 px;奇怪的是,我的下拉类别也被填充了,留下了额外的空间,这使得它看起来非常难看。我的下拉菜单链接分为两行,虽然它只有一个链接。我该如何解决这个问题?我也尝试了保证金,没有什么真正改变。我希望它是这样的第三张图片..

图片一 - 我想要的导航定位:

http://i61.tinypic.com/2cshw7q.png

图二 - 我的下拉问题:

http://i60.tinypic.com/2z4037c.png

图三——我想要的样子:

http://i60.tinypic.com/1252ejo.png

我怎样才能做到这一点?

编辑!

我的 CSS 代码:

#menu 
{
clear:both;
position: relative;
width: 100%;
height:30px;
background: rgb(38,42,53); /* Old browsers */
background: -moz-linear-gradient(top, rgba(38,42,53,1) 0%, rgba(40,45,63,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(38,42,53,1)), color-stop(100%,rgba(40,45,63,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#262a35', endColorstr='#282d3f',GradientType=0 ); /* IE6-9 */
}

ul#menu {
    margin:0;
    padding:0;
    list-style-type: none;
    text-transform: uppercase;
    font-size: 15px;
}


    ul#menu li{
    position: relative; 
    display:inline-block;
    /*float:left;*/
    margin:0;
    padding:0;
    }


ul#menu li a{
display:block;
float:left;
color:#84FD00;                /* #874B46 */
text-decoration:none;
padding-left: 80px;
padding-top: 5px;
}

ul#menu li ul {
    margin-top:20px;
    position: absolute;
    -webkit-box-shadow: none;
    -moz-box-shadow: none;
    box-shadow:none;
    opacity: 0;
    visibility: 0;
    padding-left: 30px;
}

ul#menu li ul li {
    background: rgb(38,42,53); /* Old browsers */
background: -moz-linear-gradient(top, rgba(38,42,53,1) 0%, rgba(40,45,63,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(38,42,53,1)), color-stop(100%,rgba(40,45,63,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(38,42,53,1) 0%,rgba(40,45,63,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#262a35', endColorstr='#282d3f',GradientType=0 ); /* IE6-9 */
    color: #8BA8C5;
    height: 40px;
    }

ul#menu li  ul li:hover { 

    background: #666; 

    }

ul#menu li:hover ul {
    display: block;
    opacity: 1;
    visibility: visible;
    margin-right:20px;
    }

【问题讨论】:

  • ....代码? HTML、CSS、jsfiddle.net?
  • 请提供代码示例
  • 我添加了 CSS 代码。

标签: html css navigation positioning


【解决方案1】:

将下拉列表 ul 设置为 text-align: left; - 这应该在左侧显示文本。由于某种原因,您的文本右对齐...

【讨论】:

  • 尝试使用 ul li 或 ul li a 进行文本对齐。您甚至可以尝试在 text-align 样式的末尾添加 !important
猜你喜欢
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-29
  • 2016-08-10
  • 1970-01-01
相关资源
最近更新 更多