0

I want to add text on image in bootstrap 4 but when I do it will appear after image, like so:

Image displaying behaviour

Here is my code so far:

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

    
  
 

            <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
           <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
                 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
               <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
                <style>
            body{
             box-sizing: border-box;margin: 0px;padding: 0px;overflow-x: hidden;
            }
            .row > *{min-height: 80px;

             
            }
            .img-fluid{
             width: 100%;
             height: 400px;
            }

           </style>
</head>
<body>
 
 
<div class="row" >
      

  <div class="col-md-12" style="">
   <img class="img-fluid  " src="images/bg.jpg" alt="Responsive image"> <h1>fsdfsdfdsfds</h1> </div>
  
 </div>
</body>
Roy
  • 7,811
  • 4
  • 24
  • 47
WEBKIRA
  • 37
  • 1
  • 4
  • 2
    Possible duplicate of [How to position text over an image in css](https://stackoverflow.com/questions/8708945/how-to-position-text-over-an-image-in-css) – Tommy Nov 02 '18 at 14:09

1 Answers1

3

Try this, and you're done... Just add below css...

h1 {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    width: max-content;
    height: max-content;
    background:#FFF;
}

h1 {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    width: max-content;
    height: max-content;
    background:#FFF;
}
<head>
<meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    
  
 

            <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
           <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
                 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
               <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
                <style>
            body{
             box-sizing: border-box;margin: 0px;padding: 0px;overflow-x: hidden;
            }
            .row > *{min-height: 80px;

             
            }
            .img-fluid{
             width: 100%;
             height: 400px;
            }

           </style>
</head>
<body>
 
 
<div class="row" >
      

  <div class="col-md-12" style="">
   <img class="img-fluid  " src="https://i.stack.imgur.com/1eZuM.png" alt="Responsive image"> <h1>fsdfsdfdsfds</h1> </div>
  
 </div>
</body>
ElusiveCoder
  • 1,593
  • 1
  • 8
  • 23