css - 标题不断移入导航栏(Bootstrap)

标签 css twitter-bootstrap responsive

我有一个导航栏,我有一些文本直接位于图像前面导航栏上方的正下方。此图像是响应式的,因此它会根据屏幕的大小进行缩放。但是,当我将屏幕调整到最小尺寸(即它在移动设备上的尺寸)时,图像会停留在一个地方,但通常固定在图像前面的文本会向上推,在导航栏后面。你能帮忙解释一下这是为什么吗?这是我的代码。

HTML

<header>
    <!--Navigation Secton-->
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#"> Anna's Portfolio</a>
            </div>
            <ul class="nav navbar-nav navbar-right">
                <li class="active"><a href="#"> About</a></li>    
                <li><a href="#">Works</a></li>   
                <li><a href="#">Talk To Me</a></li>        
            </ul>
        </div>
    </nav>
</header>
<body>   
    <!-- Top Image, Title Text-->
    <div class="container-fluid">
        <div class="row">
            <img class="image img img-responsive" src="http://www.qerja.com/journal/wp-content/uploads/CODING.jpg">
            <div class="text">
                <h1>Anna's Portfolio</h1>
            <h2>Come Inside.</h2>
          </div>
        </div>
    </div>

    <!--About, Mission-->
    <div class="container-fluid">
        <div class="row">
            <div class="about">
                <h2>About Me</h2>
                <p>My name is Anna Gibson and I'm a web developer<br> who seeks to tell the stories of the marginalized.<br> I'm a staunch advocate for those who struggle with<br> their mental health and I hope that I can create apps<br> that will help people with their mental health as apps<br> have helped me. </p>
            </div>
        </div>
    </div>
</body>
<footer></footer>
</html>

CSS

.navbar-brand {
    position:relative;
    bottom:70px;
    text-align:right;  
}

.image {
    position:relative;
    width:100%;
    padding-top:0;
    height:200px;
}

.text {
    text-align:center;
    position:relative;
    bottom:400px;
    color:white; 
    font-family:;
    font-size:24px;    
}

非常感谢,如果有任何不清楚的地方,请告诉我。

最佳答案

由于 bottom:400px,文本推到导航栏后面; .text 类的问题

您需要一些 HTML 和 CSS 修复

HTML

<header>
<!--Navigation Secton-->
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span> 
                </button>
                <a class="navbar-brand" href="#">Anna Portfolio</a>
            </div>
            <div class="collapse navbar-collapse" id="myNavbar">
                <ul class="nav navbar-nav navbar-right">
                <li class="active"><a href="#"> About</a></li>    
                <li><a href="#">Works</a></li>   
                <li><a href="#">Talk To Me</a></li>        
                </ul>
            </div>
        </div>
    </nav>
</header>
<body>   
    <!-- Top Image, Title Text-->
    <div class="container-fluid">
        <div class="row">
            <div class="main-section">
                <img class="image img img-responsive" src="http://www.qerja.com/journal/wp-content/uploads/CODING.jpg">
                <div class="text">
                    <h1>Anna's Portfolio</h1>
                    <h2>Come Inside.</h2>
                </div>
            </div>
        </div>
    </div>
    <!--About, Mission-->
    <div class="container-fluid">
        <div class="row">
            <div class="about">
                <h2>About Me</h2>
                <p>My name is Anna Gibson and I'm a web developer<br> who seeks to tell the stories of the marginalized.<br> I'm a staunch advocate for those who struggle with<br> their mental health and I hope that I can create apps<br> that will help people with their mental health as apps<br> have helped me. </p>
            </div>
        </div>
    </div>
</body>

CSS

.navbar-brand {
position:relative;
bottom:70px;
text-align:right;  
}

.main-section{
  position: relative;
}

.image {
    position:relative;
    width:100%;
    padding-top:0;
    height:200px;
}

.text {
text-align:center;
position:absolute;
color:white; 
font-family:;
font-size:24px;   
left:0;
right:0;
top: 0;
bottom: 0;
margin:auto;
}

Link for reference

希望这有帮助..

关于css - 标题不断移入导航栏(Bootstrap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45157024/

相关文章:

html - 需要 CSS 帮助 |悬停图像 |放大效果

css - Angular 响应式表单模板

html - 如何阻止 Sticky Footer 覆盖内容...?

angularjs - 将 Bootstrap 工具提示与 AngularJS 结合使用

javascript - 选中所有复选框时取消选中复选框

CSS 使外部元素固定职责

javascript - 使用 View 框的响应式 SVG

reactjs - 如何使React Material-UI中的GridList组件响应式

html - 如何实现显示:table div with additional,合并行?

javascript - Bootstrap 滚动 spy 不工作和导航菜单按钮导致标题重新加载