【问题标题】:How do I create background image and add text over it如何创建背景图像并在其上添加文本
【发布时间】:2015-02-04 09:14:27
【问题描述】:

首先我是 非常 新手,但我想做一些类似于此示例的操作:text over background image 但在引导框架内。我尝试在导航栏下方的容器内创建一个 div,但这似乎在覆盖图像的文本后面放置了一个白色背景......你可以在这里看到我的代码:JSFiddle:my code。或者如下:

CSS

body {
margin-top: 50px; /* Required margin for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */
}

@import url(http://fonts.googleapis.com/css?family=Oswald:700);

html { 
background: url(http://3.bp.blogspot.com/_6r-mOI0OuO0/S6q3VodCqI/AAAAAAAAB5A/Uycl8dCr92A/s1600/NYC15BrooklynBridge02.jpg) no-repeat center center fixed; 
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
font-family: 'Oswald', sans-serif;
}

h1 {
color: #fff;
text-align: center;
font-size: 120px;
text-transform: uppercase;
}

span {
font-size: 130px;
color: transparent;
text-shadow: 0 0 10px #fff;
}

HTML

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>Full - Start Bootstrap Template</title>

<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="css/full.css" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<style type="text/css">
    @import url(http://fonts.googleapis.com/css?family=Oswald:700);


h1 {
color: #FF6600;
text-align: center;
font-size: 120px;
text-transform: uppercase;
}

span {
font-size: 130px;
color: transparent;
text-shadow: 0 0 10px #FF6600;
}
</style>

</head>

<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
            <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="#">Start Bootstrap</a>
    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
            <li>
                <a href="#">About</a>
            </li>
            <li>
                <a href="#">Services</a>
            </li>
            <li>
                <a href="#">Contact</a>
            </li>
        </ul>
    </div>
    <!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>

<div class="container">
<h1>
  <span>some text</span><br>some other text
</h1>
</div>
<!-- jQuery -->
<script src="js/jquery.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>

</body>

</html>

【问题讨论】:

  • 如果您将示例发布到jsfiddle,其他人可以更轻松地使用您的代码。您可以从侧边栏中包含引导程序和其他外部资源(see here 寻求帮助)。
  • 只需将您的代码应用到正确的容器中。 codepen.io/alexincarnati/pen/NPxRKM

标签: html css twitter-bootstrap


【解决方案1】:

只需添加body { background: none; }FIDDLE

【讨论】:

    【解决方案2】:

    我看到您已将 CSS 样式添加到整个主体,这意味着您必须关闭位于其顶部的所有内容的所有背景。但是您可以将您创建的样式添加到包含文本的容器中。然后,您可能需要设置文本样式以使其可见。

    <div class="container full">
        <h1>some text</h1>
        <h1>some other text</h1>
    </div>
    

    顺便说一句,您真的不应该将两位标头文本用中断分开,使用两个标头并定位它们。此外,如果您要使用它,您真的应该关闭 break 标签。 :)

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      • 1970-01-01
      相关资源
      最近更新 更多