html flexbox 2 elements vertical and one on the left [duplicate] - html

This question already has answers here:
Left column and stacked right column using flexbox CSS [duplicate]
(2 answers)
Closed 2 years ago.
I am totally lost with flexbox for css3, and I cannot seem to figure out how to get it correctly working :(.
I want a layout like:
|-----| |----|
------- |----|
|-----| |----|
(Where |----| on the left are 2 divs an on the right its one)
And on mobile I want the right div to below the other 2 divs...
And I cannot seem to figure it out.
It just will not line up correctly, or the 2 divs on the left will not be as large as the one on the right.
I am using bootstrap 4.0 for this... so maybe that is something?
The following code I am currently at:
There is a container div around it
<div id="container">
<div class="d-flex row">
<div class="flex-row flex-fill">
<div class="d-flex flex-column">
<div class="card d-flex flex-fill">
<div class="card-body">
<form>
<div class="form-group">
<label>xxx</label>
<input type="text" class="form-control date" id="birthdatepicker" data-toggle="daterangepicker" data-single-date-picker="true">
</div>
<button type="submit" class="btn btn-primary waves-effect waves-light">{{ __('Submit') }}</button>
</form>
</div>
</div>
<div class="card d-flex flex-fill mb-4 mb-md-0">
<div class="card-body">
<h4 class="card-title">{{ __('Progress') }}</h4>
<div class="progress mb-2">
<div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</div>
</div>
</div>
<div class="flex-row col-12 col-md-4 col-lg-2">
<div class="d-flex flex-fill card mb-4 mb-md-0">
<div class="card-body">
<h5>xx</h5>
<p>
xx
</p>
</div>
</div>
</div>
</div>
</div>

here is a simple example of what i think you wish to achive.
.flexbox{
display: flex;
flex-direction: row;
width: 400px;
height: 400px;
}
#media only screen and (max-width: 478px){
.flexbox{
flex-direction: column;
}
}
.left{
width: 50%;
height: 100%;
}
.top-left{
height: 50%;
width: 100%;
position: relative;
background: red;
}
.bottom-left{
height: 50%;
width: 100%;
position: relative;
background: green;
}
.right{
width:50%;
height:100%;
}
.center-right{
width: 100%;
height: 100%;
background: blue;
}
<div class="flexbox">
<div class="left">
<div class="top-left">
</div>
<div class="bottom-left">
</div>
</div>
<div class="right">
<div class="center-right">
</div>
</div>
</div>

Related

How can I align the last element of a flexbox to the right with taking into account space-around?

