I'm currently learning to make a responsive website. I'm confused about how do I do the breakpoints of the content when the screen size changed. Here's what I wanted to do :
This code below only work for the desktop size :
<div className="row wrapper-about">
<div className="col-lg-6 col-md-6 col-6">
<div className="img-box">
<img src="/pp1.jpg" alt="foto.jpg" />
</div>
</div>
<div className="col-lg-6 col-md-6 col-6">
<div className="row">
<div className="desc-container">
<h5 className="text-justify">
Content 2
</h5>
</div>
</div>
<div className="row desc2-d">
<span>
Content3
</span>
</div>
</div>
</div>
The simplest way (no extra CSS or duplicate markup) to get this layout would be to disable flexbox for the larger screen width and use the float utils:
https://www.codeply.com/go/snVOquHz1k
<div class="container">
<div class="row d-md-block">
<div class="col-6 col-md-8 float-left border border-danger c1">
c1
</div>
<div class="col-6 col-md-4 float-left border border-success">
c2
</div>
<div class="col-12 col-md-4 float-left border border-warning">
c3
</div>
</div>
</div>
Similar questions have been answered before:
Rearranging responsive Bootstrap 4 grid layout
Bootstrap with different order on mobile version
One tall div next to two shorter divs on Desktop and stacked on Mobile with Bootstrap 4
Bootstrap 4 - Stack 2 columns with 1 large column on the right
With the Bootstrap grid, you'd have to place the C3 div twice. Once inside the 2nd column of the first row (for desktop view) and the other below the first row (for mobile view); Then toggle the visibility based on the 768px breakpoint to get what you wanted...
code snippet below:
.divC1 {
border: 5px solid red;
height: 300px;
}
.divC2 {
border: 5px solid green;
height: 150px;
}
.divC3 {
border: 5px solid yellow;
height: 150px;
}
#media screen and (max-width:768px) {
.divC2 {
height: 300px
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class='col-6 col-sm-6'>
<div class="row">
<div class="col-sm-12 divC1"> C1
</div>
</div>
</div>
<div class='col-6 col-sm-6'>
<div class="row">
<div class="col-sm-12 divC2"> C2
</div>
<div class="col-sm-12 divC3 d-none d-md-block"> C3
</div>
</div>
</div>
<div class='col-12 divC3 d-block d-md-none'> C3
</div>
</div>
</div>
I think following code will help you.
.c1 { height:200px; outline:2px solid red; outline-offset: -5px; }
.c2 { height:100px; outline:2px solid green; outline-offset: -5px; }
.c3 { height:100px; outline:2px solid yellow; outline-offset: -5px; }
#media only screen and (max-width:768px) and (min-width:200px) {
.c1 { height:auto; }
.c2 { height:auto; }
.c3 { height:auto;}
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 c1">
C1
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 c2">
C2
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 c3">
C3
</div>
Related
I'm working with bootstrap 4 and following codes,
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.css">
<div class="card-header rounded-0 border border-dark">
<div class="row">
<div class="col-12 col-md-4 ">
<img src="{{asset('images/usa.jpg')}}" alt="..." class="rounded-circle">
</div>
<div class="col-12 col-md-8 ">
<p>This is not a game fgfhg dfghdh dhdhdf dfgdhfhg dfdfhfh dfhdfhdf dfhdfh</p>
</div>
</div>
</div>
I need display above two div elements in the same row on large screen and need separate two rows (image is above and paragraph is under the image) when it is displaying mobile device. I use following col-12 col-sm-8 col-md-6 col-lg-4 col-xl-3 item codes in side to the div but not success.
how could I manage this problem?
View in Full Page , You will get it
body {
padding-top: 40px;
}
.col-sm-6 {
background: #ccc;
}
.other {
background: #a4a4a4;
}
.p {
text-align: center;
padding-top: 120px;
}
.p a {
text-decoration: underline;
color: blue;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-sm-6">
<h1>Bootstrap Grid Demo</h1>
</div>
<div class="col-sm-6 other">
<h1>2 Columns</h1>
</div>
</div>
</div>
<p class="p">Demo by Jabir Sayed. See article.</p>
So I'm trying to center my green divs vertically which are the ones with the class myCol by using align-items-center on the parent row but it's not centering it and I have no idea why.
Why does it behave like that?
.myRow {
height: 30vh;
border: orange dotted 2px;
}
.myCell {
width: 100px;
height: 100px;
background: green;
border: blue dotted 3px;
}
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"/>
<div class="container">
<div class="row align-items-center myRow">
<div class="col-3 myCell">
</div>
</div>
<div class="row myRow">
<div class="col-4 myCell">
</div>
</div>
</div>
The problem with your code is that you are using Bootstrap version 2 whereas you should be using Bootstrap version 4.
Just replace the links for bootstrap script and css file and it should work.
You are using bootstrap version 2, but align-items-center class appear in bootstrap version 4.
Replace your html code to:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row align-items-center myRow">
<div class="col-3 myCell">
</div>
</div>
<div class="row myRow">
<div class="col-4 myCell">
</div>
</div>
</div>
I already tried different solutions posted here to get two columns with the same height, but unfortunately I can't get this to work. The Problem is, that I have three images, one on the left in "portrait mode" and two on the right in "landscape mode". I want both images together on the right to have the same height as the image on the left.
I think that this could be a solution, but I didn't get this to work: The two items on the right could each have a height of 50% of the div on the left. The images inside the item then should fill the height and have an auto width.
Like this:
Here is what my basic code looks so far: https://jsfiddle.net/qg7t976L/
.padding-0 {
padding: 0;
}
img {
width: 100%;
}
img {
border: 1px white solid;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
<div id="work" class="content">
<div class="container-fluid work-body">
<div class="row">
<div class="padding-0 col-sm-6">
<div class="work-inner">
<div class="work-item">
<img src="http://placehold.it/500x750" alt="work1">
</div>
<!--/.work-item-->
</div>
<!--/.work-inner-->
</div>
<div class="padding-0 col-sm-6">
<div class="padding-0 work-inner col-sm-12">
<div class="work-item">
<img src="https://placehold.it/450x250" alt="work2">
</div>
<!--/.work-item-->
</div>
<div class="padding-0 work-inner col-sm-12">
<div class="work-item">
<img src="https://placehold.it/500x250" alt="work3">
</div>
<!--/.work-item-->
</div>
</div>
</div>
</div>
<!--/.container-->
</div>
<!--/work-->
You can try with these code.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row row--equal">
<div class="col-md-6 no-padding">
<div class="item item--full-height">
<img src="https://i.stack.imgur.com/WS7U5.png" alt="">
</div>
</div>
<div class="col-md-6 item--half-height no-padding">
<div class="item ">
<img src="https://i.stack.imgur.com/cslWU.png" alt="">
</div>
<div class="item item--half-height">
<img src="https://i.stack.imgur.com/niAPD.png" alt="">
</div>
</div>
</div>
</div>
</body>
</html>
CSS:
.row--equal{
display: flex;
}
.no-padding{
padding-left: 0px !important;
padding-right: 0px !important;
}
.item{
margin-right: 1px;
margin-bottom: 1px;
}
.item img{
width: 100%;
height: 100%;
}
.item--full-height{
height: 100%;
}
.item--half-height{
height: 50%;
}
So i have a 4 column row in bootstrap and i want to add a divider in between them.
I've added this through the css and made it so .divider-right:last-child has no border. This is fine until you resize the page and it goes from a 4 column grid, to a two column grid.
.divider-right {
border-right:1px solid #dddddd;
}
.divider-right:last-child {
border-right:transparent;
}
<section class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
</div>
</section>
This should handle removing the border as the viewport is reduced.
Add the appropriate Pseudo Class to the relevant media query.
.row div.divider-right {
border-right: 1px solid #f00;
}
.row div.divider-right:last-child {
border-right: none;
}
#media(max-width:991px) {
.row div.divider-right:nth-child(2n) {
border-right: none;
}
}
#media(max-width:767px) {
.row div.divider-right {
border-right: none;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<section class="container">
<div class="row">
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here1</div>
</div>
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here2</div>
</div>
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here3</div>
</div>
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here4</div>
</div>
</div>
</section>
i think you want to remove border of second element when it jumps to next div
try this code
#media (max-width:991px) {
.divider-right:nth-child(2n) {
border-right: medium one;
}
}
I'm trying to show two divs next to each other using Bootstrap, but there is a distance between them. How can i place them exactly next to each other.
The code:
<div class="col-lg-8 col-lg-offset-2 centered">
<div style="float: left; border: 1px solid; width: 227px; height: 50px;"></div>
<div style="float: right; border: 1px solid;width: 227px; height: 50px;"></div>
</div>
Image illustration:
Look into grids in Bootstrap.
You could do something like this:
<div class="row">
<div class="col-xs-6">div 1</div>
<div class="col-xs-6">div 2</div>
</div>
Adding to Lschessinger's answer you could use offset to center the blocks. Look here under Offsetting columns
Maybe this is what you're looking for?
<style>
.border {border: 1px solid #CCC;}
</style>
<div class="row">
<div class="col-xs-2 border col-xs-offset-4">div 1</div>
<div class="col-xs-2 border">div 2</div>
</div>
Or if you have to stick to your code with the inline styles and specific widths then maybe this, you can increase the width between by increasing the width 454px to 464px for a 10px gap, and so on:
<div class="col-lg-12">
<div style="width: 454px;" class="center-block">
<div style="border: 1px solid; width: 227px; height: 50px;" class="pull-left"></div>
<div style="border: 1px solid; width: 227px; height: 50px;" class="pull-right"></div>
</div>
</div>
One approach is to have a row containing two div elements. The elements will seemingly stack next to each other due to the fact that Bootstrap is built with flexbox.
In the following example I'm using the class justify-content-center to center both elements. And col-auto that will size columns based on the natural width of their content.
div{border:1px solid blue}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="container">
<div class="row justify-content-center p-3">
<div class="col-auto">
content one
</div>
<div class="col-auto">
content two
</div>
</div>
</div>
Align the elements to the left by using justify-content-start
div{border:1px solid blue}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="container">
<div class="row justify-content-start p-3">
<div class="col-auto">
content one
</div>
<div class="col-auto">
content two
</div>
</div>
</div>
Align the elements to the right by using justify-content-end
div{border:1px solid blue}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="container">
<div class="row justify-content-end p-3">
<div class="col-auto">
content one
</div>
<div class="col-auto">
content two
</div>
</div>
</div>
Note: This codes do not have breakpoints. If you want to add breakpoints use this format: col-{breakpoint}-auto or/and justify-content-{breakpoint}-auto