Move div element below, after #media screen and (max-width: ...) - html

I am currently learning basics of web development and I wanted to create a simple webpage with a navigation bar, two main div elements and a footer. Ideally I would make it responsive to the window's size and when the user resizes it one of the three divs should go below the remaining two. Analogically, after further rescaling they would end up in a vertical line.
HTML code snippet:
<div class="bottom-container">
<div class="clock first-two" id="clock1" data-clock>
<p class="border">Add 1</p>
</div>
<div class="clock first-two" id="clock2" data-clock>
<p class="border">Add 2</p>
</div>
<div class="clock" id="clock3" data-clock>
<p class="border">Add 3</p>
</div>
</div>
CSS:
.bottom-container {
display: flex;
flex-direction: row;
justify-content: space-evenly;
width: 100%;
}
.clock {
margin: 2% 0;
padding: 200px 150px;
height: 100%;
align-self: center;
}
#media screen and (max-width: 1150px) {
.first-two {
display: flex;
flex-direction: row;
justify-content: space-evenly;
}
}
#media screen and (max-width: 770px) {
}
When I wrapped clock1 and clock2 in a separate div so that after first resizing 1 and 2 would stay in the same line and 3rd would go below them. Please see the screenshots for reference(I disabled 3rd div in the 2nd picture to demonstrate my desired effect).
First Image
Second Image
Thank you.

Add flex-wrap: wrap to bottom-conatiner -
.bottom-container {
display: flex;
justify-content: space-evenly;
flex-wrap: wrap;
width: 100%;
}
The flex-wrap property specifies whether the flexible items should wrap or not.
As a side note, I removed flex-direction: row because it's a default.

Are you looking for something like this?
* {
box-sizing: border-box;
}
.bottom-container {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
width: 100%;
}
.clock {
padding: 200px 0;
flex: 1 0 50%;
border: 1px solid black;
}
#media(min-width: 800px) {
.clock {
flex: auto;
}
}
<div class="bottom-container">
<div class="clock first-two" id="clock1" data-clock>
<p class="border">Add 1</p>
</div>
<div class="clock first-two" id="clock2" data-clock>
<p class="border">Add 2</p>
</div>
<div class="clock" id="clock3" data-clock>
<p class="border">Add 3</p>
</div>
</div>

Related

How can I use flexbox to make a three column layout turn into a two column layout (when the tab is resized)?

My goal is to have three responsive columns using flexbox. Currently, when resized, the columns can go left to right or up to down. I'm trying to make the three column layout go into a two column layout with the third column centered below the first two. However, the first and second columns don't go next to each other.
I google this and looked at other examples and tried to implement them, but I'm not sure why it still isn't working.
How can I fix this? Thanks in advance.
Link to my codepen: https://codepen.io/sbarclay7/pen/ZEQZvaj
html {
height: 100%;
}
body {
color: #FFFFFF;
text-align: center;
}
* { box-sizing: border-box; }
.wrapper {
padding-top:2.1rem;
display: flex;
padding-bottom:2.2rem;
max-width:40%;
justify-content: center;
margin:auto;
}
.category {
display: flex;
flex-direction: column;
width: 16rem;
flex: 1;
background-color:#203a8a;
border-radius: 0.7rem;
border: 1.5px solid rgb(5, 30, 37);
}
.flex {
display: flex;
flex-wrap: wrap;
}
#media (max-width: 1000px) {
.wrapper {
flex-direction: column;
flex-flow: column wrap;
}
.category {
width: 49%;
}
}
#media (max-width: 700px) {
.wrapper {
flex-direction: column;
}
.category {
width: 100%;
}
}
<div class="wrapper flex">
<div class="category" style="flex-basis: 4rem;" >
<h3>Header 1</h3>
<p>a</p>
</div>
<div class="category"style="flex-basis: 4rem;" >
<h3>Header 2</h3>
<p>a</p>
</div>
<div class="category"style="flex-basis: 4rem;">
<h3>Header 3</h3>
<p>a</p>
</div>
</div>
I noticed you modified the flexibility of the flex property by setting a flex: column property using media queries. This is currently affecting the resized display you are getting.
Remove the flex property added in the media queries and it should work just fine.

Aligning the last div to the bottom of a flexbox

