Creating a split screen layout using Bootstrap

I've been working hard to create a split-screen layout using Bootstrap. After using CSS to achieve it, I realized that it's not responsive for mobile users. Therefore, I'm reworking it with Bootstrap but facing issues with resizing the image and text box. I want the layout to adjust to a single row with two columns for desktop and mobile views.

Edit: Apologies for the sudden change, but I'm now working with Bootstrap version 5.

#promotion-textbox {
  top: 115px;
  display: inline-block;
  margin-right: 5vw;
  left: 55%;
  background-color: white;
  object-fit: fill;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}

#promotion-title {
  padding: 10px;
  position: static;
  color: #23272a;
  font-size: 3vw;
  overflow: hidden;
  display: inline-block;
}

#promotion-button {
  width: 40vw;
  opacity: 0.8;
  left: 75%;
  transform: translate(-50%, -75%);
  margin-left: auto;
  margin-right: auto;
  top: 620px;
}
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d6dbdbc0c7c0c6d5c4f4819a849a86">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<div class="row">
  <!-- First Half -->
  <div class="col-md-6">
    <img class="img" src="https://via.placeholder.com/100">
  </div>
  
  <!-- Second Half -->
  <div class="col-md-6">
    <div id="promotion-textbox">
      <div id="promotion-title">
        Duck Zone is the best game of all time, I mean just look at these awesome reviews:<br /><br /> TheP0mp21 Says:<br />- Game is pretty good but it needs a your mum duck that is extremely fat and spawns other ducks.
      </div>
    </div>
  </div>
</div>

Answer №1

If you're utilizing a library, make sure to fully utilize its features like the utility classes and understand its grid system:

  • Apply the vh-100 utility class to your row
  • Include w-100 h-100 in the img tag HTML and add object-fit: cover in the CSS

Since you've switched from to , to eliminate spacing and hide the horizontal scrollbar, replace no-gutters with g-0

Important: Some of your styles do not have a logical purpose, like left/top without position

I have also made improvements to your code

#promotion-textbox {
  background-color: white;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  margin-bottom: 20px;
}

#promotion-title {
  padding: 10px;
  color: #23272a;
  font-size: 3vw;
}

#promotion-button {
  opacity: 0.8;
  border: 2px solid #fff;
  color: #fff;
  padding: 10px 20px;
  background: transparent;
}

img {
  object-fit: cover
}

.col-6:last-child {
  background: darkgray
}

.promotion-column {
  display: flex;
  flex-direction: column;
  padding: 20px;
  align-items: center;
  justify-content: center;
  height: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1d3dedec5c2c5c3d0c1f1849f819f83">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="row g-0 vh-100">
  <!-- First Half -->
  <div class="col-md-6">
    <img class="img w-100 h-100" src="https://picsum.photos/300/200">
  </div>
  <!-- Second Half -->
  <div class="col-md-6">
    <div class="promotion-column">
      <div id="promotion-textbox">
        <div id="promotion-title">
          Duck Zone is the best game of all time, I mean just look at these awesome reviews:<br /><br /> TheP0mp21 Says:<br />- Game is pretty good but it needs a your mum duck that is extremely fat and spawns other ducks.
        </div>
      </div>
      <button type="button" id="promotion-button">All Projects</button>
    </div>
  </div>
</div>

Answer №2

To ensure your images are responsive, make sure to use responsive image techniques. Additionally, I removed the gutters from the row to enhance the design.

UPDATE: I have implemented some improvements, such as using height:100vh which adjusts the height exactly to the window size.

.half {
  border: 1px solid red;
  height: 100vh;
  position: relative;
}

.my-image {
  width: 100%;
  height: 100%;
}

#promotion-textbox {
  top: 115px;
  display: inline-block;
  background-color: white;
  object-fit: fill;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}

#promotion-title {
  padding: 10px;
  position: static;
  color: #23272a;
  font-size: 3vw;
  overflow: hidden;
  display: inline-block;
}

#promotion-button {
  width: 40vw;
  opacity: 0.8;
  left: 75%;
  transform: translate(-50%, -75%);
  margin-left: auto;
  margin-right: auto;
  top: 620px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c2e2323383f383e2d3c0c78627a627d">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">

<div class="row no-gutters">
  <!-- First Half -->
  <div class="half col-sm-6">
    <img class="img my-image" src="https://picsum.photos/536/354">
  </div>
  <!-- Second Half -->
  <div class="half col-sm-6">
    <div id="promotion-textbox">
      <div id="promotion-title">
        Duck Zone is the best game of all time, I mean just look at these awesome reviews:<br /><br /> TheP0mp21 Says:<br />- Game is pretty good but it needs a your mum duck that is extremely fat and spawns other ducks.
      </div>
    </div>
  </div>
</div>

<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>
<p>content </p>

Answer №3

If you want to create a split screen with two columns, you can achieve this by using .row as the parent element and .col-md-6 for the children. The "md" part indicates that the columns will expand to full screen width on medium and smaller screens (you have options like xxl, xl, lg, md, sm, xs). To ensure the columns fit the screen vertically, add min-height: 100vh; to both columns and use a media query for the break point with min-height: 50vh;

Source: https://getbootstrap.com/docs/4.6/layout/grid/

Here is an example using Bootstrap 4 (compatible with Bootstrap 5 and 4):

CSS:

