What is the best way to split a section into two articles of the same width?

My challenge is to create a layout with two articles inside a section, each with equal width and bordered with a slight separation in between. The ultimate goal is to have these articles within a section, next to which there will be an aside.

I'm struggling to achieve the desired result of having the articles with equal width while also incorporating borders and a separation between them.

.section-split {
  border: solid;
  margin-top: 5px;
  float: left;
  overflow: hidden;
  width: 84%;
  background-color: white;
  padding: 5px;
}
.section-article1 {
  width: 50%;
  float: left;
  margin-right: 5px;
}
.section-article2 {
  display: inline-block;
  width: 50%;
  margin-right: -330px;
}
.article-orange {
  background-color: orange;
  border: solid;
  width: 100%;
  padding: 10px;
}
.article-red {
  background-color: red;
  float: left;
  width: 100%;
  border: solid;
  padding: 10px;
}
.aside-purple {
  background-color: purple;
  float: left;
  width: 200px;
}
<section class="section-split">
  <section class="section-article1">
    <article class="article-orange">Article 1</article>
  </section>
  <section class="section-article2">
    <article class="article-red">Article 2</article>
  </section>
</section>

<aside class="aside-purple">Aside</aside>

Answer №1

To achieve the desired layout, you need to eliminate white-space, implement box-sizing, and utilize the calc() function.

* {
  box-sizing: border-box;
}
section.sec2 {
  border: solid;
  float: left;
  width: calc(100% - 200px);
  background-color: white;
  padding: 5px;
}
section.sec3 {
  width: calc(50% - 5px);
  display: inline-block;
  vertical-align: top;
  margin-right: 5px;
}
section.sec4 {
  width: 50%;
  display: inline-block;
  vertical-align: top;
}
article.ar1 {
  background-color: orange;
  border: solid;
  width: 100%;
  padding: 10px;
}
article.ar2 {
  background-color: red;
  float: left;
  width: 100%;
  border: solid;
  padding: 10px;
}
aside.as1 {
  background-color: purple;
  float: left;
  width: 200px;
}
<section class="sec2">
  <section class="sec3">
    <article class="ar1">Ar1</article>
  </section><!--
  
  --><section class="sec4">
    <article class="ar2">Ar2</article>
  </section>
</section>
 <aside class="as1">Aside</aside>

Alternatively, you can simplify this process by utilizing Flexbox.

* {
  box-sizing: border-box;
}
.container {
  display: flex;
  align-items: flex-start;
}
section.sec2 {
  border: solid;
  display: flex;
  flex: 1;
  background-color: white;
  padding: 5px;
}
.sec3,
.sec4 {
  flex: 1;
}
article.ar1 {
  background-color: orange;
  border: solid;
  padding: 10px;
}
article.ar2 {
  background-color: red;
  border: solid;
  padding: 10px;
}
aside.as1 {
  background-color: purple;
  flex: 0 0 200px;
}
<div class="container">
  <section class="sec2">
    <section class="sec3">
      <article class="ar1">Ar1</article>
    </section>
    <section class="sec4">
      <article class="ar2">Ar2</article>
    </section>
  </section>
  <aside class="as1">Aside</aside>
</div>

Answer №2

Here's an alternate solution...

To enhance the layout, include an additional div with the style box-sizing: border-box applied universally. You can set the width of the separator DIV to your preference and adjust the two sections using width: calc(50% - 10px), where 10px represents half of the separator's width. The height should be fixed at 1px as there is no content inside. I've included a background color for visibility purposes only:

http://codepen.io/anon/pen/zKWxrV

<section class="sec2">
  <section class="sec3">
    <article class="ar1">Ar1</article>
  </section>
  <div class="vertical_separation">
  </div>
  <section class="sec4">
    <article class="ar2">Ar2</article>
  </section>
</section>

<aside class="as1">Aside</aside>

CSS:

* {
  box-sizing: border-box;
}
section.sec2 {
  border: solid 1px black;
  margin-top: 5px;
  float: left;
  width: 84%;
  background-color: white;
  padding: 5px;
  overflow: hidden;
}

section.sec3 {
  float: left;
  width: calc(50% - 10px);
  display: inline-block;
}

section.sec4 {
  float: left;
  width: calc(50% - 10px);
  display: inline-block;
}

article.ar1 {
  background-color: orange;
  border: solid;
  width: 100%;
  padding: 10px;
}

article.ar2 {
  background-color: red;
  width: 100%;
  border: solid;
  padding: 10px;
}

aside.as1 {
  background-color: purple;
  float: left;
  width: 200px;
}

