align divs side by side - html

I want to align divs side by side but the padding doesn't let the divs to align side by side and I'm not allowed to remove padding or change anything. just need to add a property and i don't know what property I should add.
Here's the code:
body {
padding: 30px;
}
section {
background: lightgreen;
width: 75%;
float: left;
}
article {
background: white;
margin: 0 0 1rem 0;
}
aside {
background: pink;
width: 25%;
float: right;
}
header,
article,
section,
.module {
padding: 1rem;
}
<section>
<article>
<h2>Title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo
molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab
doloremque accusamus iusto aliquam facilis sapiente!
</p>
</article>
<article>
<h2>Title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo
molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab
doloremque accusamus iusto aliquam facilis sapiente!
</p>
</article>
</section>
<aside>
<div className="module">
<h3>Module</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio rem
ab delectus fugit repellendus perspiciatis dolor consequuntur
tenetur voluptatem a vitae odit aspernatur? Voluptas quisquam
corporis nostrum aspernatur aliquid harum saepe ab pariatur veniam
iste ipsam alias nemo voluptatibus doloribus.
</p>
</div>
</aside>

box-sizing CSS will fix this issue.
Add default box-sizing property to border-box
* {
box-sizing: border-box;
}

Related

Make each section appear to the left/right of the line in the middle

I have this green line down the middle of the page, how can I make it so that each section appears on the left then the right, for example section 1 at the top and to the left, section2 on the right hand side and a little lower than the next one.
So on so forth
#line {
height: 500px;
width: 5px;
border: 1px solid green;
background: green;
position: relative;
left: 50%;
}
<div class='about'>
<h2>About</h2>
<p>A little journey throguh my life/career</p>
<div class='timeline'>
<div id='line'></div>
<div id='section1'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section2'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section3'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section4'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section5'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
</div>
</div>
Generating the line as a separate element is just going to cause you problems giving it the right height.
Make the line a border, and use the odd or even position of the div to design which side to push it to and which side to draw the line on.
.timeline > div {
overflow: hidden;
margin: 0;
padding: 0;
}
.timeline > div:nth-child(odd) {
margin-right: calc(50% - 3px);
border-right: 5px solid green;
}
.timeline > div:nth-child(even) {
margin-left: calc(50% - 3px);
border-left: 5px solid green;
}
<div class='about'>
<h2>About</h2>
<p>A little journey throguh my life/career</p>
<div class='timeline'>
<div id='section1'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section2'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section3'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section4'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section5'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
</div>
</div>
Try:
#section1,
#section3,
#section5{
float: left;
clear: both;
}
#section2,
#section4{
float: right;
clear: both;
}
Without changing the HTML structure, you can do it like this:
1) Add a class to the sections, something like .section.
<div class="section" id='section1'>
...
</div>
<div class="section" id='section2'>
...
</div>
<div class="section" id='section3'>
...
</div>
...
2) Then, change the relative position to absolute position for the line element, so it will be absolutely positioned in the middle.
#line {
height: 500px;
width: 5px;
border: 1px solid green;
background: green;
position: absolute;
left: 50%;
}
3) Finally, make each section 50% of the total width and use nth-of-type() selector to make it alternating from left to right using a margin-left for the sections that will be on the right side.
.timeline .section:nth-of-type(2n) {
margin-left: 50%;
}
.section {
width: 50%;
}
If you want to make each section a little lower than the previous one, you can add some negative margin, which is a little bit hacky, but can work well in this case.
The first section doesn't need it. The selector is number 2 because it is the second child, not the first. The first is the about div element.
.section {
margin-top: -50px;
}
.timeline .section:nth-of-type(2) {
margin-top: 0;
}

Section Leak generating horizontal scroll

