How can i make Containers in Bootstrap side by side? - html

This is my container. I think it looks really good, but it only shows one container on the right side, and I want it to show 3 side by side. How can I do this?
If I just copy and paste the code right beneath itself, the second container is underneath the first one.
<div class="container">
<div class="row">
<div class="col-sm">
<h2>Product 2</h2>
</div>
<br>
<br>
<div class="text-center">
<img src="https://picsum.photos/200" alt="..." class="img-thumbnail" />
</div>
<div class="text-center">
<button class="btn btn-primary btn-sx" type="button">Confirm</button>
</div>
</div>
</div>

Use the Bootstrap Grid!
To arrange any elements into a grid, use the Bootstrap grid system. Give the parent element the row class, and give any children the col class. This will make all the children elements share the parent horizontally.
<div class="row">
<div class="col">
<div class="col-sm">
<h2>Product 2</h2>
</div>
</div>
<div class="col">
<div class="text-center">
<img src="https://picsum.photos/200" alt="..." class="img-thumbnail">
</div>
</div>
<div class="col">
<div class="text-center">
<button class="btn btn-primary btn-sx" type="button">Confirm</button>
</div>
</div>
</div>
You could replace col with col-4, which would do almost the same thing, but would be more explicit.
You could add a breakpoint (like sm) to the class (so col-sm), to make it automatically wrap vertically when you resize the window to a certain breakpoint.
Learn all about the Bootstrap grid system here.