.vertical_separation {
  float: left;
  width: 20px;
  height: 10px;
  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

Hey there, I'm having trouble with button B. It's not working, do

Why doesn't my Button B display an alert popup? Here are the code snippets from separate files: .html: <html> <body> <input type="button" class="popup" value="BUTTON A"/><br> <input type="button" class="displaymeh ...

Stylus - elements close by: the "+" symbol

For some reason, I am unable to make this work in Stylus: .class1 + .class2 background: red The styles are not being applied to the element. Could it be an issue with my syntax? ...

Reasons and methods for closing the img tag

Should you always close an image tag in HTML? <img src="" alt="" /> Versus <img src="" alt""> I've noticed both methods being used and as someone new to HTML, I'm curious about the correct way. Personally, I prefer closing all my ...

Unveiling the method to fetch the emitted value from a child component and incorporate it into the parent component's return data in Vue

How can I retrieve the title value passed by the Topbar component and incorporate it into the data() return section? I attempted to create a method to pass the value, but was unsuccessful despite being able to successfully log the value in the parent file. ...

The concept of cascading opacity in CSS: exploring nested elements

I'm facing an issue with nesting. The header has an opacity of 0.75, and since the logo and mainNav are nested after the header, they also inherit that opacity. However, I require them to have an opacity of 1. #header { position: relative; padding: 0 ...

Guide to showing a form following a button click in Angular 9

I am trying to create a feature on my page where when I click a button, a form will appear directly below it. Additionally, I would like the number of forms displayed to match the number of times the button is clicked. Being a newcomer to Angular 9, I am ...

jQuery UI - Add character right before the final element

My slider is set to range from 10 to 1000 with increments of 20 (10-30-50, etc). I'm looking to add a character before the value on the last step (1000). Currently, it shows values like "560 kr/h" or "400 kr/h", but I want it to display ">1000 kr ...

The toggle button is unresponsive and the menu fails to slide down smoothly

When the quiz menu is clicked, it slides down to reveal four divs within a single div. Here is the fiddle link for reference: fiddle link. Below is the HTML code: Toggle button for quizzes: <ul> <li id="togglebtn"class="quizli"><a href= ...

Tips for verifying user input prior to taking action

I am fairly new to internet languages and I am trying to understand how to validate user input before calling a method, but I have not been successful so far. <html> <head> </head> <body> <?php $gr ...

What is the method for enclosing the Font Awesome addition symbol within a bordered box to create the appearance of a button?

Here is a sample HTML code: <div id="menu-icon"> <div><i class="fa fa-plus fa-lg"></i></div> </div> And this is the corresponding CSS: #menu-icon { height: 45px; width: 45px; background-color: #A3D8D4; ...

Unable to interpret the JSON reply from the server

I am currently developing a web application that sends data to a website, which then updates its database and returns a JSON array to replace my web app page. I am using AJAX for this query, but I am facing an issue with preventing the overwriting of my we ...

Google Maps introduces a new feature that creates a blur effect on

Currently, I am utilizing the sample code provided below to superimpose an element on a Google map. <!DOCTYPE HTML> <html> <head> <title>Google Map Test</title> <style> html, body { margin: 0; ...

My attempt to use the Redux method for displaying data in my testing environment has not yielded

I've been attempting to showcase the data in a Redux-friendly manner. When the advanced sports search button is clicked, a drawer opens up that should display historical data when the search attributes are selected. For this purpose, I implemented the ...

Strategies for determining the direction of a slide event within a Bootstrap carousel

I am attempting to identify the direction of the slide in a Bootstrap 4 carousel when the user initiates the slide event. Is there a method to achieve this? $('#myCarousel').on('slide.bs.carousel', function () { //Determine wheth ...

Using the <script> attribute within the <head> tag without the async or defer attributes

https://i.stack.imgur.com/cRFaR.pngCurious about Reddit's use of the async or defer attribute in the script tag. Are there situations where blocking the parser is necessary? ...

Using an HTML block within an AJAX request

I'm working on an AJAX code snippet: $('#ShowMore').click(function () { $.ajax({ url: "/Course/GetCoursesJson", dataType: "json", type: "GET", beforeSend: function () { $('#ShowMore').find(&apos ...

I'm having trouble showing the concealed list with JavaScript

I am new to javascript and facing a challenge. Whenever I update the list items in an HTML example from engineer, pilot, technician, if I select engineer, there should be an onchange event calling a function in JavaScript that shows a hidden select list co ...

ReactStrap: Rows and columns causing components to stack on top of each other

When I opt not to utilize Row and Col: <FormGroup> <InputGroup> <InputGroupAddon addonType="prepend"> <InputGroupText> ...

I am looking to transform col-sm-4 into two evenly sized columns with one row at the bottom using Twitter Bootstrap

Hello there, I have successfully created three columns in one row with column sizes of col-sm-4 each. Each column is further split into two equal sections and includes a footer row. You can see the alignment in the image below: Check out this sample align ...

What is the best way to check the difference between the current date and time with another date and

Seeking assistance in comparing 2 dates using JavaScript has been a bit challenging for me. I haven't found the exact solution on this platform yet. As a beginner in JavaScript, I initially assumed that obtaining the current date and time would be a s ...