Scenario :
I'm creating a pricing comparison table and am having difficulties aligning the last div, card-vat-fee, to the bottom of the container.
I need to do this because the tiers have longer running lists than
one another, causing the last div isn't aligned with the bottom of
the container.
How can I get the last div to align to the bottom of the flexbox?
Tried Case :
Of course, if I set a min-height: 320px; on the card-vat-fee class it will align the div to the bottom, however this isn't a responsive solution and I feel like there is a better approach that uses flex properties. Moreover, setting the card-vat-fee div to flex-grow, flex: 1 1 auto, produces an unideal solution.
Code :
<div class='pricing__tier'>
<div class='uni-card-header'>
</div>
<div class='uni-card-body'>
<div class='uni-row-on'>
</div>
<div class='uni-row-off'>
</div>
<div class='uni-row-on card-vat-fee'>
<div class='vat-fee-text'>
Credit card fees and VAT apply. See below for details.
</div>
</div>
</div>
</div>
<style>
.pricing__tier {
padding: 0;
text-align: center;
display: flex;
flex-direction: column;
width: 0%;
flex: 1;
}
.uni-card-body {
display: flex;
flex-direction: column;
}
</style>
Pricing Tier
Please Suggest.
Thanks in advance
Use margin-top:auto on the last div.
.pricing__tier {
padding: 0;
text-align: center;
display: flex;
flex-direction: column;
width: 25%;
flex: 1;
height: 200px; /* for demo purposes */
border: 1px solid grey;
}
.uni-card-body {
display: flex;
flex-direction: column;
flex: 1;
}
.card-vat-fee {
margin-top: auto; /* push to bottom */
background: green;
}
<div class='pricing__tier'>
<div class='uni-card-header'>
</div>
<div class='uni-card-body'>
<div class='uni-row-on'>
</div>
<div class='uni-row-off'>
</div>
<div class='uni-row-on card-vat-fee'>
<div class='vat-fee-text'>
Credit card fees and VAT apply. See below for details.
</div>
</div>
</div>
</div>
plaesa try this one :
.uni-card-body {
display: flex;
flex-direction: column;
width: 'for example' 700px;
}
.uni-row-on.card-vat-fee{
align-self: flex-end;
}
Ihope this will help you!
.uni-card-body {
display: flex;
flex-flow: row wrap;
justify-content: center;
background: yellow;
height: 90vh;
}
.uni-row-on.card-vat-fee {
align-self: flex-end;
background: green;
}
<div class='pricing__tier'>
<div class='uni-card-header'>
</div>
<div class='uni-card-body'>
<div class='uni-row-on'>
</div>
<div class='uni-row-off'>
</div>
<div class='uni-row-on card-vat-fee'>
<div class='vat-fee-text'>
Credit card fees and VAT apply. See below for details.
</div>
</div>
</div>
</div>
I've illustrated the thing in the snippet, it'll help.
Note: Content justification, background and height are for demonstration and not necessary.
1- set the parent div relative position without top & left & right &
bottom property
2- set the last div position absolute with bottom:0;right:0;left:0;height:36px;
<style>
.pricing__tier {
position:relative;
padding: 0;
text-align: center;
display: flex;
flex-direction: column;
width: 0%;
flex: 1;
}
.pricing__tier>.vat-fee-text {
position:absolute;
bottom:0;
right:0;
left:0;
height:36px;
}
</style>

How to fix height the content inside a div with flex css

