Create a CSS layout with two columns that each take up 50% of the

Is there a way to create a 2 column div with equal width of 50% each, without using floats? Yes, by setting the display property to inline-block. However, a problem arises when attempting to set both columns to exactly 50% - the second div ends up going down to the next line.

#first{
       background-color: aqua;
       display:inline-block;
       width: 50%;
   }
   #second{
       background-color: blueviolet;
       display: inline-block;
       width: 50%;         
   }

I even attempted adjusting the box-sizing property, but unfortunately it did not resolve the issue at hand.

Any suggestions on how to overcome this obstacle?

Answer №1

To achieve this effect, make use of flexbox.

.container {
  display: flex;
}

.first,
.second {
  flex: 1;
  height: 60px;
}

.first {
  background: red;
}

.second {
  background: blue;
}
<div class="container">
  <div class="first"></div>
  <div class="second"></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

Can you tell me why one of these Sass codes is throwing an invalid CSS error while the other is not?

My code: @for $j from 1 to 6 { .text-#($j) { font-size: 15px * $j; } } I'm facing an issue where my code doesn't run as expected. In an attempt to fix this, I modified it to use a 'through' keyword instead of 'to' in the loop ...

Opacity of background color only applies to the color

So, here's the scenario - I currently have a background that looks like this: background:url(../img/arrow_lch.png) right no-repeat #2e443a; The challenge I'm facing is how to decrease the opacity of only the background color (#2e443a). Any sugg ...

What is the reason for the presence of the ^ symbol in this drop-down menu?

Just came across a great script, check it out here! Noticed the drop down has a ^ on top. The CSS I found for this is as follows: #colorNav li ul li:first-child:before{ content:none; position:absolute; width:1px; height:1px; border:5 ...

Utilize jQuery to retrieve data attributes and set them as CSS properties in a key-value format

Looking at the HTML below: <h4 data-padding-top="100" data-padding-left="0" data-text-align="left" data-color="#ffffff">Promotion Two</h4> I aim to use the data attributes as CSS styles for the H4 element. I have attempted to achieve this ...

Can an advertisement's appearance be altered to include custom content using only CSS?

Dealing with SAP for our ticket system has been quite a challenge due to the design that is causing some frustration. In an attempt to make it more tolerable, I used CSS to make some adjustments. However, my problem now lies in the fact that they keep maki ...

Combining Jquery scripts for seamless integration

I am facing an issue while trying to execute two different jQuery scripts simultaneously - one named balancedgallery and the other museum. Individually, each script works perfectly fine. However, when running them together, the balancedgallery script seems ...

Unlimited height dialog overlay exclusive to Facebook

It seems like a crucial matter that needs attention. My dialog has an overlay with specific width settings as shown below: .ui-widget-overlay { width: 518px !important; } The height of the overlay will vary based on the page size controlled by JavaS ...

Challenges arise when creating a complementary php script for a natural language form

I'm a beginner at this and all the PHP I've tried hasn't been successful. I've come across examples of Natural Language forms, but none with functional PHP. While I am familiar with PHP in traditional forms, integrating the two has been ...

display the information stored within the sports attribute using React

I am attempting to display the values stored in the sports property. So, I inserted a console log within the sports property. However, an error is being thrown: Syntax error: C:/codebase/src/containers/sports.js: Unexpected token, expec ...

CSS alert problem encountered

I have an HTML and CSS notification template that I would like to incorporate into my PHP code. You can view the template here. HTML <div class="alert-box error"><span>error: </span>Write your error message here.</div> &l ...

Is there a way for me to utilize the Bootstrap carousel without it adjusting the height as the user transitions from slide 1 to slide 2?

body{ background-color: #CAF7E3; } .container-fluid{ padding: 3% 15%; } .navbar{ font-family: 'Montserrat'; font-weight: bold; } .navbar-brand{ font-size: 2.5rem; } .nav-item{ margin-right: 2rem; } #title{ padding: 8% 15%; backgr ...

I'm trying to get the following code to work on my HTML page, but I'm not sure which jQuery script I need to link

I'm struggling to make this code work in a standalone HTML file: http://jsfiddle.net/J8XaX/2/ Here is the script I am using: var divs = $('.fademe'); $(window).on('scroll', function() { var st = $(this).scrollTop(); divs.cs ...

"Exploring the option of using a fly-in feature to add multiple items with checkboxes in HTML

I need to implement a feature where I can select multiple items using checkboxes and retrieve them when a popup is closed. Here's what I want to achieve: Is there a way to accomplish this? Imagine I have a div with several items, and I want to displ ...

CSS fails to function properly on websites hosted on nginx servers

During the process of creating a static website, I utilized VS Code and Live Server on my Windows machine. The site appeared to function properly. However, upon transferring the files to my CentOS machine to run the site through nginx, the site loaded cor ...

Using CSS/HTML5 with either the :target or :active selector can allow for the display of different text content when a

Is it possible to change the text displayed on a website without reloading the page when a link is clicked? For instance, if I have an "About" or "Contact" link on my personal website, can the text in the body of the page be switched dynamically? In the i ...

The background color of the columns is overwhelming

I would like to create a TV remote control design using bootstrap, but I am encountering some issues. The background color is overflowing and I'm unsure how to fix it. Please take a look at the code and feel free to offer any suggestions! @media scre ...

jQuery Animation Issue: SlideDown Effect Not Working as Expected

I'm feeling quite confused about this situation. I've been attempting to utilize the slideDown function in jQuery, but when I click on the 'information' div, it just jumps instead of animating smoothly. I suspect that one of the cause ...

Moving from one page to another

I am attempting to create a transition effect between sections within a single-page application. All the sections are contained on the same page, with only one section displayed at a time while the rest are set to display none. When a specific event is tri ...

The font-face declaration is not in accordance with the correct syntax outlined by fontspring, generating an error

I've been attempting to change my font using the font-face rule, but it's not working. Every time I try, it displays an error saying "@font-face declaration doesn't follow the fontspring bulletproof syntax". I've searched online for a s ...

Issues with loading CSS, JavaScript, and links when deploying a Spring Boot application as a WAR file in Tomcat

My Spring boot web application runs smoothly as an executable jar, but when I build it as a war and deploy it to Tomcat, the CSS and JS files fail to load. Upon further investigation, I discovered that all links are pointing to the root context path "/" I ...