I have a flex-div with 7 elements in it.
<div class="d-flex flex-wrap justify-content-around">
<div style="width: 350px">
[...]
</div>
[6 more identical divs]
</div>
On large screens, there are 3 divs in each row, on medium screens 2 and on small screens only 1. The last element is always centered but I want it to be aligned right. I tried margin-left: auto on the last element but due to justify-content-around there should be space on the right (first 2 rows on large screens, first 3 rows on medium screens). Unfortunately, margin-left: auto pushes the last element all the way to the right without the space from justify-content-around. How can I position the last element exactly as if it was an element of the right column?
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-around
}
.card {
border: 1px solid rgba(0, 0, 0, .125)
}
.ml-auto {
margin-left: auto
}
<h3>
Without margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card" style="width: 200px">
7 is centered
</div>
</div>
<h3>
With margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card ml-auto" style="width: 200px">
7 is too far to the right
</div>
</div>
It goes from
1 2
3 4
5 6
7 8
For 7 to come under 6 is tricky, but lets say thats not what you meant, and just want to align the 7 to left side.
Let's start removing all these style=width, If you ever want to edit the width of div you would need to edit every single div, dumping it into the CSS is much more efficient.
<div class="card">
4
</div>
This is the adjusted CSS
.flex-wrap {
flex-wrap: wrap;
}
.justify-content-around {
justify-content: space-between;
display: flex;
}
.card {
border: 1px solid rgba(0, 0, 0, 0.125);
width: 200px;
}
If you want it aligned on the right then you can use JS but its difficult, since you use justify it might conflict.
The following solution works, if the element and the parent width are constant, i. e. you know, when there are 1 or 2 or 3 columns:
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-around
}
.card {
width: 200px
}
.ml-auto {
margin-left: auto
}
.d-none {
display: none
}
.border {
border: 1px solid rgba(0, 0, 0, .125);
}
#media (min-width:500px) {
.d-lg-flex {
display: flex
}
}
#media (min-width:700px) {
.d-xl-flex {
display: flex
}
}
<h3>
Centered
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card border">
1
</div>
<div class="card border">
2
</div>
<div class="card border">
3
</div>
<div class="card border">
4
</div>
<div class="card border">
5
</div>
<div class="card border">
6
</div>
<div class="card border">
7 is centered
</div>
</div>
<h3>
With margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card border">
1
</div>
<div class="card border">
2
</div>
<div class="card border">
3
</div>
<div class="card border">
4
</div>
<div class="card border">
5
</div>
<div class="card border">
6
</div>
<div class="card border ml-auto">
7 is too far to the right
</div>
</div>
<h3>
Correct position
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card border">
1
</div>
<div class="card border">
2
</div>
<div class="card border">
3
</div>
<div class="card border">
4
</div>
<div class="card border">
5
</div>
<div class="card border">
6
</div>
<div class="card d-none d-lg-flex"></div>
<div class="card d-none d-xl-flex"></div>
<div class="card border">
7 is now at correct position
</div>
</div>
Instead of min-width:500px and min-width:700px in the media queries, use the bootstrap ones: min-width:992px and min-width:1200px. I just needed the smaller values for the snippet. Or simply use <div class="data-box d-none d-lg-flex"></div> and <div class="data-box d-none d-xl-flex"></div> for the placeholder-divs.
While other answers here are better, You should be tricky and smart,
you can create another element ,say div 8,now
Change
<div class="card" style="width: 200px">8</div> to
<div class="space" style="width: 200px"></div>
Place this div before div 7
What have we done?
We have removed all content inside that div(removed 8 from it)
We have changed class card to space, this removes the border property we apply in css(We can even remove the class instead of changing)
.card {
border: 1px solid rgba(0, 0, 0, .125);/*removed to our element 8*/
}
Your code
Note: I have added just 1 line of code,in html
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-around
}
.card {
border: 1px solid rgba(0, 0, 0, .125)
}
<h3>
Without margin-left: auto
</h3>
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="space" style="width: 200px"></div><!--I HAVE ADDED ONLY THIS LINE-->
<div class="card" style="width: 200px">
7
</div>
</div>
As of your original question,
"but due to justify-content-around",
You get problem when using margin-left: auto because of, justify-content- around.
The solution is to use justify-content-space-between
Snippet:
.d-flex {
display: flex
}
.flex-wrap {
flex-wrap: wrap
}
.justify-content-around {
justify-content: space-between;
margin: auto;
}
.card {
border: 1px solid rgba(0, 0, 0, .125)
}
.card:last-child{
margin-left: auto
}
<div class="d-flex flex-wrap justify-content-around">
<div class="card" style="width: 200px">
1
</div>
<div class="card" style="width: 200px">
2
</div>
<div class="card" style="width: 200px">
3
</div>
<div class="card" style="width: 200px">
4
</div>
<div class="card" style="width: 200px">
5
</div>
<div class="card" style="width: 200px">
6
</div>
<div class="card" style="width: 200px">
7
</div>
</div>
Note: If you need space-around also,then use margin or fixed width,or even another parent div to make it center!

creating three dots vertically with span and align them

I'm trying to create three vertical dots and align the bottom left of my container with css and bootstrap 5. exactly like the pic below:
my HTML and CSS:
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</section>
this is my output
how can i align the vertically and move them to bottom left of container? because when i use div for wrapping they disappear
1st: wrap the dots in a container. I used a section with the class: .dot-wrapper.
2nd: give the wrapper a width: min-content;. With that, it will only be as wide as the seclected dot.
3rd: to cenetr the dots, give them a margin left and right of auto;
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
margin: 5px auto;
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
.dot-wrapper {
width: min-content;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<section class="dot-wrapper">
<div class="dot selected-dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</section>
</section>
it's quite easy, you can wrap the dots with a div container like this
<!--Column Dots -->
<div class="dot-container">
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
and style the container as below
.dot-container{
width: 15px;
display: flex;
flex-direction:column;
align-items:center;
}
and for better styling. give dot class some amrgin like margin: 3px 0;
here is a codpen : https://codepen.io/shammlo/pen/QWKggNX?editors=1100

Boostrap grid height and placing row with height: auto

I am doing a simple page with a bootstrap grid and I am having some problems with placing the middle row occupying the full height in the middle.
These are the 3 rows: page
I want to place the row with the logo in the middle, but I am having problems with it. I placed height: 100%;, height: auto;. I even placed the container height to 100% and auto and nothing works!
I think there is a concept about bootstrap heigh that I am missing, because its the heigh that I have problems
html:
<div class="container-fluid">
<div class="row">
<div class="col-md-1 col-2">
<img id="menuIcon" (click)="toggleRightSidenav()" onmouseover="this.src='../../../assets/Images/generic/menuIcon_hover.png'" src="/assets/Images/generic/menuIcon.png" onmouseout="this.src='/assets/Images/generic/menuIcon.png'">
</div>
<div class="col-md-10 col-8">
</div>
<div class="col-md-1 col-2">
<img id="helpIcon" routerLink="/guide" onmouseover="this.src='../../../assets/Images/home/helpIconHover.png'" src="/assets/Images/home/helpIcon.png" onmouseout="this.src='/assets/Images/home/helpIcon.png'">
</div>
</div>
<div class="row row align-items-center mh-100" >
<div class= "col-md-12">
<img id="logo" src="/assets/Images/home/Logo.png">
</div>
</div>
<div class="row align-items-center justify-content-around fixed-bottom">
<div class="col-md-2 col-sm-2">
<img id="addButton" routerLink="/addPlayer" onmouseover="this.src='../../../assets/Images/generic/addIcon_hover.png'" src="../../../assets/Images/generic/addIcon.png" onmouseout="this.src='/assets/Images/generic/addIcon.png'" />
</div>
<div class="col-md-2 col-sm-2">
<p>Players Waiting: {{playerWaiting}} </p>
</div>
<div class="col-md-2 col-sm-2">
<p>Listed Players: {{playersListed}}</p>
</div>
<div class="col-md-2 col-sm-2">
<img id="searchButton" routerLink="/search" onmouseover="this.src='../../../assets/Images/generic/searchIcon_hover.png'" src="../../../assets/Images/generic/searchIcon.png" onmouseout="this.src='/assets/Images/generic/searchIcon.png'" />
</div>
</div>
</div>
css:
div{
border: yellow 1px solid;
}
#menuIcon{
width: 100%;
height: auto;
}
#helpIcon{
width: 100%;
height: auto;
}
#addButton{
width: 100%;
height: auto;
max-width: 127px;
}
#searchButton{
width: 100%;
height: auto;
max-width: 127px;
}
https://www.codeply.com/p/Xd0xi5hFNc
Couple of things.
To be able to fill several rows, you'd need a height for the container div.
Current HTML
<div class="container-fluid">
Update as
<div class="container-fluid d-flex vh-100 flex-column">
Now you can easily make your middle div fill the remaining gap by adding a fill-height class.
Current HTML
<div class="row row align-items-center mh-100" >
Update as
<div class="row row align-items-center fill-height">
Add this to your css
.fill-height {
flex: 1;
}
.fixed-bottom {
position: sticky;
}
jsFiddle

