How do i create a 2 column grid in Bootstrap 4 that is responsive but the column widths are not fixed.
For example: I will have an image in the LEFT column of some width and I want the RIGHT column to flex to the remaining width of the parent DIV.
<div class="tut_wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-xl-8 col-lg-12 col-md-12 col-sm-12">
<div class="tut_leftbox"><img class="img-fluid" src="tutorials/anamorphic_drawing1.jpg"></div>
</div>
<div class="col-xl-4 col-lg-12 col-md-12 col-sm-12">
<div class="tut_rightbox">
<h3>Introduction</h3>
some text
</div>
</div>
</div>
</div>
</div>
To make a div use up the space left, you just need to add the class col to that div. It will automatically assign all the space left to it. Under mobile view (when the left div occupies the whole row), the div will automatically become 100% wide.
div {
border: 1px solid #000000;
}
<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>
<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://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container">
<div class="row">
<div class="col-4">
ex: col-4
</div>
<div class="col">
this will take up all the space left
</div>
</div>
</div>
Or if you want to have your left div 100% fit with the image, you could do col-xs-auto to the left div and col to the right div.
div {
border: 1px solid #000000;
}
<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>
<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://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container">
<div class="row justify-content-md-center">
<div class="col-xs-auto">
Fixed width image here
</div>
<div class="col">
Other content
</div>
</div>
</div>
Details of Bootstrap 4 grid system could be found HERE.
Related
i have used container class for the parent div
here:
<div class="container">
<main role="main" class="pb-3">
<div style="width:100%; height:300px;z-index:-1" class="col-lg-12 mt-n4 bg-white text-
center">
<div style="margin: 0;position: absolute;top: 50%;left: 50%;-ms-transform:
translate(-50%,
-50%);transform: translate(-50%, -50%);">
<img class="rounded-circle border border-info p-1" style="width:150px;height:150px;"
src="~/ProfileImages/#currentuser.ImageProfile">
<h4 class="text-center font-weight-bold text-info">#Model.ApplicationUser.ArName</h4>
</div>
</div>
</main>
</div>
now: i want to make width for div inside the parent 100% but i could not with this code:
<div style="width:100%; height:300px;z-index:-1" class="col-lg-12 mt-n4 bg-white text-center">
<div style="margin: 0;position: absolute;top: 50%;left: 50%;-ms-transform: translate(-50%,
-50%);transform: translate(-50%, -50%);">
<img class="rounded-circle border border-info p-1" style="width:150px;height:150px;"
src="~/ProfileImages/#currentuser.ImageProfile">
<h4 class="text-center font-weight-bold text-info">#Model.ApplicationUser.ArName</h4>
</div>
</div>
how can i remove bootstrap "container" class effects on child element?
//Try this One, It works fine and responsive in all widths and no need to write that much css
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<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">
</head>
<body style="width: auto;height: auto;">
<div class="container mt-2">
<div class="card bg-white text-
center" style="width:20rem">
<img class="img-fluid card-img-top"
src="https://cnet2.cbsistatic.com/img/-e95qclc6pwSnGE2YccC2oLDW_8=/1200x675/2020/04/16/7d6d8ed2-e10c-4f91-b2dd-74fae951c6d8/bazaart-edit-app.jpg">
<div class="card-body">
<h4 class="text-center font-weight-bold text-info">#Model.ApplicationUser.ArName</h4>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
</body>
</html>
I had two classes, for md size and sm size. Sm size was supposed to trigger the vertical stacking of columns.
Actually, Bootstrap has xs as its default breaking point, which is supposed to trigger the same effect, but nothing happens.
If I want vertical stacking, I have to set the columns to 12, and have no other classes for different screen sizes.
The code is here:
https://hastebin.com/uyaboxatuk.js
You may have copied the wrong <link> & <script> tags for Bootstrap. Also watch your indentation. Keep in mind that you're better off putting your <link> tags first and then your <script> tags afterwards. Replace your <link> & <script> tags with what I have below in the exact order that are they are and it should work fine.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
Bootstrap Breakpoints specify the minimum screen size to apply the columns to.
For example col-md classes will only be applied to screen widths greater than 768px.
See the complete table of breakpoints and their sizes here.
Using your code as an example:
<html>
<head>
<style>
.row {
margin-bottom: 10px;
}
.a {
background-color: red;
}
.b {
background-color: blue;
}
.c {
background-color: green;
}
.d {
background-color: gray;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js" integrity="sha384-6khuMg9gaYr5AxOqhkVIODVIvm9ynTT5J4V1cfthmT+emCG6yVmEZsRHdxlotUnm" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="a row">
<div class="b col-lg-2">large</div>
<div class="c col-lg-4">large</div>
<div class="d col-lg-6">large</div>
</div>
<div class="a row">
<div class="b col-md-2">medium</div>
<div class="c col-md-4">medium</div>
<div class="d col-md-6">medium</div>
</div>
<div class="a row">
<div class="b col-sm-2">small</div>
<div class="c col-sm-4">small</div>
<div class="d col-sm-6">small</div>
</div>
</div>
</body>
</html>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="row">
<div class="col-sm-2">
<span class="badge badge-info badge-pill">2</span>
</div>
<div class="col-sm-10">
<p>short text to write.</p>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
This code run in wrong way, becouse dont create one row with two columns in 2: 10 ratio, but second column goes down. I can add that when i fill with content second column that include 100 % width of itself - then everything is well.
You need a container (.container / .container-fluid) to wrap your rows and columns.
<div class="container">
<div class="row">
<div class="col-sm-2">
<span class="badge badge-info badge-pill">2</span>
</div>
<div class="col-sm-10">
<p>short text to write.</p>
</div>
</div>
</div>
fiddle: http://jsfiddle.net/aq9Laaew/184407/
I have this code: https://www.bootply.com/a0wTkTuKyG
<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-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-md-2" style="background-color:red">
Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>
</div>
<div class="col-md-6" style="background-color:yellow">
Content<br>Content<br>Content<br>Content<br>Content<br>
</div>
</div>
</div>
As you can see there is a big remaining white area right to the yellow "Content" div. I want that when I scale (resize) the window horizontally first shrink the white area and only when it's over re-scale or break the red and blue divs.
I also want to add some margin between the sidebar and the content which should be reduced first as well.
So I want the same as "container" class behaves. Keep the content size until it is possible and only re-size content when windows size become small enough.
Can I do it with bootstrap?
as far as i know you can get close with bootstrap, if i understood you well this might help you:
<div class="container-fluid">
<div class="row">
<div class="col-md-2 col-sm-3 col-xs-4" style="background-color:red">
Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>
</div>
<div class="col-md-6 col-sm-7 col-xs-8" style="background-color:yellow">
Content<br>Content<br>Content<br>Content<br>Content<br>
</div>
</div>
</div>
Its hard for me to explaint what i want, so i made a mocup
How to make that with bootstrap 4? So goal is that those 4 elements on the right are all the time (except on mobile) equal height like element on the left (image). Can someone help with that? Here is makrup for now.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
</head>
<body>
<div class="container">
<section class="hero">
<div class="row">
<div class="col col-md-8"><img src="http://placehold.it/700x300/ccc/333.png?text=placeholder" alt=""></div>
<div class="col col-md-4">
<div class="contentMy">somthing</div>
<div class="contentMy">somthing</div>
<div class="contentMy">somthing</div>
<div class="contentMy">somthing</div>
</div>
</div>
</section>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</body>
</html>
You can use Bootstrap 4's new flexbox utility classes. The d-flex class is used for display:flex, and then flex-column is used to set flex-direction: column..
<div class="container">
<section class="hero">
<div class="row">
<div class="col col-md-8"><img src="" alt=""></div>
<div class="col col-md-4 d-flex flex-column">
<div class="contentMy h-100">somthing</div>
<div class="contentMy h-100">somthing</div>
<div class="contentMy h-100">somthing</div>
<div class="contentMy h-100">somthing</div>
</div>
</div>
</section>
</div>
http://www.codeply.com/go/YyTEyi4IcU