.img-col{
  background: url(https://via.placeholder.com/100) center center no-repeat;
  background-size: cover;
}
.min-h-50{
  min-height:100vh;
}
@media only screen and (max-width: 767px) {
  .min-h-50{
    min-height:50vh;
  }
}

HTML:

<div class="row">
  <div class="col-md-6 img-col min-h-50">
  </div>
  <div class="col-md-6 bg-dark min-h-50">
    <div class="row justify-content-center h-100">
      <div class="col-10 align-self-center">
        <div class="bg-white p-3">rff</div>
        <div class="mt-3 text-center"><button class="btn btn-primary">xxx</button></div>
      </div>
    </div>
  </div>
</div>

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

A guide on showcasing the compilation results of PHP code directly on the web browser

How can I compile PHP code on an HTML Button click and display the compilation output in a browser? The code snippet below works well in the terminal but doesn't show anything in the browser. I am currently using XAMPP server on a Windows machine. &l ...

Tips for defining CSS styles for the background color of <td> elements within a sitemap

I am facing a similar issue to the one discussed in this thread Possible to fill a table cell with a bg color?. The challenge I am encountering is related to applying CSS styles to the td tags within a sitemap structure. (Although it functions correctly ...

Utilize the bootstrap grid to align content into 4 columns evenly

I have the following code snippet: <div class="panel-body"> <div class="col-sm-6"> <label class="head6">Business Name : </label><span class="head9">'.$name.'</span> </div> <div ...

What could be causing these cards to not show up correctly?

I am currently incorporating Angular Material's cards in a material grid. Here is the code snippet that I am working with: http://codepen.io/anon/pen/YWwwvZ The issue at hand is that the top row of images extends off the screen at the top, and the b ...

Is it possible for a form to direct submissions to various pages depending on the value of certain fields

I need to set up a text field and submit button that will redirect users based on their input: index.html: If the user inputs "123" in the text box and clicks submit, they should be redirected to john.html page. AND If the user inputs "456" and clicks s ...

Breaking up and Substituting text within Angular 8's HTML structure

When I retrieve data from a REST api, I need to split the name parameter at '2330' and insert a line break. For example, if the name is: ABCD 2330 This is My Name, I want the output on my screen to appear as: ABCD 2330 This is My Name // this par ...

The text following a table is spilling into the table because it is too big to fit within the designated div

I've been searching for a solution to this issue (it's a common problem), but nothing I've attempted has resolved it. Currently, I am using jQuery Mobile. Below is the code snippet in question: <div style="width:100%; height:220px;"> ...

What is the best way to resize SVG graphics effectively?

I am in need of creating a seating chart. I have generated an SVG with the seats. <div class="seats-map"> <svg xmlns="https://www.w3.org/2000/svg" id="seats-map-svg" viewBox="0 0 1000 300"> <g data-row ...

How can I achieve a transparent background for a text field in CSS instead of white?

I've come across several solutions, but none have been able to solve my issue so far. The text fields in question look like this: .form-wrapper .field-list .field .field-element{ background-color: rgba(0,0,0,0.5); color: rgba(255,255 ...

What Makes Bracket Notation Essential in HTML5?

I recently came across an interesting discussion on the Code Review StackExchange site about best practices for creating forms with multiple rows of identical form inputs. Joseph Silber suggested using bracket notation and avoiding IDs altogether in this s ...

Guide on retrieving HTML content from a URL and showing it in a div

I'm trying to retrieve the content of a URL and display it within a DIV element, but I'm struggling to achieve the desired result. Below is the code I'm using: index.js fetch('https://github.com/') .then(res => res.text()) ...

Node.js web application encounters ECONNRESET and MongoNetworkError issues

Currently working on a website with Node.js, Express, and MongoDB (MLAB). The code is too long to post here. When I try to access my index page, app.get("/alumniport", (req, res) => { alumni.find((err, theAlumni) => { if (err) { res.redi ...

Steps to bold a specific word within a div on react native

Hey there! I'm working with the code below: getDescription = () => { return( <div className="Description">{this.props.mytext + ': ' + this.name} </div> ) } Is it possible to bold only the specific te ...

Is there a way to command Chrome or Firefox to execute JavaScript or load a Bookmarklet directly from the command line?

Is there a way to execute javascript in the current browser window through the command line, either in Chrome or Firefox? Or is it possible to load a bookmarklet that includes javascript? I'm interested in creating a program that can monitor changes ...

The system encountered an issue with the CSS code, indicating "Invalid CSS after "...inear-gradient(": expected selector, was "{"

While attempting to compile my sass code, I encountered the following error message regarding a syntax issue: /* { "status": 1, "file": "C:/Users/faido/Desktop/Productivity/sass css/project/sass/main.sass", "line": 36, "column": 9, "mes ...

Ways to showcase the contents of a React JavaScript document, or more specifically, a file designed for React interpretation

After trying multiple solutions, I found a conceptual guide on How to call and form a React.js function from HTML. However, the HTML generated doesn't seem to be calling from the JavaScript file as expected. It appears identical to what is mentioned i ...

Unlimited icon carousel crafted with CSS

Currently, I have a set of 10 icons that are scrolling horizontally from right to left. However, I am encountering an issue where at the end of the icon loop, there is a space causing the icons to jump back to the beginning. I am looking for a solution to ...

Ways to adjust the size or customize the appearance of a particular text in an option

I needed to adjust the font size of specific text within an option tag in my code snippet below. <select> <?php foreach($dataholder as $key=>$value): ?> <option value='<?php echo $value; ?>' ><?php echo ...

Viewing a Google Charts graph upon the loading of a web page

Utilizing the Google Charts library, I have incorporated a graphic on my web page that is dynamically added using AJAX into a <div> element. To display the graph when the page loads, I have written the following code: <script type="text/ ...

Notify the user with a Jqgrid alert when they attempt to select multiple checkboxes

When editing rows, I wanted to avoid multiple selections. In order to achieve this, I need to check the condition if(count>1) and display an alert message. I am struggling to figure out how to retrieve the count of selected checkboxes in jqGrid. var m ...