Introduction beneath the photograph using the Bootstrap framework

I have a div with an SVG background image and I am attempting to override Bootstrap's responsive behavior so that content can be displayed over the background. The desired outcome is for the text "test" to appear on top of the background, rather than underneath it.

What steps do I need to take in order to achieve this?

.firstsection {
  height: 70vh;
  background-image: url(https://via.placeholder.com/1200);
  background-size: cover;
}

.text {
  font-size: 50px;
  color: red;
}

.secondsection {
  height: 30vh;
  background-color: #151519;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35575a5a41464147544575001b041b06">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<div class="firstsection">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 text">
        <p>test</p>
      </div>
    </div>
  </div>
</div>

<div class="secondsection">

</div>

Answer №1

The reason for this behavior is that the parent element has a background-image property, which means that if you nest text within a div with a background-image, it will appear on top. To resolve this issue, you can close the div containing the background and then start your container and row elements.

I have included a dummy image to illustrate this concept.

.firstsection {
  height: 70vh;
  background-image: url(https://dummyimage.com/600x400/000/fff);
  background-size: cover;
}

.text {
  font-size: 50px;
  color: red;
}

.secondsection {
  height: 30vh;
  background-color: #151519;
}
<head>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="791b16160d0a0d0b1809394c5749574b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<div class="firstsection"></div>
<div class="container">
  <div class="row">
    <div class="col-lg-12 text">
      <p>test</p>
    </div>
  </div>
</div>
<div class="secondsection"></div>

If you wish to maintain similar markup, remove the image from the background and use the img tag instead. You can then add the flex-column class and specify width: 100%; on the img to achieve the same appearance as a background image. Additionally, set margin: 0; on the body element to ensure full-width display.

.firstsection {
  height: 70vh;
  /*background-image: url(background.svg);*/
  background-size: cover;
}

.text {
  font-size: 50px;
  color: red;
}

.secondsection {
  height: 30vh;
  background-color: #151519;
}

img {
  width: 100%;
}

body {
  margin: 0;
}
<div class="firstsection">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 w-100 flex-column text">
        <img src="https://dummyimage.com/600x400/000/fff">
        <p>test</p>
      </div>
    </div>
  </div>
</div>

<div class="secondsection">

</div>

Edit made so that the text sits on top of the background image.

.firstsection {
  height: 70vh;
  background-image: url(https://dummyimage.com/600x400/000/fff);
  background-size: cover;
  background-position: center;
}

.text {
  font-size: 50px;
  color: red;
}

.secondsection {
  height: 30vh;
  background-color: #151519;
}
<!-- Your index file structure should be like this -->
<!doctype html>
<html>
<head>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2a0adadb6b1b6b0a3b282f7ecf3ecf1">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>

<body>
  <div class="firstsection">
    <div class="container">
      <div class="row">
        <div class="col-lg-12 text">
          <p>test</p>
        </div>
      </div>
    </div>
  </div>

  <div class="secondsection">

  </div>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I personalize the preview feature in a Bootstrap rich text editor?

Currently, I am utilizing Bootstrap's rich text editor by this method $('#editor').wysiwyg();. Utilizing AJAX, I am passing the HTML content created by .wysiwyg to save it in the database. Later on, I plan to retrieve the saved HTML data to ...

Is there a way to apply the same class exclusively to the first child within a group?

How can I include specific classes for only the initial group of items in a nested ul li list? <ul> <li class="first-group"> <ul> <li></li> </ul> </li> <li class="first-group"></li> & ...

developing a fluid grid system with flexible ordering

I'm currently working on a section for my app that consists of one row with 3 columns, each column containing 3 divs. JSFIDDLE: demo Here is how it should appear in desktop view: https://i.sstatic.net/ugAXd.png And here is the expected appearance ...

Remove any unnecessary white space and new lines from the HTML code

Is there a way to remove double whitespaces and new lines from my HTML output without altering the ones within textarea and pre tags using PHP? ...

What is the most effective way to utilize a loop in order to generate a comma-separated list of values that does not contain an additional comma

Using @for to generate multiple box-shadow arguments: .myclass { $bxsw : ""; @for $i from 1 through 10 { $bxsw : $bxsw + " -" + $i + "px -" + $i + "px " + brown + ","; } box-shadow: #{$bxsw}; } This results in: .myclass { bo ...

Attempting to choose everything with the exception of a singular element using the not() function in Jquery

Within the mosaic (div #mosaique) are various div elements. My goal is to make it so that when I click on a specific div, like #langages or #libraries, the other divs become opaque while the selected div undergoes a size change (which works correctly in t ...

Make the element switch from hidden to visible when hovering over it using CSS

I had a challenge to only show some rating text on my website when I hovered over it. Being new to coding with CSS and JavaScript, I was experimenting with overriding styles using the Stylebot extension in Chrome. I encountered an issue while trying to mo ...

The iframe came to a halt as soon as it was no

I am currently developing a live video website that utilizes third-party tools to play the videos. To simplify things, I have embedded all the components required for live video into a single HTML page. Here is how it looks: <iframe data-v-140cfad2= ...

Facing challenges with parsing JSON files in an Angular 2+ application

Utilizing the Angular CLI, I have configured this project with the standard folder layout. My goal is to practice reading a JSON file from src/app/assets/items.json and then using it to display these items in the HTML. items.json: { "results": [ ...

"Utilizing FileReader to seamlessly integrate data into FormData without the risk

Currently, I'm in the process of constructing an ajax file uploader. This is made possible thanks to the recently introduced FormData interface. Everything seems to work as expected when using the original file. However, I encounter issues when conver ...

Mastering the Art of Line Breaks in WordPress

I am looking for a way to break a WordPress site title over two lines at a specific point in the text. Since the WordPress content filter 'wpautop' disables the ` ` tag (also known as ` ` or ` `), I'm wondering what the best alternative ...

What's the best way to apply a margin top to an image using Tailwind CSS?

Is there a way to adjust the top margin of an image in Tailwind CSS? I'm having trouble making my logo clearly visible and think giving it some space at the top might help. How can I do this within the Tailwind CSS framework? https://i.sstatic.net/Ae ...

Modify CSS when scrolling, based on the size of the screen

I've implemented this JQuery script to modify elements in my header as the user scrolls. Is there a way to limit these modifications based on the screen size? Here's the code snippet: $(window).scroll(function() { // Once the user has scro ...

How can I extract the value of the first element in a dropdown using Javascript?

Imagine there is a dropdown menu with an unspecified number of options: <select id="ddlDropDown"> <option value="text1">Some text</option> <option value="text2">Some text</option> <option value="text3">Some ...

Creating a tabular layout using div elements and CSS styling

Here is the css and html code that I am working with: <style type="text/css"> .formLayout { background-color: #f3f3f3; border: solid 1px #a1a1a1; padding: 10px; width: 300px; border-radius: 1em; } ...

Scaling down in CSS does not center the element properly using the margin 0 auto technique when the scaled element was larger than the container before scaling

Upon scaling down an element that previously overflowed its container, I noticed that margin: 0 auto no longer centers the element as expected. Interestingly, even using transform-origin: center center did not fix this issue. It seems that the auto margins ...

How to embed HTML code within PHP using a conditional variable

I've encountered an issue with a PHP code that sends emails containing HTML templates. The HTML template includes PHP variables such as Name and Email. <strong>Name: {name} </strong> As the email template is lengthy, I have included ...

Using jQuery to submit an array within a form - a comprehensive guide

My goal is to accumulate form data each time the user clicks add_accommodation and add it to an array that will be sent to the endpoint http://server/end/point. <form action="http://localhost:3000/a/b/c" method="post"> <div> <input ...

Using Kendo UI Mobile, take advantage of a button to trigger the click action of another

Consider the following situation: HTML <a id="mButton" data-role="button" data-click="clickFn">myButton</a> <asp:ImageButton runat="server" ID="aspButton" style="display: none"></asp:ImageButton> SCRIPT function clickFn(e) { ...

What is the best way to trigger the closing of a Bootstrap (version 5.2) Modal using JavaScript

In order to complete my school project, I decided to create a modal using Bootstrap in HTML. Inside the modal, there is a prompt that needs to be checked from JavaScript. How can I close the Modal from JavaScript? This way, if the prompt is valid, I can sa ...