简体   繁体   English

bootstrap-如何在响应图像上放置文本

[英]bootstrap - how to position text over responsive image

I am trying to get this layout 我正在尝试获得此布局

在此处输入图片说明

I've used this code for the background image 我已经将此代码用于背景图片

<div class="container-fluid" style="padding: 0px;">
        <img class="img-responsive center-block header1" src="images/header.jpg" />
</div>

After that I don't know how to use bootstrap to position the logo or the navbar over the background image like given in the above image. 之后,我不知道如何使用引导程序将徽标或导航栏放置在背景图像上,如上图所示。

Can anyone give me which bootstrap class or tag is going to be used? 谁能给我使用哪个引导程序类或标记? or will I have to use custom css? 还是我必须使用自定义CSS?

Thanks in advance. 提前致谢。

Try the below, 试试下面的,

You can set the background-image using css..Also i will recommend you to use this because there will be issues if you make the elements absolute in responsive. 您可以使用css设置background-image我也建议您使用此图像,因为如果您将元素设置为absolute响应式会出现问题。

 .img-full { height: 300px; background-image: url('http://www.aegisworld.com/wp-content/uploads/2013/06/65-3.jpg'); background-repeat: no-repeat; background-position: center; background-size: 100%; } .navbar { margin-top: 20px; } .navbar.navbar-default { background-color: transparent; border-color: transparent; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <div class="img-full"> <div class="container"> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Project name</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="#">Home</a> </li> <li><a href="#">About</a> </li> <li><a href="#">Contact</a> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a> </li> <li><a href="#">Another action</a> </li> <li><a href="#">Something else here</a> </li> <li role="separator" class="divider"></li> <li class="dropdown-header">Nav header</li> <li><a href="#">Separated link</a> </li> <li><a href="#">One more separated link</a> </li> </ul> </li> </ul> </div> <!--/.nav-collapse --> </div> <!--/.container-fluid --> </nav> </div> </div> 

It's not a Bootstrap feature, you have to apply position:relative; 这不是Bootstrap功能,您必须应用position:relative; to container DIV, and then using positition:absolute; 到容器DIV,然后使用positition:absolute; with appropriate top and left/right offset for inner ones. 对于内部的顶部和左侧/右侧偏移适当。

<div class="container-fluid" style="padding: 0px;">
        <img class="img-responsive center-block header1" src="images/header.jpg" />
        <div class='inner'>......</div>
</div>

.container-fluid {
  position:relative;
}

.inner {
  position:absolute;
  top:10%;
  right:20%;
}

This is right if you want to preserve your user of img SRC way to place image. 如果您想保留img SRC用户的图像放置方式,这是正确的。 Otherwise you can transform it into a background and so, is no necessary relative/absolute positioning but you must set a size (width and height) on DIV that have this image as background 否则,您可以将其转换为背景,因此不需要相对/绝对定位,但是必须在DIV上设置以该图像为背景的大小(宽度和高度)

You need to set the image as the background of the DIV. 您需要将图像设置为DIV的背景。 You can use the following CSS to do that. 您可以使用以下CSS来做到这一点。 Then you can add your content to the DIV and style/place accordingly 然后,您可以将内容添加到DIV中,并相应地设置样式/位置

.container-fluid{
    background:url('images/header.jpg') no-repeat;
    background-size:100% auto;
}

You also need to set the height of the DIV to the height of the image or the desired height. 您还需要将DIV的高度设置为图像的高度或所需的高度。

Actually you have 2 options here 其实这里有两个选择

Put the backgroun image in the body 将背景图像放在体内

body {
background:bg.jpg top center
}

Add your nav-bar 添加您的导航栏

nav-bar {
position:fixed
z-index:9999
}

I think that would work 我认为那行得通

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM