Bootstrap: one row inside a column with a large width in another row

Hello, I am trying to create a layout with a blue row inside a red col-lg-4 div within a yellow row. Here is the code snippet I have attempted:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  // Other stylesheet and script links...

  <link rel="stylesheet" type="text/css" href="style.css">

</head>
<body>

<div class="container-fluid" style="height: 400px;background-color: yellow">
    <div class="row">
        <div class="col-lg-4 col-lg-offset-1" style="background-color: red;">
            <div class="row" style="padding-top:20%;padding-bottom: 20%;background-color: blue;">
                dddd
            </div>
        </div>
    </div>
</div>

</body>
</html>

Here is the CSS used:

.navbar {
    margin-bottom: 0 !important;
    background-color: white;
}

.row1 {
    background: url("appart.jpg");
    background-size: 100% 400px;
    background-repeat: no-repeat;
}


[class*="col-"], footer {

  background-color: lightgreen;
  opacity: 0.5;
  line-height: 400px;
  text-align: center;
}

However, my result looks like this:

https://i.sstatic.net/e71qO.png

I'm having trouble achieving the desired outcome without the colors getting mixed up. Any suggestions would be greatly appreciated. Thank you.

Answer №1

Here is the solution I posted in the jsfiddle code:

To resolve the issue, remove the class attribute rule [class*="col-"] from your css. Instead, target specific elements using css to avoid converting all columns to have a line-height of 400px which may distort your final html layout. Remember not to use inline styles.

If you eliminate [class*="col-"] and add the following code snippet to your css file, you will achieve the desired result:

.container-fluid > .row, .col-lg-4.col-lg-offset-1 {
  height: 100%;
}

.col-lg-4.col-lg-offset-1 > .row {
  top: 50%;
  transform: translateY(-50%);
  position: relative;
  text-align: center;
}

For a demonstration, check out the fiddle demo at the following link: https://jsfiddle.net/karthick6891/4js3r3hd/

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

I am looking to incorporate a dropdown menu into an HTML form that displays the upcoming four or five Saturdays

Looking for a way to incorporate a dropdown feature in an html form that will display the next four upcoming Saturdays. The purpose behind this is to allow individuals signing up to select which of the upcoming Saturdays they would like to visit our establ ...

Steps for creating scrollable boxes with uniform size using tailwindcss:1. Define a specific width and height for

<div className="overflow-x-auto p-5 gap-5"> <div className={` bg-orange-700 w-[300px] h-[300px]`}></div> <div className={` bg-orange-700 w-[300px] h-[300px]`}></div> <div className={` bg-orange-700 ...

Using jQuery trigger to activate a function whenever a new <li> element is appended to a <ul> list

I am currently facing an issue with a PHP page that utilizes flush() and ob_flush() to send progress updates to a browser. The page generates a styled <ul class="progresslog"> where individual <li class="{success|warning|error}"> items are sent ...

What is the process for connecting two scripts together?

Purpose : I am currently working on a Firefox add-on with the goal of tracking the online status of my team members in a game. Current Progress : I have developed an initial JavaScript script that runs upon opening the browser. This script creates and ...

Statement featuring session parameter for querying

Is it appropriate to include session variables in a SQL query? The following is an example of a query I am working with: $sql="SELECT teacher.f_name,attendance.student_id,attendance.SNO ,attendance.s_section,attendance.DateTime FROM teach,subject,teacher ...

Converting a table into div elements and subsequently reverting it back to its original table format

[STOP DOWNVOTING: NEW AND IMPROVED] Discovering a simple technique on stackoverflow to transform tables into divs has been quite enlightening. By assigning classes to each tag, such as: <table class="table"> the process of converting from table to ...

How can you design an input type text to resemble a select dropdown?

Is there a way to customize an input type=text element to appear as a dropdown? Currently, I have a text box that, when clicked, displays options using jQuery and a div. I want the text box to include a dropdown icon to mimic a traditional dropdown menu. ...

Connect my php search outcomes to a different webpage

Hello, I am new to the world of php and I have written a search result function that allows users to click on items. However, I am facing an issue with making a specific search item clickable to open in another page with full details. Below is the code I h ...

The addEventListener feature in Bootstrap 5.2.3 seems to be malfunctioning

I have a sample page with a Bootstrap dialog being returned from the server. I want to display it inside a DIV. However, when clicked, I receive this error: Uncaught TypeError: myModal.addEventListener is not a function It points to this line of code: ...

Each element in Sass is assigned the same index value in a loop

Seeking to add animations to various div elements with unique delay times, I encountered a puzzling issue. Despite following online tutorials closely (such as this one), the animation delays remain consistent for all divs. The loop I have is as follows: @ ...

Tips for saving data from dynamically created input and select boxes

I have developed a webpage where users can add or delete rows by clicking on the addrow and delrow buttons. Everything is working fine so far. The issue I am facing now is that I need to store the values of dynamically generated fields using the post metho ...

Can anyone lend a hand with styling this menu without relying on margins in CSS?

I've been working on a website and I've noticed a significant lag in Internet Explorer when hovering over the menus. It appears that Cufon is contributing to this issue, especially when applying height, width, margins, or paddings to the li:hover ...

Issue with auto height calculation occurs when element is initially hidden upon DOM load but is later displayed

Currently, I am facing an issue with an SVG that has a CSS width of 100% and height of 100%. The wrapping element spans the entire width of the screen while its height is set to auto. It's important to note that the wrap div determines the dimensions ...

jQuery registers the enter event, but does not proceed to trigger the enter action

Hey there, I've been experimenting with jQuery to capture the enter event. Something peculiar is happening though - after pressing enter in the text area, an alert pops up but the text gets entered only after that. Despite trying various solutions, I ...

Boosted by Bootstrap 4 running smoothly on Internet Explorer version 10

I'm starting to have second thoughts about my decision to move to B4. I'm currently troubleshooting the navigation in IE 10 using their example: https://getbootstrap.com/docs/4.0/examples/jumbotron/ After checking it on IE 10, I noticed that th ...

Bootstrap's grid width is not aligned properly

I am a newcomer to Boostrap and I find myself in a bit of a sticky situation...I have tried numerous solutions, consulted the Boostrap documentation, but I still require assistance. Here is the code snippet: <link rel="stylesheet" href=" ...

What is the process for defining a date range in HTML5?

I am currently working on a wedding website and I am trying to set up a countdown for the wedding date. However, I am having trouble figuring out how to correctly display the countdown. https://i.sstatic.net/iGikh.png Here is the code snippet that I am u ...

Dynamic content display using AJAX

Having already tried to find a solution through Google with no success, I am at a loss. I have articles where a paragraph is initially displayed, followed by a "read more" link which reveals more content using JavaScript. However, this approach may slow do ...

When provided with no input, the function will output true

I'm having trouble understanding this problem! I've implemented a basic jQuery validation that checks if an input field is empty when a button is clicked. http://fiddle.jshell.net/fyxP8/3/ I'm confused as to why the input field still retu ...

Is there a way to obtain HTML code within a contentEditable DIV?

When working in a contentEditable-DIV, my goal is to extract the HTML code from the starting position (0) to the end position where the user has clicked. <div id="MyEditableId" contentEditable="true"> 1. Some text 123. <span style="background-c ...