I'm trying to create a way to leak an element from it's parent container.
I'm using max-width and margin: auto for the container to center.
The child element has position: relative and uses left + translateX transform to become centered.
The CSS works OK until the page gets scrolling (content height higher than screen height).
This vertical scroll also generates horizontal scrolling.
I was able to hide it using overflow-x: hidden but i really want to know why i'm getting an horizontal scroll?
Maybe is because the transform? CODE BELOW (see in fullscreen):
.leaked {
position: relative;
left: 50%;
transform: translatex(-50%);
width: 100vw;
margin: 0;
overflow: hidden;
}
.container {
padding: 0 20px;
margin: 0 auto;
max-width: 960px;
position: relative;
}
/* EXTRA */
.block {
padding: 20px 0;
background: darkred;
color: white;
}
body {
-webkit-font-smoothing: antialiased;
}
img {
max-width: 100%;
height: auto;
}
figcaption {
text-align: center;
color: gray;
font-size: 0.8em;
}
.force-scroll {
height: 100vh;
}
<article class="container">
<header>
<h1>Article title</h1>
<small>To see in action, use and 1024px wide screen or larger</small>
</header>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Enim dolore quaerat quos ex quo laborum officiis maxime molestias cum omnis. Veritatis quas, molestiae nihil soluta inventore provident minus nostrum atque!</p>
<figure class="leaked">
<img src="http://via.placeholder.com/1920x800" alt="Example figure" width="1920" height="800">
<figcaption>An example figure</figcaption>
</figure>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Enim dolore quaerat quos ex quo laborum officiis maxime molestias cum omnis. Veritatis quas, molestiae nihil soluta inventore provident minus nostrum atque!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint quis pariatur totam nostrum explicabo doloremque quaerat! Ipsum odit dolor ut corrupti hic quae provident voluptates saepe commodi, id culpa praesentium?</p>
<section class="leaked block">
<div class="container">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ut accusantium doloribus aspernatur laboriosam! Voluptatem blanditiis doloremque earum ab alias, modi repudiandae eveniet autem fugiat facilis ducimus? Veniam laboriosam nobis ab!
</p>
</div>
</section>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque voluptates voluptas eveniet suscipit fugiat. Quidem nesciunt ducimus veritatis, sed repudiandae perferendis nam fugiat! Laborum minus consequatur hic. Ut, dolorum facilis.</p>
<div class="force-scroll">This is only to force an scroll</div>
</article>
According to documentation
The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they have scaled accordingly.
However, when the value of overflow on the root element is auto, any
scrollbars are assumed not to exist.
So there is no way to without js to get width without scrollbars :(
It's the width on .leaked. I changed the width from 100vw to 100% and the image reduces in size so it now fits in the container.
.leaked {
width: 100%;
//other styles
}
But if you do want the leaked content to go full width you need to change your html structure so .leaked sections are not inside the container, that way it will go full width:
<article class="container">
<header>
<h1>Article title</h1>
<small>To see in action, use and 1024px wide screen or larger</small>
</header>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Enim dolore quaerat quos ex quo laborum officiis maxime molestias cum omnis. Veritatis quas, molestiae nihil soluta inventore provident minus nostrum atque!</p>
</article>
<figure class="leaked">
<img src="http://via.placeholder.com/1920x800" alt="Example figure" width="1920" height="800">
<figcaption>An example figure</figcaption>
</figure>
<article class="container">
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Enim dolore quaerat quos ex quo laborum officiis maxime molestias cum omnis. Veritatis quas, molestiae nihil soluta inventore provident minus nostrum atque!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint quis pariatur totam nostrum explicabo doloremque quaerat! Ipsum odit dolor ut corrupti hic quae provident voluptates saepe commodi, id culpa praesentium?</p>
</article>
<section class="leaked block">
<div class="container">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ut accusantium doloribus aspernatur laboriosam! Voluptatem blanditiis doloremque earum ab alias, modi repudiandae eveniet autem fugiat facilis ducimus? Veniam laboriosam nobis ab!
</p>
</div>
</section>
<article class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque voluptates voluptas eveniet suscipit fugiat. Quidem nesciunt ducimus veritatis, sed repudiandae perferendis nam fugiat! Laborum minus consequatur hic. Ut, dolorum facilis.</p>
<div class="force-scroll">This is only to force an scroll</div>
</article>

How can I use flexbox to achieve a floating sidebar layout with content that wraps around the sidebar?

I'm trying to achieve a responsive layout that looks like this on desktop:
And like this on mobile:
Note the following requirements:
Sidebar should only take up as much space vertically as is necessary to fit the content. Below the sidebar, content from the main section should take up the full width.
On mobile, the sidebar should appear below the main content.
Here is a jsfiddle containing my initial HTML and CSS:
https://jsfiddle.net/sergkr/np6k2tj3/
and a snippet:
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
padding: 0 2em;
line-height: 1.4;
color: #333;
background-color: #fff
}
section {
margin: 1.6em 0;
}
section>h2 {
margin: 0;
padding: 12px 24px;
font-size: 16px;
background: #eceeee;
text-transform: uppercase;
}
section>p {
margin: 0;
padding: 12px 24px;
background: #fafafa;
}
.container {
display: flex;
flex-wrap: wrap;
}
main {
flex-basis: 100%;
}
.sidebar {
padding: 0 2em;
background: #fbf6f4;
}
#media screen and (min-width: 1024px) {
.container {
flex-wrap: nowrap;
}
main {
flex: 1 1 70%;
}
.sidebar {
flex: 0 0 30%;
margin-left: 2em;
}
}
<div class="container">
<main>
<h1>Main</h1>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa eaque hic voluptates quas minus minima, officiis, quaerat animi illum dolor est ipsum maiores sunt sint, velit consequatur illo perspiciatis magni!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum placeat animi illum, a cumque ab illo soluta saepe dicta, deleniti voluptatibus ratione modi pariatur laudantium, nulla libero earum, ea molestias.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem sapiente labore eos quia assumenda quod perspiciatis odio sit, hic incidunt, eum, inventore qui veniam ex iure voluptatum deleniti accusamus quidem.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, quasi laudantium neque, dolor illo repellat totam fugiat veritatis sit harum, quam asperiores error minima ducimus id. Repellat ea, omnis veniam.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste vel harum, ratione voluptas qui odit ea ipsum ipsa distinctio laborum? Ut voluptate, accusantium alias, autem hic dignissimos corporis quas cum!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum praesentium, aut! Nam officiis tempora reprehenderit, dignissimos minus voluptatum ullam. Doloremque quis dolorem tempora incidunt maiores iusto similique cumque atque repellendus?
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est ab fugit repellendus exercitationem, incidunt perspiciatis, accusamus deserunt dolores molestias odio tenetur iure nesciunt! Officiis debitis, cumque impedit odit vero earum.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores ratione doloribus repellat molestias dolorum quae, iste, quo corrupti impedit consequuntur quod ex magnam recusandae dolorem dignissimos incidunt, ducimus, quia ipsum.
</p>
</section>
</main>
<div class="sidebar">
<h1>Sidebar</h1>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam deleniti officia nobis atque voluptatum maxime voluptas ipsum rerum accusantium repudiandae quae quia, quam quis. Consectetur dolorem excepturi assumenda reprehenderit accusantium.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos ab laborum numquam dolore eius, aperiam amet cumque. Laboriosam aut at cupiditate quis ea blanditiis eveniet, dolorum. Autem at, quisquam dolorem.
</p>
</section>
</div>
</div>
Note there is wasted space below the sidebar. I want the main content to wrap around and take up the full width after the sidebar ends, but I'm not sure how to achieve that.
I thought about using float: right on the sidebar and putting it before the <main>, but that results in the sidebar appearing first on mobile (I want it to appear after the content).
Is there a way to achieve the desired layout given the above requirements, either using flexbox, float, or some other technique?
you can switch display and order with float. In order to use float you will need aside being first in HTML, so content can wrap around. flex and order will send it back to bottom on mobile.
Example or snippet below with HTML update to switch from a flex layout to a float layout
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
padding: 0 2em;
line-height: 1.4rem;
color: #ddd;
background-color: #333
}
section {
color:#333;
margin: 1.6em 0;
}
section > h2 {
margin: 0;
padding: 12px 24px;
font-size: 16px;
background: #ace;
text-transform: uppercase;
}
section > p {
margin: 0;
padding: 12px 24px;
background: #fafafa;
}
.container {
overflow:hidden;
}
main {
display:flex;
flex-direction:column;
}
.sidebar {
padding: 0 2em;
background: tomato;
order:2;
}
#media screen and (min-width: 1024px) {
.container {
}
main {
display:block;
}
main h1 {
float:left;
width:70%;
}
main section {
clear:left;
overflow:hidden;
}
.sidebar {
width:25%;
float:right;
margin-left:2em;
}
}
<div class="container">
<main>
<h1>Main</h1>
<aside class="sidebar">
<h1>Sidebar</h1>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam deleniti officia nobis atque voluptatum maxime voluptas ipsum rerum accusantium repudiandae quae quia, quam quis. Consectetur dolorem excepturi assumenda reprehenderit accusantium.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos ab laborum numquam dolore eius, aperiam amet cumque. Laboriosam aut at cupiditate quis ea blanditiis eveniet, dolorum. Autem at, quisquam dolorem.
</p>
</section>
</aside>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa eaque hic voluptates quas minus minima, officiis, quaerat animi illum dolor est ipsum maiores sunt sint, velit consequatur illo perspiciatis magni!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum placeat animi illum, a cumque ab illo soluta saepe dicta, deleniti voluptatibus ratione modi pariatur laudantium, nulla libero earum, ea molestias.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem sapiente labore eos quia assumenda quod perspiciatis odio sit, hic incidunt, eum, inventore qui veniam ex iure voluptatum deleniti accusamus quidem.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, quasi laudantium neque, dolor illo repellat totam fugiat veritatis sit harum, quam asperiores error minima ducimus id. Repellat ea, omnis veniam.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste vel harum, ratione voluptas qui odit ea ipsum ipsa distinctio laborum? Ut voluptate, accusantium alias, autem hic dignissimos corporis quas cum!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum praesentium, aut! Nam officiis tempora reprehenderit, dignissimos minus voluptatum ullam. Doloremque quis dolorem tempora incidunt maiores iusto similique cumque atque repellendus?
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est ab fugit repellendus exercitationem, incidunt perspiciatis, accusamus deserunt dolores molestias odio tenetur iure nesciunt! Officiis debitis, cumque impedit odit vero earum.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores ratione doloribus repellat molestias dolorum quae, iste, quo corrupti impedit consequuntur quod ex magnam recusandae dolorem dignissimos incidunt, ducimus, quia ipsum.
</p>
</section>
</main>
</div>
Updated
Thanks to G-Cyr, who put me in another direction, there is actually a Flexbox/Float combination, making the section flex column containers, which appear to respect the floated element and wrap around it.
All it takes is to add display: flex; flex-direction: column; to the section rule...and it even work with IE11 :)
Fiddle demo
Stack snippet
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
padding: 0 2em;
line-height: 1.4;
color: #333;
background-color: #fff
}
section {
display: flex; /* added */
flex-direction: column; /* added */
margin: 1.6em 0;
}
section > h2 {
margin: 0;
padding: 12px 24px;
font-size: 16px;
background: #eceeee;
text-transform: uppercase;
}
section > p {
margin: 0;
padding: 12px 24px;
background: #fafafa;
}
.container {
display: flex;
flex-wrap: wrap;
}
main {
flex-basis: 100%;
}
.sidebar {
order: 1;
padding: 0 2em;
background: #fbf6f4;
}
#media screen and (min-width: 1024px) {
.container {
display: block;
}
.sidebar {
float: right;
width: 30%;
margin: 0 2em;
}
}
<div class="container">
<div class="sidebar">
<h1>Sidebar</h1>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam deleniti officia nobis atque voluptatum maxime voluptas ipsum rerum accusantium repudiandae quae quia, quam quis. Consectetur dolorem excepturi assumenda reprehenderit accusantium.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos ab laborum numquam dolore eius, aperiam amet cumque. Laboriosam aut at cupiditate quis ea blanditiis eveniet, dolorum. Autem at, quisquam dolorem.
</p>
</section>
</div>
<main>
<h1>Main</h1>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa eaque hic voluptates quas minus minima, officiis, quaerat animi illum dolor est ipsum maiores sunt sint, velit consequatur illo perspiciatis magni!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum placeat animi illum, a cumque ab illo soluta saepe dicta, deleniti voluptatibus ratione modi pariatur laudantium, nulla libero earum, ea molestias.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem sapiente labore eos quia assumenda quod perspiciatis odio sit, hic incidunt, eum, inventore qui veniam ex iure voluptatum deleniti accusamus quidem.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, quasi laudantium neque, dolor illo repellat totam fugiat veritatis sit harum, quam asperiores error minima ducimus id. Repellat ea, omnis veniam.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste vel harum, ratione voluptas qui odit ea ipsum ipsa distinctio laborum? Ut voluptate, accusantium alias, autem hic dignissimos corporis quas cum!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum praesentium, aut! Nam officiis tempora reprehenderit, dignissimos minus voluptatum ullam. Doloremque quis dolorem tempora incidunt maiores iusto similique cumque atque repellendus?
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est ab fugit repellendus exercitationem, incidunt perspiciatis, accusamus deserunt dolores molestias odio tenetur iure nesciunt! Officiis debitis, cumque impedit odit vero earum.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores ratione doloribus repellat molestias dolorum quae, iste, quo corrupti impedit consequuntur quod ex magnam recusandae dolorem dignissimos incidunt, ducimus, quia ipsum.
</p>
</section>
</main>
</div>
And by putting the h2 and the p in a section of their own, also the p by itself will wrap around the floated element
Fiddle demo 2
Stack snippet 2
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
padding: 0 2em;
line-height: 1.4;
color: #333;
background-color: #fff
}
section {
display: flex; /* added */
flex-direction: column; /* added */
}
section:nth-child(2n+2) { /* added */
margin-top: 1.6em;
}
section > h2 {
margin: 0;
padding: 12px 24px;
font-size: 16px;
background: #eceeee;
text-transform: uppercase;
}
section > p {
margin: 0;
padding: 12px 24px;
background: #fafafa;
}
.container {
display: flex;
flex-wrap: wrap;
}
main {
flex-basis: 100%;
}
.sidebar {
order: 1;
padding: 0 2em;
background: #fbf6f4;
}
#media screen and (min-width: 1024px) {
.container {
display: block;
}
.sidebar {
float: right;
width: 30%;
margin: 0 2em;
}
}
<div class="container">
<div class="sidebar">
<h1>Sidebar</h1>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos ab laborum numquam dolore eius, aperiam amet cumque. Laboriosam aut at cupiditate quis ea blanditiis eveniet, dolorum.
</p>
</section>
</div>
<main>
<h1>Main</h1>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa eaque hic voluptates quas minus minima, officiis, quaerat animi illum dolor est ipsum maiores sunt sint, velit consequatur illo perspiciatis magni!
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum placeat animi illum, a cumque ab illo soluta saepe dicta, deleniti voluptatibus ratione modi pariatur laudantium, nulla libero earum, ea molestias.
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem sapiente labore eos quia assumenda quod perspiciatis odio sit, hic incidunt, eum, inventore qui veniam ex iure voluptatum deleniti accusamus quidem.
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, quasi laudantium neque, dolor illo repellat totam fugiat veritatis sit harum, quam asperiores error minima ducimus id. Repellat ea, omnis veniam.
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste vel harum, ratione voluptas qui odit ea ipsum ipsa distinctio laborum? Ut voluptate, accusantium alias, autem hic dignissimos corporis quas cum!
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum praesentium, aut! Nam officiis tempora reprehenderit, dignissimos minus voluptatum ullam. Doloremque quis dolorem tempora incidunt maiores iusto similique cumque atque repellendus?
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est ab fugit repellendus exercitationem, incidunt perspiciatis, accusamus deserunt dolores molestias odio tenetur iure nesciunt! Officiis debitis, cumque impedit odit vero earum.
</p>
</section>
<section>
<h2>Section</h2>
</section>
<section>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores ratione doloribus repellat molestias dolorum quae, iste, quo corrupti impedit consequuntur quod ex magnam recusandae dolorem dignissimos incidunt, ducimus, quia ipsum.
</p>
</section>
</main>
</div>
Short answer is "No, that won't be possible using Flexbox".
inline elements though, they will wrap around a floated element.
With that inline elements we can accomplish something that is similar, which it has some drawbacks though, where the difficult part is to have the background color fill the available space, so here is how it could look like w/o.
See the notes in the CSS
Fiddle demo
Stack snippet
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
padding: 0 2em;
line-height: 1.4;
color: #333;
background-color: #fff
}
section {
display: inline; /* changed display type */
/*margin: 1.6em 0;*/ /* have no effect on inline element */
}
section > h2 {
display: inline; /* changed display type */
/*margin: 0;*/ /* have no effect on inline element */
padding: 12px 24px;
font-size: 16px;
background: #eceeee;
text-transform: uppercase;
}
section > p {
display: inline; /* changed display type */
/*margin: 0;*/ /* have no effect on inline element */
/*padding: 12px 24px;*/ /* won't work properly on
multiline inline element */
/*background: #fafafa;*/ /* removed as it does not look good */
}
section > p::before,
section > p::after {
content:"\A\A"; /* create 2 line break's */
white-space: pre; /* or pre-wrap */
}
.container {
display: flex;
flex-wrap: wrap;
}
main {
flex-basis: 100%;
}
.sidebar {
order: 1;
padding: 0 2em;
background: #fbf6f4;
}
#media screen and (min-width: 1024px) {
.container {
display: block;
}
.sidebar {
float: right;
width: 30%;
margin: 0 2em;
}
}
<div class="container">
<div class="sidebar">
<h1>Sidebar</h1>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam deleniti officia nobis atque voluptatum maxime voluptas ipsum rerum accusantium repudiandae quae quia, quam quis. Consectetur dolorem excepturi assumenda reprehenderit accusantium.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos ab laborum numquam dolore eius, aperiam amet cumque. Laboriosam aut at cupiditate quis ea blanditiis eveniet, dolorum. Autem at, quisquam dolorem.
</p>
</section>
</div>
<main>
<h1>Main</h1>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa eaque hic voluptates quas minus minima, officiis, quaerat animi illum dolor est ipsum maiores sunt sint, velit consequatur illo perspiciatis magni!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum placeat animi illum, a cumque ab illo soluta saepe dicta, deleniti voluptatibus ratione modi pariatur laudantium, nulla libero earum, ea molestias.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem sapiente labore eos quia assumenda quod perspiciatis odio sit, hic incidunt, eum, inventore qui veniam ex iure voluptatum deleniti accusamus quidem.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, quasi laudantium neque, dolor illo repellat totam fugiat veritatis sit harum, quam asperiores error minima ducimus id. Repellat ea, omnis veniam.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste vel harum, ratione voluptas qui odit ea ipsum ipsa distinctio laborum? Ut voluptate, accusantium alias, autem hic dignissimos corporis quas cum!
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum praesentium, aut! Nam officiis tempora reprehenderit, dignissimos minus voluptatum ullam. Doloremque quis dolorem tempora incidunt maiores iusto similique cumque atque repellendus?
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est ab fugit repellendus exercitationem, incidunt perspiciatis, accusamus deserunt dolores molestias odio tenetur iure nesciunt! Officiis debitis, cumque impedit odit vero earum.
</p>
</section>
<section>
<h2>Section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores ratione doloribus repellat molestias dolorum quae, iste, quo corrupti impedit consequuntur quod ex magnam recusandae dolorem dignissimos incidunt, ducimus, quia ipsum.
</p>
</section>
</main>
</div>

