Re-order items when I hit a custom breakpoint [duplicate] - html

This question already has answers here:
Order columns through Bootstrap4
(6 answers)
Closed 3 years ago.
I have four items with different sizes in a row.
On extra-large screens everything looks fine. But when I hit large screens (1199.98px / bootstrap 'lg'), I need to re-order my div items.
The third div need to be the last.
I also made a code pen for this
<!-- https://codepen.io/ibrahim-kunushefci/pen/OKJWzq -->
.hotelPr,
.hotelPr2,
.hotelPr3 {
height: 100px;
display: flex;
justify-content: center;
align-items: center;
color: white;
background: #3161a3;
border: 2px solid black;
}
.custom {
height: 100px;
display: flex;
justify-content: center;
align-items: center;
color: white;
background: #bbbbbb;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="row">
<div class="col-xl-2 col-lg-4">
<div class="hotelPr">
<p>Hotel</p>
</div>
</div>
<div class="col-xl-2 col-lg-4">
<div class="hotelPr2">
<p>Hotel</p>
</div>
</div>
<div class="col-xl-5 col-lg-10">
<div class="custom">
<p>This needs to be the last on small, medium and large screens. But not in extra large</p>
</div>
</div>
<div class="col-xl-3 col-lg-4">
<div class="hotelPr3">
<p>Hotel</p>
</div>
</div>
</div>

Add d-flex to your row container:
Add order-1 order-xl-0 to your the col you need to re-order

You can specify the order of the displayed siblings on a parent flexbox element.
I changed the display of your .row div in a flexbox, and I added an order property to your col-xl-5 div.
.row{
display: flex;
}
.hotelPr,
.hotelPr2,
.hotelPr3 {
height: 100px;
display: flex;
justify-content: center;
align-items: center;
color: white;
background: #3161a3;
border: 2px solid black;
}
.custom {
height: 100px;
display: flex;
justify-content: center;
align-items: center;
color: white;
background: #bbbbbb;
}
.col-xl-5{
order: 1; /* here */
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="row">
<div class="col-xl-2 col-lg-4">
<div class="hotelPr">
<p>Hotel</p>
</div>
</div>
<div class="col-xl-2 col-lg-4">
<div class="hotelPr2">
<p>Hotel</p>
</div>
</div>
<div class="col-xl-5 col-lg-10">
<div class="custom">
<p>This needs to be the last on small, medium and large screens. But not in extra large</p>
</div>
</div>
<div class="col-xl-3 col-lg-4">
<div class="hotelPr3">
<p>Hotel</p>
</div>
</div>
</div>

Related

Issue with vertical centering of text [duplicate]

This question already has answers here:
How to remove line spacing between HTML heading elements?
(4 answers)
Space before heading larger than space after heading with HTML and CSS
(3 answers)
Closed 1 year ago.
I am having an issue getting text to be centered vertically within a div. I've tried both CSS and bootstrap options, but not having luck. The closest that I get is with using align-items: center, however, the test is still offset from what should be middle.
Current code:
.code-quote {
max-width: 70%;
height: 40px;
background-color: #707793;
display: flex;
align-items: center;
justify-content: center;
}
.code-text {
font-size: 1.5rem;
color: #3BBA9C;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div class="row">
<div class="col">
<div class="code-quote mx-auto">
<h3 class="code-text">This is my text</h3>
</div>
</div>
</div>
This is what I get:
If I remove the align-items: center, then it's much closer to the top of the element.
The h3 element has a bottom margin by default. Adding margin: 0 might do what you're after:
.code-quote {
max-width: 70%;
height: 40px;
background-color: #707793;
display: flex;
align-items: center;
justify-content: center;
}
.code-text {
font-size: 1.5rem;
color: #3BBA9C;
margin: 0;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div class="row">
<div class="col">
<div class="code-quote mx-auto">
<h3 class="code-text">This is my text</h3>
</div>
</div>
</div>
Bootstrap provides all the alignment and flex stuff you could ask for. Have a look at the docs.
Also note my adjustment to margin on the heading element.
.code-quote {
max-width: 70%;
height: 40px;
background-color: #707793;
}
.code-text {
font-size: 1.5rem;
margin-bottom: 0;
color: #3BBA9C;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="code-quote mx-auto d-flex flex-column
align-items-center justify-content-center">
<h3 class="code-text">This is my text</h3>
</div>
</div>
</div>
</div>

Text not aligning in center

I have created 4 columns. The first 3 columns are supposed to contain text vertically oriented. The problem is I am unable to align it. justify-content and align-items are not positioning the text in the center of the column. If you run the code you'll see it's positioned to the right. I want it to be exactly in center.
body{
margin:0;
padding: 0;
height: 100vh;
width: 100vw;
}
.forAll{
height: 100vh;
display: flex;
justfiy-content: center;
align-items: center;
text-align: center;
padding: 0;
}
.verticalOption{
transform: rotate(270deg);
line-height: 10px;
}
.verticalOption a{
text-decoration: none;
color: white;
font-size: 10px;
line-height: 5px;
white-space: nowrap;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<body>
<div class="no-gutters">
<div class="fluid-container d-flex flex-row-reverse">
<div class="container col-xl-9 col-9 col1 forAll bg-primary"></div>
<div class="container col-xl-1 col-1 col2 forAll bg-warning">
<h1 class="verticalOption">Sample Text</h1>
</div>
<div class="container col-xl-1 col-1 col3 forAll bg-danger">
<h1 class="verticalOption">Sample Text</h1>
</div>
<div class="container col-xl-1 col-1 col4 forAll bg-success">
<h1 class="verticalOption">Sample Text</h1>
</div>
</div>
</div>
</body>
I added another flex container to the column, so alignment can be controlled further into the HTML nesting. I also justified the content of the column to center. I also made the h1 display inline-flex to remove all extra white-space.
Here is where all the classes have been added:
<div class="container col-xl-1 col-1 col2 forAll bg-warning d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0">
Sample Text
</h1>
</div>
Demo
body{
margin:0;
padding: 0;
height: 100vh;
width: 100vw;
}
.forAll{
height: 100vh;
display: flex;
justfiy-content: center;
align-items: center;
text-align: center;
padding: 0;
}
.verticalOption{
transform: rotate(270deg);
line-height: 10px;
}
.verticalOption a{
text-decoration: none;
color: white;
font-size: 10px;
line-height: 5px;
width: 200px;
white-space: nowrap;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<body>
<div class="no-gutters">
<div class="fluid-container d-flex flex-row-reverse">
<div class="container col-xl-9 col-9 col1 forAll bg-primary"></div>
<div class="container col-xl-1 col-1 col2 forAll bg-warning d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0">Sample Text</h1>
</div>
<div class="container col-xl-1 col-1 col3 forAll bg-danger d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0">Sample Text</h1>
</div>
<div class="container col-xl-1 col-1 col4 forAll bg-success d-flex justify-content-center">
<h1 class="verticalOption d-inline-flex m-0">Sample Text</h1>
</div>
</div>
</div>
</body>
Just do text-align:center on your h1.
If that doesn't work, its most likely cause you're hardcoding your width to your a tag, and that 200px is probably larger than the container itself.
You just have to add two lines in .verticalOption:
vertical-align:center;
display:table-cell;
and delete justfiy-content: center;
Sorry, I had a typo in justify-content: center which was causing this problem.

How to get elements within a flexbox to be equalheight (nested) using CSS [duplicate]

This question already has answers here:
How to get header from cards or similar to have the same height with flex box?
(2 answers)
Closed 5 years ago.
I've searched and can't figure out how to make the contents inside a flexbox panel equalheight. I have the panel itself equal height, but I'd also like the panel-heading and panel-body to be equal height also. I've played around for hours hoping I'd stumble on a solution.
In summary I'd like equal height panel (already got) with equal height panel-heading and equal height panel-body.
<div class="container">
<div class="row">
<div class="flex-equalheight">
<div class="col-md-3 col-sm-4 col-xs-12 equal">
<div class="panel panel-yellow bells-shadow" style="text-align: center;">
<div class="panel-heading">Line 1</div>
<p class="panel-body panel-statement">understand your company's website goals<br>understand your company's website goals<br>understand your company's website goals</p>
</div>
</div>
<div class="col-md-3 col-sm-4 col-xs-12 equal">
<div class="panel panel-yellow bells-shadow" style="text-align: center;">
<div class="panel-heading">Line 1<br>Line 2</div>
<p class="panel-body panel-statement">benchmark you agains your competition</p>
</div>
</div>
</div>
/* START THE EQUAL HEIGHT FLEX MAGIC */
.flex-equalheight, .equal {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
flex: 1 1 0px;
margin-bottom: 15px;
}
.flex-equalheight .panel {
min-width:100%;
}
I have a codepen that demonstrates the problem . Cheers for any help you can give me.
[EDIT]
I've tried adding the following to the codepen with limited success, it seems to work, but then when you resize the browser the content overflows the div for some reason
.panel {
display: flex;
flex-direction:column;
height:100%;
}
.panel-heading, .panel-body {
height:100%;
display:inline-flex;
}
How about using jquery-match-height
$(function() {
$('.panel-heading').matchHeight();
});
body {
padding: 20px;
}
.panel-yellow {
border-color: #e2dd43;
}
.panel-yellow>.panel-heading {
color: #2c399e;
background-color: #e2dd43;
border-color: #e2dd43;
}
.panel-heading {
font-size: 1.2em;
}
.bells-shadow {
transition-property: color, background-color, box-shadow, transform;
transition-duration: .55s;
}
.bells-shadow {
box-shadow: 0 15px 35px rgba(50, 50, 93, .1), 0 5px 15px rgba(0, 0, 0, .07);
}
.bells-shadow:hover {
transform: translateY(-4px);
box-shadow: 0 18px 35px rgba(50, 50, 93, .1), 0 8px 15px rgba(0, 0, 0, .07);
}
/* START THE EQUAL HEIGHT FLEX MAGIC */
.flex-equalheight,
.equal {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
flex: 1 1 0px;
margin-bottom: 15px;
}
.flex-equalheight .panel {
min-width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.matchHeight/0.7.2/jquery.matchHeight-min.js"></script>
<div class="container">
<div class="row">
<div class="flex-equalheight">
<div class="col-md-3 col-sm-4 col-xs-12 equal">
<div class="panel panel-yellow bells-shadow" style="text-align: center;">
<div class="panel-heading">Line 1</div>
<p class="panel-body panel-statement">understand your company's website goals<br>understand your company's website goals<br>understand your company's website goals</p>
</div>
</div>
<div class="col-md-3 col-sm-4 col-xs-12 equal">
<div class="panel panel-yellow bells-shadow" style="text-align: center;">
<div class="panel-heading">Line 1<br>Line 2</div>
<p class="panel-body panel-statement">benchmark you agains your competition</p>
</div>
</div>
</div>
</div>
</div>
Check this Codepen.

Vertically center item with flexbox - align-items: center doesn't work?

I used the styling from this thread to make a progress bar fill in the empty space in a div (only other item is a button).
The problem is now that align-items: center doesn't vertically center the progress bar. I tried using align-content: center on the child too, with no effect.
Here's the code in case you didn't open the link
.wrapper {
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
height: 5em;
background: #ccc;
}
.wrapper > .left
{
background: #fcc;
}
.wrapper > .right
{
background: #ccf;
flex: 1;
}
Markup:
<div class="wrapper">
<div class="left">Left</div>
<div class="right">Right</div>
</div>
Can someone tell me what I'm doing wrong? Thanks in advance
This is how it looks:
I guess you can do the following to get it right:
There is a margin coming for the .progress element- first you can nullify it:
.wrapper > .left > .progress {
margin: 0;
}
Give 100% height for wrapper
I also removed height: 10vh for the container of wrapper to finish things up.
See revised fiddle here and snippet below:
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
.wrapper {
display: flex;
align-items: center;
width: 100%;
background: #ccc;
height: 100%;
}
.wrapper > .left {
background: #fcc;
flex: 1;
}
.wrapper > .right {
background: #ccf;
}
.wrapper > .left > .progress {
margin: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-s-6 col-s-offset-3" style="background:purple; position:relative; border-radius:10px;">
<div class="wrapper">
<div class="left">
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="35" aria-valuemin="0" aria-valuemax="100" style="width:35%">
</div>
</div>
</div>
<div class="right">
<button type="button" aside-menu-toggle="menu-1" class="btn btn-sm btn-default">Меню</button>
</div>
</div>
</div>
</div>
</div>
Let me know your feedback on this. Thanks!
A flex container will enable a flex context only to its direct children. Hence, your "progress-bar" div is out of reach. Likewise, your purple background bar is before flex container (wrapper), so don't expect it's content to be centered either. You can check this guide.
Check this code:
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-s-6 col-s-offset-3" style="background:purple; height:10vh; position:relative; border-radius:10px;">
<div class="wrapper">
<div class="left">
left
</div>
<div class="right">
right
</div>
</div>
</div>
</div>
</div>
Pen based on your code here
Try adding
align-items: center;
justify-content: center;
to your .wrapper class.
Here is a good article on FlexBox positioning:
https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/

Flexbox breaks bootstrap responsiveness

I have a row where one column can vary in height so I don't know how high it will be. In order to properly space the adjacent column I have used nested flex boxes.
This works fine on main break point but as soon as I add the flex box then this breaks the responsiveness as the columns don't stack on mobile anymore.
What should I do here? Should I drop flexbox? How else can I achieve this spacing?
.container{
margin-top: 60px;
}
.container{
border: 1px solid #000;
}
.row{
display: flex;
}
.row-center{
display: flex;
flex: 1;
}
.outer{
display: flex;
flex-direction: column;
justify-content: space-around;
border: 1px solid #000;
width: 100%;
}
.one, .two, .three{
flex: 0 0 40px;
border: 1px solid #000;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6"><img src="http://placehold.it/350x500"></div>
<div class="col-xs-12 col-sm-6 row-center">
<div class="outer">
<div class="one">some text</div>
<div class="two">some text</div>
<div class="three">some text</div>
</div>
</div>
</div>
</div>
jsfiddle mirror: https://jsfiddle.net/y68dnzwy/
May be this help you:
.container{
margin-top: 60px;
}
.container{
border: 1px solid #000;
}
.row{
display: flex;
}
.row-center{
display: flex;
flex: 1;
}
.outer{
display: flex;
flex-direction: column;
justify-content: space-around;
border: 1px solid #000;
width: 100%;
}
.one, .two, .three{
flex: 0 0 40px;
border: 1px solid #000;
}
/* Added: */
#media screen and (min-width:100px) and (max-width: 980px) {
.row-center {
flex: auto;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6"><img src="http://placehold.it/350x500"></div>
<div class="col-xs-12 col-sm-6 row-center">
<div class="outer">
<div class="one">some text</div>
<div class="two">some text</div>
<div class="three">some text</div>
</div>
</div>
</div>
</div>
Demo
Used this with bootstrap 3, 4-text boxes in row with same height depending on the dynamic text, where on tablet and mobile are only 2 in row. And with tetx centered in middle
Somehow this flex magic makes on mobile, that only text boxes that are in same row have same height, so if last item is super tall, only last 2 items are super tall, not affecting first 2.
<div class="row row-flex-box">
<div class="col-xs-6 col-sm-6 col-md-3">
<div class="thumbnail flex-col-vertical-center">
<div class="caption"><span>text text text text</span></div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-3">
<div class="thumbnail flex-col-vertical-center">
<div class="caption"><span>text text text text text text text text</span></div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-3">
<div class="thumbnail flex-col-vertical-center">
<div class="caption"><span>text text text text</span></div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-3">
<div class="thumbnail homepage-slider-bottom-block-single flex-col-vertical-center">
<div class="caption"><span>text text text texttext text text texttext text text text</span></div>
</div>
</div>
</div>
Css:
.row-flex-box {
display: flex; /* make cols same heigh */
flex-wrap: wrap; /* alows responsive behavior of cols (otherwise cols will never break on mobile)*/
}
.flex-col-vertical-center {
display: flex; /* specifing display/flex-direction/justifi-content only because i want to have text aligned in the middle of boxes much cleaner than display:table-cell way*/
flex-direction: column;
justify-content: center;
text-align:center;
height: 100%; /* since cols have bigger height this has effect, also can be ussefull - height: calc(100% - 15px); with 15px bottom margin */
}