猿问

在背景图像顶部有一个透明框/覆盖层

我希望将灯箱放在背景图像的顶部,以便可以通过灯箱看到背景图像。我试图进入图片(顶部)而不是在它之外,但到目前为止没有任何效果。

我想把这个标题和这些文字放在白框中,背景图像看到槽(不透明度大约为 0.5)。

        <h2 style="color: black" align="center">Food is essential part of our well-being</h2> 
        <p>Our expertise </p>

这是引导程序/HTML。


<!doctype html>

<html>

  <head>

    <!-- Required meta tags -->

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">


    <!-- Bootstrap CSS -->

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<link rel="stylesheet" href="style.css">

    <title>Hello, world!</title>

  </head>

  <body>


    <nav class="navbar navbar-expand-lg navbar-light bg-light">

  <a class="instagram" href="#">

  <img src="https://cdn3.iconfinder.com/data/icons/picons-social/57/38-instagram-256.png" width="35" height="35" alt=""></a>

    <a class="facebook" href="#">

  <img src="https://cdn3.iconfinder.com/data/icons/wpzoom-developer-icon-set/500/01-256.png" width="35" height="35" alt=""></a>

      <a class="twitter" href="#">

  <img src="https://cdn2.iconfinder.com/data/icons/font-awesome/1792/twitter-square-256.png" width="35" height="35" alt=""></a>

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">

    <span class="navbar-toggler-icon"></span>

  </button>


杨__羊羊
浏览 287回答 2
2回答

慕运维8079593

您可以使用display: flexon.container将元素放置.container在顶部。我添加了一些注释来最小化您的代码。一探究竟!.container {&nbsp; background-image: url("https://cdn.pixabay.com/photo/2015/08/25/03/51/toner-906142__480.jpg");&nbsp; /* Add the background image like this */&nbsp; height: 500px;&nbsp; /* Give the background image the correct height */&nbsp; background-repeat: no-repeat;&nbsp; background-position: center;&nbsp; background-size: cover;&nbsp; display: flex;&nbsp; /* Places content inside on top */&nbsp; justify-content: center;&nbsp; /* Center horizontally */&nbsp; align-items: center;&nbsp; /* Center vertically */}.transbox {&nbsp; padding: 30px;&nbsp; background-color: rgba(255, 255, 255, 0.5);&nbsp; /* Opacity can be given to background with rgba*/&nbsp; border: 1px solid black;&nbsp; height: 100px;}<div class="container" href="service">&nbsp; <div class="transbox">&nbsp; &nbsp; <h2>&nbsp; &nbsp; &nbsp; Food is essential part of our well-being&nbsp; &nbsp; </h2>&nbsp; &nbsp; <p>Our expertise </p>&nbsp; </div></div>

泛舟湖上清波郎朗

只需将此 CSS 添加到您的.transbox样式中即可https://jsfiddle.net/rjaw5nvx/position:&nbsp;absolute; top:&nbsp;50%; transform:&nbsp;translateY(-50%);您还可以使用 Flexbox 使框垂直和水平居中,但这有点复杂。
随时随地看视频慕课网APP

相关分类

Html5
我要回答