I have made this layout with bootstrap
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-md-2 leftsidebar">left</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-12 header">header</div>
</div>
<div class="row">
<div class="col-md-12 content">content</div>
</div>
<div class="row">
<div class="col-md-12 footer">footer</div>
</div>
</div>
<div class="col-md-2 rightsidebar">right</div>
</div>
</div>
Content should always fill out the page, so I want to get something along the lines of:
Use code as below (run and see in full page):
html,body{
height:100%;
}
.leftsidebar{
background:orange;
}
.rightsideba{
background:green;
}
.vh-100{
height: 100vh!important;
}
.footer{
position: absolute;
bottom: 0;
width: 100%;
background:red;
}
.content{
background:skyblue;
height: calc(100% - (30px));
}
.vw-100{
width:100vw;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container-fluid h-100">
<div class="row">
<div class="col-md-2 leftsidebar vh-100">left</div>
<div class="col-md-8">
<div class="row header">
<div class="col-md-12 h-100">header</div>
</div>
<div class="row content">
<div class="col-md-12">content</div>
</div>
<div class="row footer">
<div class="col-md-12 h-100">footer</div>
</div>
</div>
<div class="col-md-2 rightsideba vh-100 vw-100">right</div>
</div>
Related
I created a bootstrap grid that has 3 rows with the following layout.
All I'm trying to do is add a bit of margin between them but as you can see, the columns and rows are not longer properly aligned.
Is there a way to fix it or maybe there's a better way to achieve what I want?
#featured {
margin-bottom: 15px;
}
.featured-1 {
height: 200px;
}
.featured-2 {
height: 50%;
margin-left: 5px;
}
.featured-3 {
height: 50%;
margin-left: 5px;
margin-top: 5px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container">
<div class="row featured-1" id="featured">
<div class="col-md-7 col-sm-12 bg-warning">
Featured 1
</div>
<div class="col-md-5">
<div class="row featured-2">
<div class="col-md-12 col-sm-12 bg-danger">
Featured 2
</div>
</div>
<div class="row featured-3">
<div class="col-md-12 col-sm-12 bg-success">
Featured 3
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12 bg-primary">For reference</div>
</div>
</div>
The official bootstrap document recommended the use of Gutter.
you can do this like below:
.featured-1 {
height: 200px;
}
.featured-2, .featured-3 {
height: 50%;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="container">
<div class="row featured-1" id="featured">
<div class="col-md-7 col-sm-12 bg-warning">
Featured 1
</div>
<div class="col-md-5 px-4">
<div class="row featured-2">
<div class="col-md-12 col-sm-12 bg-danger">
Featured 2
</div>
</div>
<div class="row featured-3">
<div class="col-md-12 col-sm-12 bg-success gy-2">
Featured 3
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 bg-primary gy-2">For reference</div>
</div>
</div>
There's already padding on the columns, which acts as gutters. I'd put the background on your column content instead.
#featured {
margin-bottom: 15px;
}
.featured-1>div {
height: 200px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container">
<div class="row" id="featured">
<div class="col-7 featured-1">
<div class="bg-warning">Featured 1</div>
</div>
<div class="col-5 d-flex flex-column">
<div class="featured-2 flex-grow-1 bg-danger mb-1">Featured 2</div>
<div class="featured-3 flex-grow-1 bg-success mt-1">Featured 3</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="bg-primary">For reference</div>
</div>
</div>
</div>
.r1{
border:1px solid black;
}
.r2{
border:1px solid black;
text-align:center;
}
.r3{
border:3px solid blue;
text-align:center;
}
.t1{
border:1px solid red;
background-color:red;
text-align:center;
border:1px solid black;
}
.head{
border:2px solid black;
height:50px;
background-color:green;
}
.c{
height: 100px;
border: 1px solid black
}
.cell{
border: 5px solid green;
}
.r4{
}
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="stylo2.css">
<link rel="stylesheet" href="https://necolas.github.io/normalize.css" />
<link href="https://fonts.googleapis.com/css2?family=Russo+One&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid">
<div class="row r1">
<div class="col-md-12">
<div class="row head">
<div class="col-md-12">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-1">
</div>
<div class="col-md-9">
Content
</div>
<div class="col-md-1">
</div>
</div>
</div>
</div>
<div class="row head">
<div class="col-md-12">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-1">
</div>
<div class="col-md-9">
Content
</div>
<div class="col-md-1">
</div>
</div>
</div>
</div>
<div class="row r1">
<div class="col-md-12 c">
Table1
</div>
</div>
<div class="row r2">
<div class="col-md-6 c">
Table2
</div>
<div class="col-md-6 c">
Table3
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="row r3">
<div class="col-md-12">
<div class="row">
<div class="col-md-12 t1">
Heading
</div>
</div>
<div class="row r">
<div class="col-md-1 cell">
1
</div>
<div class="col-md-5 cell">
ABC
</div>
<div class="col-md-5 cell">
234
</div>
<div class="col-md-1 cell">
5
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row r3">
<div class="col-md-12">
<div class="row">
<div class="col-md-12 t1">
Heading
</div>
</div>
<div class="row playerrow">
<div class="col-md-1 cell">
1
</div>
<div class="col-md-5 cell">
ABC
</div>
<div class="col-md-5 cell">
234
</div>
<div class="col-md-1 cell">
5
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Hey,
when I'm on a Desktop Screen, the code is fine, but when I switch to my mobile Device, i would like to have the content of my last row with the cells "1 ABC 234 5" besides each other too (like in desktop version) instead of each col building a new row. Also they shoud have a fixed with that not depends on its content.
Thanks in advance
Easy. Remove the -md- from the classes and leave col-1, col-5 etc. Then they won't be responsive.
I have tried to create a layout using Bootstrap, however I am unable to change the height of my rows. For example, I want the first row height to be 25%, the second 50% and the last 25%. How can I do that?
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div class="container-fluid">
<div class="row h-25">
<div class="col-12">
<h1>test</h1>
</div>
</div>
<div class="row h-50">
<div class="col-4"></div>
<div class="col-8"></div>
</div>
<div class="row h-25">
<div class="col-10"></div>
<div class="col-2"></div>
</div>
</div>
You need to specify height: 100%; for html,body and the container-fluid
html, body {
height: 100%;
}
.row {
border: thin solid black;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="container-fluid h-100">
<div class="row h-25">
<div class="col-12">
<h1>test</h1>
</div>
</div>
<div class="row h-50">
<div class="col-4">height</div>
<div class="col-8">50</div>
</div>
<div class="row h-25">
<div class="col-10">height</div>
<div class="col-2">25</div>
</div>
</div>
The important thing is that your divs must be wrapped inside something else which has a defined height. Otherwise the percentages are meaningless - 25% of what, exactly?
Demo:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div style="height: 100px;">
<div class="h-25" style="background-color: yellow">Height 25%</div>
<div class="h-50" style="background-color: red">Height 50%</div>
<div class="h-25" style="background-color: green">Height 25%</div>
</div>
See also https://getbootstrap.com/docs/4.0/utilities/sizing/
Trying to Get this Grid format
Hello, I am currently new to using bootstrap 4 and am trying to get the format above.
This is what I am currently trying so far....
<div class="container">
<div class="row">
<div class="col-md-4" >1</div>
<div class="col-md-8">2</div>
<div class="col-md-8 ">3</div>
</div>
</div>
Here you go!
.content {
min-height: 100px;
background: #ccc;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-4">
<div class="row h-100">
<div class="col-12 h-100">
<div class="content h-100">1</div>
</div>
</div>
</div>
<div class="col-8">
<div class="row">
<div class="col-12 mb-3 pl-0">
<div class="content">2</div>
</div>
<div class="col-12 pl-0">
<div class="content">3</div>
</div>
</div>
</div>
</div>
</div>
.one, .two, .three{
border: solid 2px gray;
min-height: 150px;
font-weight: bold;
}
.one{
background: lightblue;
}
.two{
background: lightgreen;
}
.three{
background: pink;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-sm-5 one">1</div>
<div class="col-sm-7">
<div class="row">
<div class="col-sm-8 two">2</div>
</div>
<div class="row">
<div class="col-sm-8 three">3</div>
</div>
</div>
</div>
</div>
I'm trying to make a grid view of columns.
Here is my code:
.pink{
background: pink;
}
.yellow{
background: yellow;
}
.gray{
background: gray;
}
.blue{
background: blue;
}
.green{
background: green;
}
.red{
background: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container"> <div class="row">
<div class="col-md-3 ">
<div class="col-md-12 pink">test</div>
<div class="col-md-12 yellow">test</div>
</div>
<div class="col-md-3">
<div class="col-md-12 gray">test</div>
</div>
<div class="col-md-6 ">
<div class="col-md-12 blue">test</div>
<div class="col-md-6 green">test</div>
<div class="col-md-6 red">test</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="col-md-12 green">test</div>
</div>
<div class="col-md-6">
<div class="col-md-12 pink">test</div>
</div>
<div class="col-md-3">
<div class="col-md-12 gray">test</div>
</div>
</div>
</div>
The column in gray should be of height as column pink and yellow.
The bottom Pink column is also not of full width.
Does anyone know why is this happening?
Thanks for any help.