What is the best way to divide the background into two distinct colors behind an image by utilizing bootstrap?

Can someone help me with this in bootstrap?

I'm attempting to accomplish the following. Thanks in advance! Here are the codes I have so far:

<body>
    <nav class="navbar navbar-expand-lg navbar-light">
        <div class="collapse navbar-collapse">
            <ul class="navbar-nav ml-auto">
              <li class="nav-item active mr-5">
                <a class="nav-link" href="index.html">Home</a>
              </li>
              <li class="nav-item mr-5">
                <a class="nav-link" href="#">Profile</a>
              </li>
            </ul>
        </div>
    </nav>
    <section>
        <div class="container d-flex justify-content-center">
            <img class="img-fluid" src="img/profile.jpg">
        </div>
    </section>
</body>

Answer №1

To achieve this effect, you do not need to be familiar with bootstrap. Just use CSS along with the before and after pseudo-classes.

Here is an example:

div {
  display: flex;
  width: 100%;
  height: 200px;
  position: relative;
}

div::before, div::after {
  content: '';
  width: 100%;
  height: 50%;
  position: absolute;
  left: 0;
}

div::before { top: 0; background-color: #e6ccff }

div::after { bottom: 0; background-color: #99ffd6 } 

img {
  width: 100px;
  height: 100px;
  margin: auto;
  border-radius: 50%;
  position: relative;
  z-index: 1;
}
<div>
  <img alt="example" src="https://64.media.tumblr.com/5620d4d19c203bbdd9638b662263e45e/tumblr_pyn0cwSNl71y47v4mo1_1280.jpg" />
</div>

Answer №2

.container_image {
  width: 100%;
  min-height: 100px;
  background: linear-gradient(blue 0%, blue 50%, green 50%, green 100%);
}
<div class="container_image">
  
</div>

It seems that achieving this with Bootstrap may be challenging.
However, you can utilize linear-gradient as demonstrated in the example.

Answer №3

A simple solution involves using a top div and a bottom div with the image centered in between them, positioned relative to move it up by half its height.

Credit goes to @Hải Bùi for providing the initial code structure which I then customized further.

.top {
  height: 100px;
  background-color: #e6ccff
}


.bottom {
  height: 100px;
  background-color: #99ffd6;
  text-align: center;
}

img {
  width: 100px;
  height: 100px;
  border-radius: 50px;
  position: relative;
  top: -50px;
}
<div class="top"></div>
<div class="bottom">
  <img alt="example" src="https://64.media.tumblr.com/5620d4d19c203bbdd9638b662263e45e/tumblr_pyn0cwSNl71y47v4mo1_1280.jpg" />
</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

Can the site be shown in the background?

I have a unique idea for a games website that I want to share. It's a bit difficult to explain, so please bear with me as I try to convey my vision! The inspiration for this project comes from a website called . Have you seen it before? The concept i ...

Can a JavaScript framework be created to ensure all browsers adhere to standards?

As someone who isn't an expert in JavaScript, I wonder if it's feasible to create a comprehensive embeddable JavaScript file that ensures all browsers adhere to standards. Could there be a compilation of known JavaScript hacks that compel each br ...

Experimenting with the routerLink directive in Angular 2

Currently, I am in the process of testing routing functionality. As part of this, I have moved my navbar to a separate component called MdNavbar, which primarily consists of HTML and CSS. The RouteConfig is located in another component where MdNavbar is in ...

Unusual problem arises with the positioning of widgets in Blogspot due to the use of CSS `position

Recently, I implemented a new widget on my blog called , which functions as a menu using the "Add HTML/Script" feature. Below is the HTML/CSS code for the widget: .menukadn { line-height: 1; } a.limeka, a.limeka:visited, a.limeka:active { font-family: ...

What steps should I take to confirm the text exists within a particular <DIV> element using Selenium WebDriver (java) and Chrome?

Background: My current setup involves using Selenium WebDriver with Java and utilizing Google Chrome as the browser. I have a question regarding locating specific text on a webpage. What if there are multiple instances of the same text that I am looking f ...

JavaScript tool for connecting tags with JSON properties

As a beginner in JS, I am curious if there exists a JS library that can help bind html fields to a JS object. For example: <div class="js_source"> <input field="name" /> <input field="surname" /> <button type="button">S ...

Troubleshooting Bootstrap 4 Fixed Column Overlapping Issues when Resizing

I have a website created using Bootstrap 4 and PHP that features two columns: Left Column - with a fixed position Right Column - designed to scroll While the columns appear correctly on a desktop browser (as seen in image 1), on mobile devices the "Left ...

Modify CSS class if user is using Internet Explorer version 10 or above

I am attempting to modify the CSS of 2 ASP controls using jQuery specifically for users accessing the site with Internet Explorer 10 or 11. This adjustment is necessary because IE10 onwards, conditional comments are no longer supported. My approach to achi ...

Even when the dimensions are set to 100 width and height, the scroll bar still makes an

I recently embarked on my journey to learn web development by enrolling in a course on Udemy. Currently, I am diving into CSS3/HTML5 and have started a small project involving CSS3 - creating a web page that represents the Universe. My goal is to incorpora ...

Adjusting the input label to be aligned inside the input box and positioned to the right side

I am currently working on aligning my input label inside the input box and positioning it to float right. The input boxes I am using have been extended from b4. Currently, this is how it appears (see arrow for desired alignment): https://i.stack.imgur.co ...

Angular causing WKWebview to freeze

Situation Our Angular+Bootstrap app is functioning smoothly in Desktop on all operating systems, as well as Android and iPhone devices. There are no visible JavaScript errors or CSS warnings. Dilemma However, an issue arises intermittently while using t ...

Unable to utilize first-child CSS to establish the display

I'm currently using WordPress and it's generating the following code: <aside class="left-hand-column"> <div class="textwidget"> <p></p> ...1 <div class="pdf-download"> <p> ... 2 <a href="http ...

Remembering position in JSP using Java Beans

In my "Web Engineering" assignment, I am tasked with developing a Web Application game using JSP, Servlets, and Java Beans. The game mechanics are already in place with the Servlet controlling the algorithms, JSP handling the Model/View, and Beans managing ...

Returning draggable elements to their original placement

I'm looking to create a custom function that resets my draggable elements to their original positions when invoked. This is not related to the built-in revert functionality. $('.drag').draggable({ stack: ".drag", snap: ".dro ...

What is the best way to display the counter result on the cards at the top of an html webpage?

My latest project involves a comparison script using Groovyscript to analyze two distinct files. Embedded within the Groovyscript is HTML code that utilizes CSS and potentially Bootstrap of any version. I have successfully implemented counters with a titl ...

Include a hyperlink to a website that was created with the help of Photoshop

Is it feasible to incorporate a hyperlink into a website that was designed using Photoshop templates? In the past, creating templates in Photoshop and then adding links with tools like Dreamweaver was common practice. I believed that dynamically adding li ...

Is PHP the best choice for creating simple websites?

Throughout my web design experience, I have always relied on PHP for the most basic tasks and avoided using the .html extension. One of the main reasons for this was my ability to utilize "PHP Includes" on my website, allowing me to create navigation eleme ...

Struggle with incorporating a file

As part of the login process, I have two options available: easy login and standard login. The easy login requires an employee ID, birthdate, and captcha answer, while the standard login asks for first name, last name, birthdate, and captcha. To facilitate ...

I am having trouble getting Google Maps to load

Why does the map on my website only load when the browser window is resized? Below is the JavaScript code being used: <div class="map-cont"> <div id="map" class="location-container map-padding" style="width:100%;height:400px;background:y ...

The Bootstrap modal stubbornly refuses to close even after resetting the HTML body

I am having an issue with my bootstrap modal where the closeModal button is not functioning properly after the printModal button has been clicked. The modal does not close as expected. Step 1: Click on the printModal button after the modal pops up (this w ...