【问题标题】:Extending the sides of my nav bar in CSS/HTML (just like the header)在 CSS/HTML 中扩展导航栏的两侧(就像标题一样)
【发布时间】:2013-07-28 06:07:08
【问题描述】:

我从昨天开始一直在寻找解决方案,但找不到,或者找不到合适的关键字来搜索。

所以我的网站上有一个标题,就像这是一个标题,我很好地居中并扩展了它的背景颜色。

现在我发现了如何制作一个漂亮的交互式/有光泽的导航栏作为页脚,但我在顶部使用它,问题是我还想扩展它的大小,但它只是居中而不扩展。我将在屏幕截图中显示此内容并发布我的代码。

另外:我希望我的盒子居中,它包含在一个名为 #main_inner_area 的 div 中。

注意:导航栏在 CSS/HTML 代码中仍称为 #footer。我想扩展导航栏的两侧,就像我的标题的背景颜色扩展到全宽一样。 我的截图:i41 DOT tinypic DOT com SLASH 2qk6mmt.png(抱歉,如果没有screenie很难解释)

HTML:

<div id="main_area">
    <header> 
     <h1>This is a header</h1>
    </header>
    <div id="footer">long code for layout navbar</div>

    <div id="main_inner_area">
        <article>d       fsdf sdf sdf dsf dsf dsf</article>
    </div>
</div>

CSS:

*{
padding: 0px;
margin: 0px;
}
#main_area{
    background:#4863A0;
    display: block;
    text-align: left;


}
header {

height:100px;
background: #4863A0;
color:white;
border:none;
width:700px;
margin: 0 auto;


}



#footer{

    width:700px;
            top:100px;
    margin:0 auto;
    padding:0;
    left:0;
    right:0;

            margin: 0 auto;
    height: 40px;
            border-radius:7px 7px 7px 7px;
    font-family:Arial;
    text-shadow: 1px 1px 1px black; /*h,v,blur,color */
    /* glass effect */
    border-bottom: 1px solid rgba(0,0,0,0.3);
    background: rgba(0,0,0,0.5);
    /*inset = inner shadow ----------- this just creates multiple shadows*/
    /*top border, top white section, overlay top white, bottom*/
    box-shadow:  inset 0px -2px rgba(255,255,255,0.3),
         inset 0px -15px 20px rgba(0,0,0,0.2),
         inset 0 -10px 20px rgba(255,255,255,0.25),
         inset 0 15px 30px rgba(255,255,255,0.3); 
}

#main_inner_area{
            float: left;
            width:735px;
            margin:25px 0px 10px 0px; 

}

article{

        background: rgba(255,255,255, 0.5);
        border: 1px solid #4863A0;
        margin:0px;
        margin-bottom: 10px;
        padding: 15px;
        font-family: Tahoma;
        font-size: 14px;
        text-align:left;
        display:block;
        width:700px;
        height:auto;
        border-radius: 7px 7px 7px 7px;     

}

附:我真的很感激。我是一名 18 岁的学生,想在学习之外学习一些额外的东西。

【问题讨论】:

  • 你到底想在标题中扩展什么?

标签: html css extend navbar edges


【解决方案1】:

要使您的标题动态化,只需从中删除width 属性(以及从#footer 中删除)。如果您将其设置为固定值,它当然无法缩放。

要将article 居中,请使用margin-left: auto; margin-right: auto;

更新:(拉伸导航栏)

CSS 变化

#footer {
    width: auto;
}

#footer .links {
    width: 700px;
    margin: 0 auto;
}

HTML 更改:

<div id="footer">
    <div class="links">long code for layout navbar</div>
</div>

http://jsfiddle.net/UKYDb/1/

【讨论】:

  • 标题很好,我使用了 margin: 0 auto;为了那个原因。标题很好地居中,并且它的背景颜色很好地扩展了。我也想要#footer 元素(现在是我的导航栏)。
  • @user1842140 您的导航栏以我为中心。我不太明白你的问题是什么。要使文章居中,您必须使容器足够大,以便它实际上可以相对居中。所以在#main_inner_area 中设置width: 100%;。见这里:jsfiddle.net/UKYDb
  • 居中现在工作了。有什么方法可以让导航栏扩展到整个宽度,而无需将按钮也拉伸到屏幕的左侧和右侧?
  • @user1842140 要像这样拉伸导航栏,你必须给它一个完整的宽度(删除宽度属性或width: auto;)并将内容存储在宽度为 700px 的子元素中;查看代码的更新答案。
  • id 给你 +rep 但我不能:((没有足够的)
【解决方案2】:

我不确定您所说的“扩展”是什么意思,但您正在为所有内容设置固定的宽度和高度:

#footer {
width: 700px;
height: 40px;
...
}

尝试对 CSS 代码中的所有内容使用百分比而不是固定宽度。

width: 100%;

【讨论】:

  • 扩展我的意思是我的导航栏保持在我的页面的中心。并且它的侧面不会延伸到屏幕的整个宽度。 width100% 只是使导航栏从屏幕的最左侧开始并向右延伸。我希望我的按钮保持在中心..
  • 你在用text-align: center;吗?
猜你喜欢
  • 2019-02-15
  • 2017-07-22
  • 1970-01-01
  • 1970-01-01
  • 2015-09-15
  • 2013-09-01
  • 2015-07-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多