Is there a way to extend a div to occupy two rows?

I am attempting to accomplish the following task:

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

Here is my markup:

 <div>
   <div>A</div>
   <div>B</div>
   <div>C</div>
</div>

Can this be achieved using grid, bootstrap, or flex without altering the order of elements?

Answer №1

There are multiple ways to achieve this.

One approach is to utilize the grid method and then implement grid-template to address the issue at hand.

.container {
  display: grid;
  grid-template:
    "a b"
    "c b";
}

.a {
  grid-area: a;
  background: red;
}

.b {
  grid-area: b;
  background: blue;
}

.c {
  grid-area: c;
  background: green;
}

Alternatively, you can also employ the use of grid-area.

.container {
  display: grid;
}

.a {
  background: red;
}

.b {
  grid-area: 1 / 2 / 3;
  background: blue;
}

.c {
  background: green;
}

Answer №2

.container {
  height: 300px;
  display: grid;
  grid-template-columns: repeat(2, 50%);
}

.container div {
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.container div:nth-child(1) {
  background-color: green;
}

.container div:nth-child(2) {
  grid-row: 2 span;
  background-color: blue;
}

.container div:nth-child(3) {
  background-color: red;
}
<div class="container">
  <div>A</div>
  <div>B</div>
  <div>C</div>
</div>

Does this achieve the desired outcome? "Grid" is designed for these types of layouts.

Regarding bootstrap - the latest version defaults to using "flex".

Answer №3

To solve the issue, consider adding one more div as shown below.

This solution should prove helpful.

Link to CodePen example

HTML

<div class="container">
      <div class="subcontainer">
        <div class="box blue">BOX 1</div>
        <div class="box red">BOX 3</div>
      </div>
      <div class="box green">
         Box 2
      </div>
    <div>

CSS

.container {
  display: flex;
}

.box {
  width: 60px;
  height: auto;
}

.red {
  background: red;
}

.blue {
  background: blue;
}

.green {
  background: green;
}

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

Expandable Checkout Form for Woocommerce

I need help troubleshooting a WooCommerce collapsible checkout form using Bootstrap Collapse. Below is the HTML markup I am currently using: <div class="panel-group" id="checkout-accordion"> <div class="panel panel-default" id="panel-billing"&g ...

Buttons and links with intricate geometries

I am currently developing a web application using Java/JSF and I am interested in finding out about technologies that would allow me to define intricate shapes as clickable buttons or links. Right now, my only option is to split an image into smaller trans ...

Using padding and float properties in the a tag of HTML does not result in the expected behavior

I am attempting to display the menu in a left-to-right fashion, however I am encountering issues with using padding and float in HTML. Here is my current code: .main-nav ul li a { padding-right: 15px; float: left; } <div class="main-nav"> &l ...

Implement a counter in a JavaScript table, initializing it to zero

I have successfully written my code, but there is one issue. The first row is starting with the number one instead of zero. I'm looking for suggestions on how to start from zero. Any help would be greatly appreciated. Thanks! <script> var tabl ...

Don't forget to keep track of when the user has closed

How can I ensure that the cache retains the user's action of closing the div? Currently, when I close the div and refresh the page, it reverts back to its original state. Is there a way to make this change persistent? Experience it live: Here is the ...

The bottom of the page displays varying outcomes between Code Snippet (CodePen) and Angular

I had the idea of having my footer cover the entire length of the page and stick to the bottom, adjusting itself if more content is added. However, I encountered an issue where on Codepen everything works perfectly, but on Angular (14), the footer does not ...

Vanishing Span in CSS3 Flexboxes

I came across this particular HTML code: <div class="panel panel-info"> <div class="panel-heading">Person</div> <div class="panel-body"> <div class="data"> <p class="keys"> ...

Host your own website online using your personal computer

So I have created a simple HTML page that I want to publish on the Internet using my PC. This is just for testing purposes, so I don't require a static IP address or high uptimes. First, I installed Tomcat Apache and placed my WAR file in the webapps ...

How can I center two images using a hover effect in WordPress?

When the mouse hovers over an image, it changes to another image. Everything works smoothly except for one issue - the image is not centered. Below is the code I am currently using: HTML: <figure> <a> <img class="hover" src="na ...

How do you set a background image for the color of the font?

Imagine I have this piece of code: <span>Hello world!</span> Along with the following CSS: span{ color:red; } Is it possible to replace the red value with an image? Something like url(images/text-bg.png);? I am looking to add a texture to m ...

Output MySQL information into an HTML form with radio buttons and an additional text field

Users are able to input product data into a MySQL database through my web form. They can choose between three main suppliers using radio buttons (Sigma-Aldrich, VWR, and Filter-Service), or select 'other' and specify a different supplier in a tex ...

What is the method for customizing the color of the drop-down arrow in

Is it possible to customize the color of the dropdown arrow while maintaining the same style? #cars{ width:150px; } <!DOCTYPE html> <html> <body> <select name="cars" id="cars"> <option value="volvo">Volvo</option& ...

TinyMCE file multimedia upload feature allows users to easily add audio, video

I am looking to enhance the functionality of my TinyMCE Editor by enabling file uploads for audio/video and images. Although image uploading is functioning properly, I am encountering issues with other types of files. Despite setting up pickers throughout, ...

Troubleshooting: How can I ensure my custom scrollbar updates when jQuery niceselect expands?

I am currently utilizing the jquery plugins mCustomScrollbar and niceselect. However, I have encountered an issue when expanding the niceselect dropdown by clicking on it - the mCustomScrollbar does not update accordingly. I suspect this is due to the abso ...

Attempting to implement scroll-based animation on my webpage

Having trouble integrating this animation (from codepen) into my website. It works fine on its own, but when I try to add it to my site, it doesn't show up. I want it to appear in the middle at the bottom of the background image. Check out the codepe ...

What is the best way to access the form button inside a div element?

Here is the code snippet for my form: <form accept-charset="utf-8" action="https:example.com" method="get" name="test"> <div class="classy"><input type="button" class="buttonE ...

JavaScript error leading to ERR_ABORTED message showing up in the console

When I try to load my HTML page, my JavaScript code keeps throwing an error in the console. I am attempting to import some JavaScript code into VSCode using an app module for future reuse. The code is being run through a local server. Error Message: GET ...

supplying various color variables to a single class

I am working on a webpage with multiple elements sharing the same CSS class. I want each element to have a unique background color, but I don't want to create a bloated CSS file. Is there a way to achieve this by adding a parameter in my HTML like cla ...

Design a custom cover page before printing using the window.print() method

When it comes to printing, I have a header and footer displayed on each page. However, I want the first page to be clean with just a picture or title, without the header and footer that appear on subsequent pages. I've attempted to use CSS like this ...

Align content to the bottom using Bootstrap 4

Looking for help with aligning content to the middle and bottom on a full-page bootstrap layout? The first page has a background image in the first div, and a darker layer on top in the second div. <div class="h-100 w-100"> <div class="h-100 w-10 ...