A header with two divs taking up the entire screen

I am trying to create a full-screen header with 2 div elements, similar to the design in this example.

So far, I have attempted to implement this layout, but the div elements are not spanning 100% width, and I also need to add an overlay to the right div (similar to the example).

.masthead {
  display: table;
  width: 100%;
  height: auto;
  padding: 200px 0;
  text-align: center;
  color: #fff;
  /*background: url(../img/main_pic.jpg) no-repeat bottom center scroll;*/
  background-color: green;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover
}

.masthead .intro-body {
  display: table-cell;
  vertical-align: middle
}

.masthead .intro-body .brand-heading {
  font-size: 50px
}

.masthead .intro-body .intro-text {
  font-size: 18px
}

@media (min-width: 768px) {
  .masthead {
    height: 100%;
    padding: 0
  }
  .masthead .intro-body .brand-heading {
    font-size: 100px
  }
  .masthead .intro-body .intro-text {
    font-size: 22px
  }
}

.right {
  background-color: blue;
}

.left {
  background-color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<header class="masthead">
  <div class="intro-body">
    <div class="container">
      <div class="row">
        <div class="col-lg-6 mx-auto left">
          <p class="intro-text">left</p>
          <a href="#about" class="btn btn-circle js-scroll-trigger">
            <i class="fa fa-angle-double-down animated"></i>
          </a>
        </div>
        <div class="col-lg-6 mx-auto right">
          <p class="intro-text">right</p>
          <form class="contact-form row">
            <div class="col-md-12">
              <label></label>
              <input type="text" class="form-control" placeholder="name" required>
            </div>
            <div class="col-md-12">
              <label></label>
              <input type="email" class="form-control" placeholder="email" required>
            </div>
            <div class="col-md-6">
              <label></label>
              <input type="tel" class="form-control" placeholder="tel" required>
            </div>

            <div class="col-md-6 col-md-offset-4">
              <label></label>
              <button type="submit" class="btn btn-primary btn-block btn-lg">send</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</header>

Link to Codepen Example

Answer №1

  1. To create a full-width container, utilize the class .container-fluid
  2. For the background image, apply it to .masthead. To add an overlay effect, set a background color on .right using rgba

codepen

.masthead {
  display: table;
  width: 100%;
  height: auto;
  padding: 200px 0;
  text-align: center;
  color: #fff;
  background: url(https://unsplash.it/3000x1000) no-repeat center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
.masthead .intro-body {
  display: table-cell;
  vertical-align: middle;
}
.masthead .intro-body .brand-heading {
  font-size: 50px;
}
.masthead .intro-body .intro-text {
  font-size: 18px;
}
@media (min-width: 768px) {
  .masthead {
    height: 100%;
    padding: 0;
  }
  .masthead .intro-body .brand-heading {
    font-size: 100px;
  }
  .masthead .intro-body .intro-text {
    font-size: 22px;
  }
}

.right {
  background: rgba(0, 25, 84, 0.5);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<header class="masthead">
  <div class="intro-body">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-6 mx-auto left">
          <p class="intro-text">left</p>
          <a href="#about" class="btn btn-circle js-scroll-trigger">
            <i class="fa fa-angle-double-down animated"></i>
          </a>
        </div>
        <div class="col-lg-6 mx-auto right">
          <p class="intro-text">right</p>
          <form class="contact-form row">
            <div class="col-md-12">
              <label></label>
              <input type="text" class="form-control" placeholder="name" required>
            </div>
            <div class="col-md-12">
              <label></label>
              <input type="email" class="form-control" placeholder="email" required>
            </div>
            <div class="col-md-6">
              <label></label>
              <input type="tel" class="form-control" placeholder="tel" required>
            </div>

            <div class="col-md-6 col-md-offset-4">
              <label></label>
              <button type="submit" class="btn btn-primary btn-block btn-lg">send</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</header>

Answer №2

Both of the sections within your div element are set to occupy 50% width (specified by the col-lg-6 class) of the containing element. The reason why your container does not fill the entire screen is because you are utilizing the container class, which creates a container with a fixed width for larger viewports and becomes fluid only on extra small viewports.

If you require a container that always spans 100% of the width, you can simply switch to using the container-fluid class instead of container.

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

Modify the color of the background for a flex-wrap list

I am facing a situation where I have a list with an unknown number of items, but I need to control the height of its container. To achieve this, I am using flex-flow: wrap column to split the list. The list starts off hidden and is displayed using jQuery&a ...

What is the reason behind H1 tags not requiring a class or ID in CSS?

As I was reviewing my CSS code, I noticed that the h1 tag is defined like this: h1 { .... } Unlike everything else in my code, which either has an id "#" or a "." class preceding it. This made me wonder why header tags don't require this. Could it b ...

Make multiple images in one row resize proportionally instead of wrapping them to the next line

My phone's screen is small and I want the three images to remain in the same row. In case they don't fit, they should shrink proportionately to maintain alignment (refer to image at the bottom). Consider the code snippet below: <div id="exam ...

Bootstrap4 does not support the <button> element

How can I achieve a 'collapse icon' floated to the left followed by Copyright © using Bootstrap 4? I've looked at similar questions on this topic, but none seem to provide a direct answer. Other questions contain different code with ob ...

Aligning text vertically within a textbox using CSS

Currently tackling a textbox with a background and wondering if there's a way to vertically center the text inside it. Note: Text is perfectly centered in Firefox, but in IE it appears too high for some reason. Have tried adjusting line-height, paddi ...

Issues with Monospace Google Fonts on JSFiddle are preventing them from displaying correctly

It's strange how monospace fonts from Google Fonts don't display properly on JSFiddle. Only sans-serif and serif fonts seem to be functioning correctly. ...

Using CSS to customize the dropdown text styling of a select box within a custom wrapper

I have a specific customized dropdown menu using the styled-select wrapper: HTML: <div class="styled-select"> <select name="example_length" aria-controls="example" class=""> <option value="10">10</option> <option value="25"> ...

Tips on turning off automatic positioning in Bootstrap 4.1

My dropdown list is currently quite large. Take a look at the image linked below. Image How can I address this issue effectively? I'm considering utilizing JavaScript to reposition the menu. Any guidance on how to disable auto-positioning? Check ou ...

Unable to pinpoint the source of the excess spacing within a form field

There appears to be some extra space in the text field of my form, extending beyond the container margin. Please refer to the image and JSFiddle http://jsfiddle.net/GRFX4/. Any thoughts on what might be causing this issue? Thank you. HTML: <div id="co ...

Ways to showcase an icon within a select options tag

Is there a way to show Font Awesome icons in select options tag? I have tried using it outside like this <i class="fas fa-chart-pie"></i> But I'm not sure how to display it within the <option> tags instead of text. <select id="s ...

Changing the Direction of News Ticker Movement from Right to Left

I need to switch the news ticker movement direction from right to left to left to right because I will be using Arabic language, so it is crucial to change the movement direction. Despite trying for several days, I have been unable to find a solution. HTM ...

Choosing a CSS Grid layout

New to web development, I have a design dilemma. Working on a game that teaches students how to multiply, I am unsure about the best way to display the multiplication process. This picture illustrates my issue: https://i.sstatic.net/F8ZGs.png Given that I ...

The flex-wrap property with a value of "nowrap" does not seem to

I am struggling with making the page responsive. The flex-wrap: nowrap property seems to be causing issues. Can someone please assist me in identifying the root of the problem? .logo { text-decoration: none; color: white; } .header { width: ...

JavaFX, a versatile container capable of smoothly transitioning between two panes

Looking for a JavaFX container in my Desktop Application that can display a listview with flexible dimensions and transition to gridpane on row selection. The gridpane will show details of the selected row, and clicking the back button will revert to the ...

Is there a challenge in setting up a tag search bar similar to Stack Overflow's?

First and foremost, I apologize for the awkwardly phrased question. The issue at hand is that when the tags exceed the container size, the search option becomes hidden. My goal is to have the search bar adjust dynamically, moving everything back inside the ...

Remove padding in Twitter Bootstrap table cells

One of my current projects requires making a button that fills the entire width and height of the TD element. I have attempted setting the normal .btn-warning with -Xpx!important, but it did not produce the desired result. Here is what I currently have: ...

Element misbehaving after a certain point

I'm encountering an issue with a piece of code that is not working as expected. The problem seems to be specifically with the after element. The desired behavior is for two lines to draw from the top left corner and the bottom right corner when hoveri ...

Adjusting the cell size to align with the height of another cell in the same row

Within a table row, I have two cells that contain divs and the height varies due to changing content. Is there a way for one cell to take up 100% height to match the other cell? You can see an example here. The goal is for the second cell and its div to ...

The flex container cannot contain all of the content due to an

I am looking to implement a flexbox dropdown menu similar to this: https://i.sstatic.net/Cer9D.png After researching online, I found a simple dropdown menu example. However, I want to customize it using flexbox and its properties. The issue I encountered ...

Can you propose a different approach to creating the "word stack" that overcomes the limitations of my current method?

I am attempting to convert a set of two radio buttons into a stack of two labels, one blue and one gray, to represent the selected radio button and the unselected one. Clicking on this stack will toggle which label is blue (and consequently which radio but ...