How do you align 2 columns inner paragraph text when headers vary in size using flexbox?

CODEPEN
How can I align my paragraphs between columns when my h1s vary in size? caveat I have no control over the size of headers and therefore cannot add a static height.
Align to the crosshairs.
HTML:
<div class="paddingBlock">
<h1>Align the paragraphs to dynamic height h1s</h1>
<p>How do I make sure the paragraphs align w/o a fixed height on headers ?</p>
<div class="eqWrap">
<div class="eq">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium numquam quibusdam quis, deleniti placeat quas vitae ex </h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam harum commodi impedit.</p>
</div>
<div class="eq">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem nesciunt aliquam magni corporis dolor, assumenda similique nisi doloremque repudiandae, consequatur, reprehenderit. Explicabo dolorum consequatur quasi consequuntur, qui adipisci saepe ipsam!</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam harum commodi impedit.</p>
</div>
</div>
</div>
CSS:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
height: 100%;
width: 100%;
}
body {
font-family: sans-serif;
line-height: 1.4;
}
h1 {
font-size: 150%;
}
p {
margin-bottom: 10px;
}
.eqWrap {
display: flex;
}
.eq {
width: 50%;
padding: 10px;
}
.eq:nth-child(1) {
background: papayawhip;
}
.eq:nth-child(2) {
background: maroon;
}
One thing you can try is to make your content boxes (.eq) flex containers, then use auto margins to pin the paragraphs to the bottom:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
height: 100%;
width: 100%;
}
body {
font-family: sans-serif;
line-height: 1.4;
}
h1 {
font-size: 150%;
}
.eqWrap {
display: flex;
}
.eq {
width: 50%;
padding: 10px;
display: flex; /* NEW */
flex-direction: column; /* NEW */
}
p {
margin-top: auto; /* NEW */
margin-bottom: 10px;
}
<div class="paddingBlock">
<h1>Align the paragraphs to dynamic height h1s</h1>
<p>How do I make sure the paragraphs align w/o a fixed height on headers ?</p>
<div class="eqWrap">
<div class="eq">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium numquam quibusdam quis, deleniti placeat quas vitae ex </h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam harum commodi impedit.</p>
</div>
<div class="eq">
<h1>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem nesciunt aliquam magni corporis dolor, assumenda similique nisi doloremque repudiandae, consequatur, reprehenderit. Explicabo dolorum consequatur quasi consequuntur, qui adipisci saepe ipsam!</h1>
<p>Align these paragraphs. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam
harum commodi impedit.</p>
</div>`
</div>
Revised Codepen
Depending on the size of each paragraph, and where you want your h1 aligned, you may need to adjust the auto margins. Here are some examples: Methods for Aligning Flex Items

Where is the sidebar in this pen?

How can you fix sidebar issue here:
http://codepen.io/chriscoyier/pen/ClGcF
body {
padding: 30px;
}
header {
background: lightblue;
}
section {
background: lightgreen;
width: 75%;
float: left;
}
article {
background: white;
margin: 0 0 1rem 0;
}
aside {
background: pink;
width: 25%;
float: right;
}
header,
article,
section,
.module {
padding: 1rem;
}
<main>
<header>
<h1>Site</h1>
</header>
<section>
<article>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab doloremque accusamus iusto aliquam facilis sapiente!</p>
</article>
<article>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab doloremque accusamus iusto aliquam facilis sapiente!</p>
</article>
</section>
<aside>
<div class="module">
<h3>Module</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio rem ab delectus fugit repellendus perspiciatis dolor consequuntur tenetur voluptatem a vitae odit aspernatur? Voluptas quisquam corporis nostrum aspernatur aliquid harum saepe ab pariatur
veniam iste ipsam alias nemo voluptatibus doloribus.</p>
</div>
</aside>
</main>
The goal is to have the sidebar move back to the top.
My confusion:
Where is the sidebar there inside the pen?
<aside> is the sidebar part.
In your css:
*,*:after,*:before { box-sizing: border-box; }
You can read about box-sizing following this link: http://www.paulirish.com/2012/box-sizing-border-box-ftw/
The problem is that you are telling the program to take up 100% of the pagewidth. If you reduce the two widths to 70% and 20-25%, the sidebar will float right, adjacent to the main content body.