Following to this answer, I am trying to create a perfect height for my content, But the content height is overflowing instead of getting a scroll over content.
I have created a fiddle for this scenario. Please help me fix my content height such a way that top content and always visible and scroll-able downward.
fiddle
html,
body {
height: 100%;
margin: 0
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.box .row {
border: 1px dotted grey;
}
.box .row.header {
flex: 0 1 auto;
}
.box .row.content {
display: flex;
flex-flow: column;
flex: 1 1 auto;
overflow-y: auto;
justify-content: center;
align-items: center;
}
.data {
width: 80%;
min-height: 400px;
}
.box .row.footer {
flex: 0 1 40px;
}
HTML.
<head>
<link href="./test.css" rel="stylesheet">
</head>
<body>
<div class="box">
<div class="row header">
<p>
<b>header</b>
<br />
<br />(sized to content)</p>
</div>
<div class="row content">
<div class="data">
invisible box1
</div>
<div class="data">
visible box2
</div>
<div class="data">
visible box3
</div>
<p>
<b>Bottom Box is visible with scroll.</b> (fills remaining space)
</p>
</div>
<div class="row footer">
<p>
<b>footer</b> (fixed height)</p>
</div>
</div>
</body>
</html>
The issue you encounter is caused by justify-content: center in the .box .row.content rule.
Remove it and your text will overflow properly.
.box .row.content {
display: flex;
flex-flow: column;
flex: 1 1 auto;
overflow-y: auto;
/*justify-content: center; removed */
align-items: center;
}
Updated fiddle
This is the default behavior for justify-content: center, where, on a flex column container, when the content overflow, it will overflow both at its top and bottom.
Read more here, where you find resources and a workaround:
How to use safe center with flexbox?
I think overflow: scroll; will fix your problem.

I don't want my divs to overlap inside a flexbox

I'm currently developing my first website. I've come to a point where I have two divs placed next to each other inside of a flexbox. Both divs have a width and height size in percentages. When I shrink the website, however, the right div overlaps the left div. If they're going to overlap I want them to be placed underneath each other. (It's about the right-side-content div overlapping the left-side-content div)
I've included my HTML and CSS code.
HTML:
<div class="content">
<div class="left-side-content">
<div class="intro">
<div class="brands">
<img src="images/logo%20ster.png" id="logo-ster"/>
</div>
<p class="top-title">Banner and endcard</p>
<h1>STER</h1>
<p class="intro-text">"STER" is a beauty, make-up and lifestyle channel on YouTube hosted by the 16 y/o Aster Marcus.</p>
<button class="view-project-button">View Project</button>
</div>
</div>
<div class="right-side-content">
<img src="images/sponsorloop-collage.png"/>
</div>
</div>
CSS:
.content {
display: flex;
align-items: center;
height: 80%;
width: 90%;
margin-left: auto;
margin-right: auto;
}
.content .left-side-content {
width: 30%;
height: 100%;
display: flex;
align-items: center;
}
.content .right-side-content {
width: 70%;
display: flex;
align-items: center;
justify-content: flex-end;
}
Add the flex-wrap property to .content.
Also, instead of using width for left and right content, use flex-basis instead, or incorporate it into the shorthand flex, as in the snippet below...
.content {
display: flex;
align-items: center;
height: 80%;
width: 90%;
margin-left: auto;
margin-right: auto;
flex-wrap: wrap;
}
.content .left-side-content {
flex: 1 0 30%;
height: 100%;
display: flex;
align-items: center;
}
.content .right-side-content {
flex: 1 0 70%;
display: flex;
align-items: center;
justify-content: flex-end;
}
<div class="content">
<div class="left-side-content">
<div class="intro">
<div class="brands">
<img src="images/logo%20ster.png" id="logo-ster" />
</div>
<p class="top-title">Banner and endcard</p>
<h1>STER</h1>
<p class="intro-text">"STER" is a beauty, make-up and lifestyle channel on YouTube hosted by the 16 y/o Aster Marcus.</p>
<button class="view-project-button">View Project</button>
</div>
</div>
<div class="right-side-content">
<img src="https://placehold.it/300x300" />
</div>
</div>

Flex Box Media Query Difficulty

From min-width of 769px to 1025px, I want the 3rd figure on a new line while the first and second figures remain on the top line taking up equal space. I'm attempting flex boxes in css. How do I get this to work?
<div class="mid-col-section-2">
<figure><img src="images/landscape-maintenance.jpg" alt="landscape" height="300"><figcaption>Landscape Maintenance</figcaption></figure>
<figure><img src="images/landscape-design.jpg" alt="landscape" height="300"><figcaption>Landscape Design</figcaption></figure>
<figure><img src="images/masonry-design.jpg" alt="landscape" height="300"><figcaption>Masonry Design</figcaption></figure>
.mid-col-section-2 {
display: flex;
flex-direction: column;
}
.mid-col-section-2 figure a {
color: black;
}
figcaption {
text-align: left;
}
#media (min-width: 1025px){
.mid-col-section-2 {
flex-direction: row;
justify-content: space-between;
padding: 10px 60px 10px 60px;
}
figcaption {
text-align: center;
}
.mid-col-section-2 figure {
padding: 15px 0 15px 0;
}
}
It seems like you might want to brush up on flexbox properties. You're throwing a lot in there that you probably don't actually want.
I revised your markup since the <figure> tag has default styles applied to it by the browser:
<div class="mid-col-section-2">
<div class="mid-section">
<img width="100%" src="http://jonvilma.com/images/landscape-3.jpg" alt="landscape"><figcaption>Landscape Maintenance</figcaption>
</div>
<div class="mid-section">
<img width="100%" src="http://jonvilma.com/images/landscape-3.jpg" alt="landscape"><figcaption>Landscape Design</figcaption>
</div>
<div class="mid-section">
<img width="100%" src="http://jonvilma.com/images/landscape-3.jpg" alt="landscape"><figcaption>Masonry Design</figcaption>
</div>
</div>
Then I tidied up your CSS:
#media (min-width: 769px) and (max-width: 1025px){
.mid-col-section-2 {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.mid-section {
margin: 0;
width: 45%;
}
Here's the result: https://jsfiddle.net/qdoxL23p/embedded/result/