Adjustable row heights with bootstrap 4 - html

I'm using bootstrap columns to display expanding cards. When one expands though, it pushes the whole row underneath it down.
Unexpanded:
Currently how it behaves expanded:
How I'd like it to behave:
I've been reading about flexbox, but I cant find any good examples of the desired behavior, while maintaining responsive design.
Currently the code is along the lines of
<div class="row">
<div class="col-xl-4 col-lg-5 col-12">
expanding content...
</div>
.
.
.
<div class="col-xl-4 col-lg-5 col-12">
expanding content...
</div>
</div>

Maybe you could try giving it a css height: property. This can be done through Javascript, so when you're expanding the box, also give it a certain height to limit it. Tell me if you'd like me to do it for you :)

I see 2 possibilities:
1. Solution: Have you checked out the bootstrap-component card-columns? It organizes the cards into Masonry-like columns.
By using
.card-columns {
#include media-breakpoint-only(lg) {
column-count: 4;
}
#include media-breakpoint-only(xl) {
column-count: 5;
}
}
you can make them responsive.
2. Solution:
You use just 3 cols:
.row {
margin-top: 20px;
align-content: flex-start;
}
.card {
padding: 10px;
margin-bottom: 10px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-4">
<div class="card">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip.
</div><!-- card -->
<div class="card">
Lorem
</div><!-- card -->
</div><!-- col -->
<div class="col-4">
<div class="card">
Lorem
</div><!-- card -->
<div class="card">
Lorem
</div><!-- card -->
</div><!-- col -->
<div class="col-4">
<div class="card">
Lorem
</div><!-- card -->
<div class="card">
Lorem
</div><!-- card -->
</div><!-- col -->
</div><!--row -->

Ok, so after some trial and error I managed
--HTML--
<div id="redDiv" style="background-color: red; height: 100px; width: 10%; float:
left;">
<p>This is a div</p>
</div>
--JavaScript--
var onWindowLoaded = () =>{
document.getElementById("redDiv").setAttribute("style", "height: 150px; background-
color:red; width: 10%;");
}
window.addEventListener("load", onWindowLoaded);
So it's important to note that I used a red background in order to tell how long my div was, I see you're using a greyish background (It was hard to see them to be honest). So basically once the page loads it will set the div to the height indicated in the setAttribute() function, I had to re-add the colour because modifying the div height through javascript made the colour disappear completely. Hope this helps :)

When overriding css values while working with bootstrap try using
!important
For example:
row {
height: 150px !important;
}

Related

placing divs side by side and in columns

I have a design which I am following to create my front end. I am having difficulty in spacing the divs.
My design looks like:
I am trying to create the same in angular
code
<div fxLayout="row" fxLayoutAlign="space-bewteen start" fxLayoutGap="12px" class="side_start">
<div fxFlex="12" class="second_bar">
Side
</div>
<div fxFlex="88" fxLayout="column" fxLayoutAlign="space-bewteen" fxLayoutGap="12px">
<div ngClass=third_bar_1>
<div fxLayout="row" fxLayoutAlign="space-bewteen start" fxLayoutGap="12px">
<div fxFlex="8" class="zone">
Zone Thermal Comfort
</div>
<div fxFlex="5" class="temp">
<p>TEMP</p>
<p>37 deg</p>
</div>
</div>
</div>
<div class=third_bar_2>
second
</div>
</div>
</div>
.css
.third_bar_1{
border:1px solid red;
background-color: white;
height: 60px;
}
.zone {
/* font-color: #5d6d88; */
background-color: #f1cd86;
text-align: center;
height: 71%;
}
.temp {
background-color: #73d9fa
}
.third_bar_2{
border:1px solid red;
height: calc(100vh - 355px);
}
and it looks like:
how to create the divs as shown in the image with different divs horizontally and vertically.
If you are trying to do that using pure css that would be a bit difficult. You can do it using bootstrap which is css frmaework very easily. Just read some tutorials about bootstrap grid system you will be able to do this easily. Here is an example.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>Grid</h1>
<p>This example demonstrates a 50%/50% split on small, medium and large devices. On extra small devices, it will stack (100% width).</p>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="col-sm-6" style="background-color:yellow;">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<div class="col-sm-6" style="background-color:pink;">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto.
</div>
</div>
</div>
</body>
</html>
You need to use flexbox to align it with the desired design.
You need first write the markup keepin in mind the flexbox.
body{
margin:0px;
}
.menu {
display: flex;
align-items: center;
justify-content: space-between;
background-color: #efefef;
}
.menu .left {
display: flex;
align-items: center;
}
.menu .left .left-left{
display: flex;
align-items: center;
}
<div class="menu">
<div class="left">
<div class="left-left">
<div class="first">
<p>Zonal thermal Comfort</p>
</div>
<div class="second">
<div class="up">
<p>Temp</p>
</div>
<div class="down">
<p>37 Deg</p>
</div>
</div>
<div class="fourth">
<p>48</p>
</div>
</div>
<div class="left-right">
<img src="https://via.placeholder.com/93x45" alt="">
</div>
</div>
<div class="right">
<p>otherstuff</p>
</div>
</div>
<div class="menu">
</div>
Now this is a very basic implementation of flexbox. The properties that you require to implement this design are
align-items : This will align you align items vertically
justify-content : This will align you align items horizontally
flex-direction : This will change your main-axis from horizontal to vertical according to the value
Read flexbox in detail, in will help you develop 1-D layouts. enter link description here

How do I stack two divs on mobile but arrange side-by-side on desktop?

I have this set up on desktop with a headline on the left and an image on the right. When I collapse the browser less than 880px, I want the image to be centered underneath the headline.
I am struggling with getting the image centered & underneath the headline.
I am fairly new to html/css so any tips would be greatly appreciated.
Fiddle: https://jsfiddle.net/o7k5qgne/1/
<section class="hero">
<div class="hero-inner">
<h1>Lorem ipsum dolor<span class="blue-dot">.</span></h1>
</div>
<div class="split split-right">
<img src="https://vignette.wikia.nocookie.net/undertale-rho/images/5/5f/Placeholder.jpg/revision/latest?cb=20180213155916" alt="working" class="right-image">
</div>
</section>
<div class="clients">
<h2>Lorem ipsum dolor & sit amet</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
</p>
</div>
Try using CSS media Query to detect where (breakpoint) you want the DIVs to stack. See the example below and adjust as needed.
.myDiv {
height: 150px;
width: 150px;
display: inline-block;
background-color: orange;
margin-bottom: 25px;
}
/* The block of code below tells the browsers what to do on a screen that has a width of 320px or less */
#media screen and (max-width: 320px) {
.myDiv {
width: 90%;
display: block; /* Stops it from floating */
margin: auto; /* Ensures that it is centered */
margin-bottom: 25px; /* Space between the stacked elements */
}
}
<div class="myDiv"></div>
<div class="myDiv"></div>
More on CSS Media Query
See it here in action. Resize the browser to see how it works.
Problem is with your css. Here I edited your css just to the once that need to make the image and headline responsive.
[https://jsfiddle.net/ss123/a7q834sL/1/][1]
Styling like you are expecting can simply be achieved by using css flex box. To do that you must first put the content inside a container and make it display:flex. Then you can use the flex styling for the content inside the container.
flex-direction:column will stack the content over. flex-direction:row will put the content in a single row. jstify-content:space-venly will justify the content elements with exactly even spaces between them.
You are on the right track here with the media queries you have in place. I would avoid using the absolute positioning on the image, it will get set exactly where you tell it to and not be very flexible. Centering can be done in several ways like with flex box as others have mentioned, or even just throwing a text-align: center on its' parent element. With your media queries on mobile, be weary of padding or vh/vw that you have in place from desktop, you may not want those still in place when you get to a small screen size; looks like in your example you would want to remove padding and the vh on mobile. Also, to help your CSS be a bit easier to manage I would recommend putting your media queries right inside the class to avoid repeating a lot of code, like so:
.hero-inner {
/* Flexbox Stuff */
display: flex;
align-items: center;
/* Text styles */
text-align: left;
width: 50px;
#media only screen and (max-width: 880px) {
align-items: center;
justify-content: center;
text-align: center;
width: 80vw;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 ">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 pull-left">
<img src="https://vignette.wikia.nocookie.net/undertale-rho/images/5/5f/Placeholder.jpg/revision/latest?cb=20180213155916" alt="working" class="right-image">
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 pull-right">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
</p>
</div>
</div>
</body>
</html>

HTML CSS styling for a fixed div and a flexible div

I want to achieve the following layout where there are two columns, a fixed size one (50px wide) for my icon and a flexible one that stretches the remaining part for my messages. I am using bootstrap 4 with angular2
Currently, I am using the following setup with bootstrap 4 grid layout
<div class="col-1">
<md-icon class="material-icons notification-row-icon">done</md-icon>
</div>
<div class="col-11">
<div class="notification-row-text-div">
<label class="notification-mrow-essage-label">{{message}}</label>
</div>
</div>
But the output is off when the screen is extra small as shown below. I want the icon to be always on the left hand side of the message rather than stacked when the screen gets small. Since the col way seems to create this problem, I am thinking to re-build this from good old html/css way instead. How can I achieve that?
You can use flexbox
.flexbox{
display:flex;
}
.col-1,
.col-11{
border:1px solid;
}
.col-1 {
width: 50px;
}
.col-11 {
flex: 1 1;
}
<div class=flexbox>
<div class="col-1">
<md-icon class="material-icons notification-row-icon">done</md-icon>
</div>
<div class="col-11">
<div class="notification-row-text-div">
<label class="notification-mrow-essage-label">{{message}}</label>
</div>
</div>
</div>
Here's a flexbox solution.
The main property to know in this solution is flex-grow.
It specifies what amount of space inside the flex container the item should take up.
If all items in a flex container had the same value, they'd all be the same width. If only one item like we have in this example has flex-grow applied, it takes up the remaining space of it's container.
If you're unfamiliar with box-sizing and the value border-box, it includes padding and borders with an elements width assignment instead of them being added in addition to the assigned width. So if you tell and element to be 200px wide and have 10px of padding, it's 200px wide. Not 220px.
#import url( 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' );
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.container {
width: 90%;
margin: 0 auto;
}
.row {
display: flex;
align-items: flex-start;
margin-left: -5px;
margin-right: -5px;
}
.col {
padding: 5px;
}
.col.fixed {
width: 50px;
}
.col.fill {
flex-grow: 1;
}
p {
margin: 0 0 1rem;
}
<div class="container">
<div class="row">
<div class="col fixed">
<i class="fa fa-rocket"></i>
</div>
<div class="col fill">
<p>
Bring a spring upon her cable handsomely gibbet Corsair scuttle prow Buccaneer nipper. Gun jack clap of thunder port holystone killick bilge water chandler. Gunwalls Cat o'nine tails lookout careen Jack Tar salmagundi boom mutiny.
</p>
</div>
</div>
</div>
You could achieve this without multiple columns...
.icon {
width: 3em; /* change as you need */
display: inline-block;
}
.notification-row-text-div {
display: inline-block;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-12">
<span class="icon">▣</span>
<div class="notification-row-text-div">
<label class="notification-mrow-essage-label">John Doe</label>
</div>
</div>
</div>
</div>
Flexbox is built into Bootstrap 4 so you don't need any extra CSS other than the fixed width column.
.fixed {
width: 50px;
}
Then just use the auto-layout col class to consume the remaining space:
<div class="row">
<div class="fixed">
icon
</div>
<div class="col">
..
</div>
</div>
The col class already uses flex-grow.
Demo: http://www.codeply.com/go/iprwiDJhgy
You can try this simple code. It is fully tested. I hope it will help you.
HTML:
<div class="container">
<div class="row">
<div class="col fixed">
<span>©</span>
</div>
<div class="col fill">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
</div>
</div>
CSS:
<style>
.col.fixed {
width:50px;
float:left;
}
.col.fill {
display: block;
margin-left: 50px;
}
</style>

How to center 3 boxes with gaps in bootstrap

I'm trying to center 3 boxes, with abit of space (gutter?) between them and also space from corner of page.
I tried class="col-sm-2 col-md-offset-1" (col-sm-2 to make them smaller, and offset 1 for the gap), but its not really centered to the middle of the page, and also on mobile each col is "streched" to the corners and i dont want that.
any ideas?
thanks!
You need text-center
.grid3 >div{
height: 200px;
background: rgba(0,0,0,.4);
float: none;
display: inline-block;
background-clip: content-box
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row text-center grid3">
<div class="col-xs-3">.col-md-4</div>
<div class="col-xs-3">.col-md-4</div>
<div class="col-xs-3">.col-md-4</div>
</div>
You can wrap your content in a .well. Then the padding of the columns will be your gutters. Also, you cannot use .col-sm-3 if you want 3 columns to be centered.. you would have to use .col-sm-2 or .col-sm-4
<div class="col-sm-4">
<div class="well">
<h3>Column 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
</div>
</div>
http://www.bootply.com/CUbF8SQg8q

Side-by-side elements without using tables

I've noticed that StackOverflow resorted to using a table-based layout for the comments area beneath posts:
Notice how the text all stays to the right of the button area, regardless of how many lines of text there are. I am trying to accomplish the same effect using a table-less layout, and failing miserably. Is there any good way to do achieve this without tables?
I think this is a good start:
<div class="comment-row">
<ul class="icon-set">
<li class="icon-1">icon</li>
<li class="icon-2">icon</li>
</ul>
<div class="comment">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
CSS:
.comment-row { position relative; }
.icon-set { position: absolute; }
.icon-set a {
display: block;
text-indent: -99999px;
border: 1px solid;
width: 16px;
}
.comment { margin-left: 30px; }
Live Sample:
http://jsfiddle.net/HPbFJ/
.sidebyside { float: left}
<div class="sidebyside">
<input type="button" value="VoteUp" /><br />
<input type="button" value="Flag" />
</div>
<div class="sidebyside">Text</div>
Isn't it just as simple as this?
EDIT
Your example (fixed):
<div style="overflow: hidden;">
<div style="float: left;">Left Content</div>
<div style="float: left; width: 100px;">Right Content Right ContentRight Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content Right Content </div>
</div>
Alternate solution: http://jsfiddle.net/7JukV/
Just for the sake of alternatives... :)