Content block pushed to the bottom - html

I am currently in the process of writing mark up which has content on either side and an image that floats either left or right towards the top - this works fine.
However, when you introduce too much content on the left or right hand side, the content box does not want to move down but moves up and then moves down to cover the gap. But i would like the gap.
Example Below: If you cant reproduce it below; please try: https://jsfiddle.net/171f14cg/
article {
min-height: 450px;
position: relative;
margin-bottom: 120px;
}
article.art-white-bg {
color: black;
}
article.art-white-bg .content-area-push {
background-color: white;
box-shadow: 0px 18px 26px -5px rgba(0, 0, 0, 0.74);
}
article .content-area-push {
position: absolute;
min-height: 350px;
bottom: 0;
}
article.right-image figure {
right: 0;
}
article figure {
position: absolute;
max-height: 360px;
z-index: 1;
}
article.right-image .art-content {
float: left;
width: 30%;
}
article .art-content {
padding: 50px 45px;
}
<article class="main-article right-image art-white-bg animated hidden visible fadeInUp">
<div class="content-area-push">
<div class="art-content">
<header>
<h2>Working example cause of low amount of content</h2>
</header>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem laborum, autem voluptates ipsam voluptate porro, quibusdam vero. Error, quod, voluptates. Ducimus nulla eum quos sequi, maxime vitae ut autem numquam?</p>
</div>
</div>
<figure>
<img src="https://placeholdit.imgix.net/~text?txtsize=52&txt=550%C3%97350&w=580&h=360" alt="Baby Orang Utan hanging from a rope">
</figure>
</article>
<article class="main-article right-image art-white-bg animated hidden visible fadeInUp">
<div class="content-area-push">
<div class="art-content">
<header>
<h2>Example that does not work</h2>
</header>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem laborum, autem voluptates ipsam voluptate porro, quibusdam vero. Error, quod, voluptates. Ducimus nulla eum quos sequi, maxime vitae ut autem numquam?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem laborum, autem voluptates ipsam voluptate porro, quibusdam vero. Error, quod, voluptates. Ducimus nulla eum quos sequi, maxime vitae ut autem numquam?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem laborum, autem voluptates ipsam voluptate porro, quibusdam vero. Error, quod, voluptates. Ducimus nulla eum quos sequi, maxime vitae ut autem numquam?</p>
</div>
</div>
<figure>
<img src="https://placeholdit.imgix.net/~text?txtsize=52&txt=550%C3%97350&w=580&h=360" alt="Baby Orang Utan hanging from a rope">
</figure>
</article>

I think you're looking for something like this:
https://jsfiddle.net/dee0gjaz/
I removed a number of attributes from several elements. Basically, you were over-styling a little bit. Your text content did not need absolute positioning. That should be static so that it can stretch the parent.
The image however, can remain absolute and with a negative top measure you will have consistent offset.

Related

two <h4>, <img> and<p> tags are grouped in separate<div>s and I've used float for img, used <br> to separate each other <divs> but still they overlap

two h4, img and p tags are grouped in separate < div>s and I've used float for img, used to separate from each other but still they overlap.
https://i.stack.imgur.com/SUxli.png
this is the image with the output.
I'm new to this, can anybody please help. Thank you.
img {
width: 50%;
height: auto;
margin: 20px 10px 20px 0px;
/* float: left; */
}
.service {
margin: 20px auto 20px auto;
text-align: left;
line-height: 2;
}
<div class="service">
<h4>Lorem ipsum dolor sit amet</h4>
<img src="image.jfif" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus ab nulla dolorum autem nisi officiis blanditiis voluptatem hic, assumenda aspernatur facere ipsam nemo ratione cumque magnam enim fugiat reprehenderit expedita.</p>
</div>
<br>
<div class="service">
<h4>Lorem ipsum dolor sit amet</h4>
<img src="image.jfif" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus ab nulla dolorum autem nisi officiis blanditiis voluptatem hic, assumenda aspernatur facere ipsam nemo ratione cumque magnam enim fugiat reprehenderit expedita.</p>
</div>
I would try nesting your code in a container that is flexed with a column flex-direction. Then I would put your <h4>'s before the service div and flex that div also, but use a flex-direction: row; See the CSS changes I made.
.container {
display: flex;
flex-direction: column;
}
p {
padding: 10px;
width: 500px;
margin: auto;
}
img {
width: 50%;
height: auto;
/* float: left; */
}
.service {
text-align: left;
line-height: 2;
display: flex;
flex-direction: row;
}
<div class="container">
<h4>Lorem ipsum dolor sit amet</h4>
<div class="service">
<img src="https://dummyimage.com/600x300/000/fff" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus ab nulla dolorum autem nisi officiis blanditiis voluptatem hic, assumenda aspernatur facere ipsam nemo ratione cumque magnam enim fugiat reprehenderit expedita.</p>
</div>
<br>
<h4>Lorem ipsum dolor sit amet</h4>
<div class="service">
<img src="https://dummyimage.com/600x300/000/fff" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus ab nulla dolorum autem nisi officiis blanditiis voluptatem hic, assumenda aspernatur facere ipsam nemo ratione cumque magnam enim fugiat reprehenderit expedita.</p>
</div>
</div>

align divs side by side

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;
}

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 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