W3schools: https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_default&stacked=h
You try it:
<div class="row">
<div class="col-sm-4">
<h2>Product 2</h2>
</div>
<div class="col-sm-4">
<img src="https://picsum.photos/200" alt="..." class="img-thumbnail" />
</div>
<div class="col-sm-4">
<button class="btn btn-primary btn-sx" type="button">Confirm</button>
</div>
</div>
</div>
`
don't forget :
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

Related

Stick image to side responsive bootstrap

I am trying to create this:
I have the left and right image and the monkey image.
I was trying to create a row and make the left image col-3, the right image col-3 and the monkey and text col-6 in the middle.
Everything is stacking up on each other, comes out of the screen and not working. How can I make this sort of thing?
<section class="hero-area">
<div class="container-fluid">
<div class="row">
<div class="col-md-3 col-xs-3">
<img src="images/hero-left.svg" class="" alt="">
</div>
<div class="col-xs-6 col-md-126>
<h1 class="">
<b>monKey</b> Generator</h1>
<br>
<h2 class="">Generate a
<b>unique monkey</b> avatar
<br> from a
<b>Banano public key</b>
</h2>
<img src="https://bananomonkeys.herokuapp.com/image?address=ban_3tapge8i4kw9wa4irgda7epm4gaurr4rnp7ybjziphkt48afd6ba5pnaegs6"
class="" alt="">
</div>
<div class="col-md-3 col-sm-3">
<img src="images/hero-right.svg" class="" alt="">
</div>
</div>
</div>
</section>
There are couple of typos in your snippet above eg: col-md-126 and missing " after that. Also bootstrap 4 does not have xs on cols so using just col-3 col-6 col-3 would do the job.
See the snippet below.
img {
width:100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<section class="hero-area">
<div class="container-fluid">
<div class="row">
<div class="col-3">
<img src="images/hero-left.svg" alt="monkey left">
</div>
<div class="col-6">
<h1>
<b>monKey</b> Generator
</h1>
<br>
<h2>Generate a
<b>unique monkey</b> avatar
<br> from a
<b>Banano public key</b>
</h2>
<img src="https://bananomonkeys.herokuapp.com/image?address=ban_3tapge8i4kw9wa4irgda7epm4gaurr4rnp7ybjziphkt48afd6ba5pnaegs6" />
</div>
<div class="col-3">
<img src="images/hero-right.svg" class="" alt="monkey right">
</div>
</div>
</div>
</section>

How to fill the gap of a div without using media query?

I'm using bootstrap cards to build this layout on desktop:
So far so good, at this width everything is ok as well:
But from this width to desktop width the container is not filled:
The HTML to build the card with the images is:
<div class="card h-60">
<div>
<div class="row box">
<div class="box-content formal">
<div class="col-md-12">
<img class="imageban" src="img/crm.png" />
<span><b>CRM</b></span>
</div>
</div>
<div class="box-right">
<a href="#">
<img class="img-responsive" src="img/img1.jpg"/>
</a>
</div>
</div>
</div>
<div>
<div class="row box">
<div class="box-content report">
<div class="col-md-12">
<img class="imageban" src="img/report.png" />
<span><b>Report</b></span>
</div>
</div>
<div class="box-right">
<a href="#">
<img class="imageban" src="img/img4.jpg"/>
</a>
</div>
</div>
</div>
<div>
<div class="row box">
<div class="box-content formal">
<div class="col-md-12">
<img class="img-responsive" src="img/formal_notices.png" />
<span><b>Formal Notices</b></span>
</div>
</div>
<div class="box-content text">
<a href="#">
Open the Formal <br>Notice Document <br>Library
</a>
</div>
</div>
</div>
</div>
And the CSS is only this line:
.row.box{
max-width: 345px;
}
I'm stuck in this, any help would be nice. Thanks.
You can remove the class .box and use the Bootstrap classes instead col-md-4 col-xs-12.

Aligning 2 columns with images in rows

i want to align col-lg-8 with col-lg-4 that contains 2 rows for 2 images, i need those 2 columns align perfectly so they fit each others height
i tried this:
desired look
and what i got
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-8">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg"/>
</div>
<div class="col-lg-4">
<div class="row">
<div class="col-lg-2">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg"/>
</div>
</div>
<div class="row">
<div class="col-lg-2">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg"/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Link to CODEPEN
While it is true that you can't depend on Bootstrap to do everything, you don't need any of the additional css "gymnastics" proposed by #derek-gutierrez because with native Bootstrap classes alone you can get done almost everything and most certainly in this particular case here.
The following code is leaner and does everything you want with native Bootstrap classes alone. No extra gymnastics needed. All with perfect paddings/gutter out of the box:
<div class="container">
<div class="row">
<div class="col-lg-8">
<img src="Cupcakes01.jpg" class="img-fluid">
</div>
<div class="col-lg-4">
<div class="row">
<div class="col">
<img src="Cupcakes01.jpg" class="img-fluid">
</div>
</div>
<div class="row">
<div class="col">
<img src="Cupcakes01.jpg" class="img-fluid">
</div>
</div>
</div>
</div>
</div>
That's the magic of the Bootstrap grid just working.
Notice: You had 2 unnecessary divs (first row and col-lg-12). I cut them out. That was totally useless fat in your code. Don't put in more code than necessary. That reduces the number of potential problems.
Try below code, I hope this is what you are looking for
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-lg-12">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg"/>
</div>
<div class="col-lg-8">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg"/>
</div>
<div class="col-lg-4">
<img src="http://i183.photobucket.com/albums/x312/Tiefnuker/office_02_zpsdz0zixcd.jpg"/>
</div>
</div>
</div>
You can't depend on bootstrap to do everything. You are going to add some of your own custom CSS to achieve the effect you want. If you are unfamiliar with css and selectors W3 schools is a good resource.
To achieve this effect add this CSS to the head of your document:
(This is simply to illustrate based off of your example, you will want to be more specific with your selectors if there is going to be more to this page)
<style>
img {
width: 100%; /* Makes imgs match the parent column/container width */
}
#top-image {
margin-bottom: 30px; /* Adds the necessary space to the bottom of the first image */
}
</style>
The columns inside the col-lg-4 should not be col-lg-2. This is basically saying these columns are 2/12ths the size of the container. Instead change them to 12 to span the full width of the container. I also added an id to the first image in this column "id="top-image" to add the necessary margin.
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-8">
<img src="img/1.png" />
</div>
<div class="col-lg-4">
<div id="top-image" class="row">
<div class="col-lg-12">
<img src="img/2.png" />
</div>
</div>
<div class="row">
<div class="col-lg-12">
<img src="img/3.png" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>

How to force div to be bottom using bootstrap

I'm using bootstrap on Codepen.io.
I have a page divided into 3 main divs. The middle div has 3 images and is divided into 3 columns.
Everything looks fine on desktop but once I resize the window, the bottom div overlaps the third image instead of moving to the bottom.
Is there a way to make bootstrap work its magic without changing CSS manually?
https://codepen.io/oldmanwithbeer/pen/ENzvoY?editors=1000#0
<div class="container-fluid">
<div class="row">
<div id="one" class="col-md-12">
<div id="btn_row" class="row">
<div class="col-md-12 text-center">
<button type="button" class="btn btn-primary">some text</button>
<button type="button" class="btn btn-primary">some text</button>
<button type="button" class="btn btn-primary">some text</button>
<button type="button" class="btn btn-primary">some text</button>
</div>
</div>
</div>
</div>
<div class="row">
<div id="two" class="col-md-12">
<h2>some text</h2>
<div class="row">
<div class="col-md-4">
<div class="thumbnail">
<a href="#" target="_blank">
<img class="img-responsive" src="#" alt="text"></a>
<div class="caption">some text</div>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<a href="#" target="_blank">
<img class="img-responsive" src="#" alt="text"></a>
<div class="caption">some text</div>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<a href="#" target="_blank">
<img class="img-responsive" src="#" alt="text"></a>
<div class="caption">some text</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div id="three" class="col-md-12"><h3>text</h3>
</div>
</div>
</div>
Actually for the proper responsive or mobile view developers use the css media query. If you look at the bootstrap doc then you may see the demonstration. Importantly you used fixed height in different elements like:
#portfolio {
height: 400px;
}
So I recommendation is to use css media query at the bottom of your stylesheet or style with auto height. Like this:
#media only screen and (max-width: 767px) {
#portfolio {
height: auto;
}
}
Hope it will do the magic ...

Added a space between an image and a div using bootstrap

<div class="row">
<div>
<img id="image" class="col-md-2" src="img.png">
</div>
<div id="otherPart" class="col-md-4">
</div>
</div>
I am using Twitter bootstrap to space my html objects and I want to make it so that my id="image" is dynamic and able to adjust its size depending on the size of the image. At the same time I still want to have the spacing between my image and and "otherPart". I tried deleting col-md-2 from image and adding margins in the css but it didn't work.
<div class="row">
<div class="col-md-2">
<div class="yourAdditionalMarginClass">
<img id="image" src="img.png" class="img-responsive">
</div>
</div>
<div class="col-md-4">
<div id="otherPart"> ... </div>
</div>
</div>
The image is responsive now, the basic padding of the col's is applied and if you need even more padding/margin, wrap another div around the image, give it a class and apply your styles to that class.
Remove the col-md-2 from the image and add it to the outer most div like:
<div class="row col-md-2">
...
</div>
Try this way
<div class="row">
<div class=" col-md-2">
<img id="image" src="img.png">
</div>
<div id="otherPart" class="col-md-4">
</div>
</div>