Bootstrap container-build not filling the screen even with p-0

For screens, I put padding at 0 for container-fluid but the screen still does not fill the screen that is less than or equal to width 1024.
.container-fluid {
background-color: #e2e5f4;
height: 600px;
margin-bottom: 200px;
padding: 0;
}
What works:
at 1024- width: 101%;
at 768- width: 112%;
at 320- width: 112%;
HTML code:
<div class="container-fluid p-0">
<div class="row border bg-danger p-0">
<div class="col-md-7 p-0">
<div class="MededX">
MEDedX
</div>
<div class="capture_tittle">
liunhliunh
<br> lunliu luinu liuni
<br> nllniun Nilo ahh
</div>
<div class="subCapture_tittle">
LOerm Swaminarayan swmainarayan swaminarayan swaminarayan
</div>
</div>
<div class="col-md-5 p-0 ">
<div>
<img class= "hex" src="hex.png">
</div>
<div>
<img class= "medIpad" src="medipad.png">
</div>
<div>
<img class= "plantsLeft" src="plantsLeft.png">
</div>
</div>
</div>
</div>
What's the problem? How do I fix it?
Use a custom wrapper and set its width to 100%.
.container-full {
margin: 0 auto;
width: 100%;
}
or a fast solution
style="width:100%"

Height of rows to fill column - Bootstrap layout

I know this may be easy for most of you but I'm stuck with this issue.
I need to implement this design:
Layout Design
... and for now I've got this Current layout.The general structure is a row with col-3 and col-9, this col-9 has two rows, one for name and job title, and the other one for statistics in the page (col-3 for each of them). I need them to fill the height of his parent, but height property doesn't work. Which could be a clean solution? Thanks a lot.
Here is the structure, it's pretty simple tho.
<div class="row profile-header">
<div class="col-md-3 user-image text-center">
<img ...>
<span>..</span>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-12">
<h2 class="text-white">...</h2>
<h4 class="text-muted">...</h4>
</div>
</div>
<div class="row text-center">
<div class="col-md-3 stat">
<h3>...</h3>
<small>...</small>
</div>
...
</div>
</div>
Use position: relative on the parent and then position:absolute; bottom: 0; on the children.
Nice explanation there.
Flexbox would be my recommendation although CSS tables might be an option too.
Codepen Demo
Snippet Demo (view Fullscreen)
.user-image {
background: pink;
}
.user-image img {
display: block;
margin: auto;
}
.profile-header {
display: flex;
}
.right {
background: #c0ffee;
display: flex;
flex-direction: column;
}
.stats {
margin-top: auto;
}
.stat {
background: lightgrey;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="row profile-header">
<div class="col-md-3 user-image text-center">
<img src="http://www.fillmurray.com/300/200" alt="" />
<span>User Ranking</span>
</div>
<div class="col-md-9 right">
<div class="row">
<div class="col-md-12">
<h2 class="text-white">User Name</h2>
<h4 class="text-muted">reference</h4>
</div>
</div>
<div class="row text-center stats">
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
</div>
</div>