can not make the background makes the 100% height in responsive - html

I have html code like this
<div class="container-fluid" style="height:calc(100vh - 120px)">
<div class="row h-100" style="margin-top:20px;">
<div class="col-lg-10 col-md-12 col-xs-12 h-100 div-border-shadow mx-auto " >
<div class="row mt-3">
<div class="col-lg-10 col-md-12 col-sm-12 text-center mx-auto">
<div id="gallery" class="clearfix">
#for (int i =0; i<8 ; i++)
{
<div class="gallery-div-format d-inline-block" style="width:200px; height:200px; background-color:red">
</div>
}
</div>
</div>
</div>
</div>
</div>
</div>
it makes a page like this
this is the css
.div-border-shadow {
width: 100%;
border: 1px solid #e2efef;
box-shadow: 0 0 7px 0 rgba(0, 0, 0, 0.29);
position: relative;
background: #fff;
border-radius: 10px;
margin-bottom: 15px;
}
.gallery-div-format {
margin-left: 10px;
margin-right: 10px;
border-radius: 10px;
box-shadow: 0 5px 5px 3px rgba(0,0,0,0.4);
}
but for checking the page being responsive(when I make the browser smaller) it becomes like this
as you can see the white background would not extend, I want the white background extends as long as the red box is repeating. which part of my code is wrong?

if you remove h-100 class from below tag it display correctly:
...
<div class="col-lg-10 col-md-12 col-xs-12 h-100 div-border-shadow mx-auto ">
...
</div>
....

Related

bootstrap right block over left block on mobile view

I have 2 blocks using bootstrap grid system.
On mobile view, I want the right block above the left one. The right block should also occupy 100% width of the screen.
My code so far:
<style>
.block {
border-radius: 8px;
box-shadow: 0 0 8px 4px rgba(0,0,0,0.1);
padding: 25px;
}
.block2 {
border-radius: 8px;
box-shadow: 0 0 8px 4px rgba(0,0,0,0.1);
}
</style>
<div class="container checkoutform">
<form class="row mx-n2">
<div class="col-sm-8 px-2">
<div class="block">
<!-- code -->
</div>
</div>
<div class="col-sm-4 px-2">
<div class="block2">
<!-- code -->
</div>
</div>
</form>
</div>
I have no idea how to proceed. Any help would be greatly appreciated
Try adding width: 100%; to the .block2 and .block style rules.
As well, try to switch the places of the block and block2 div elements.
It should be looking like that:
The CSS:
.block {
border-radius: 8px;
box-shadow: 0 0 8px 4px rgba(0,0,0,0.1);
padding: 25px;
width: 100%;
}
.block2 {
border-radius: 8px;
box-shadow: 0 0 8px 4px rgba(0,0,0,0.1);
width: 100%;
}
And the HTML:
<div class="container checkoutform">
<form class="row mx-n2">
<div class="col-sm-8 px-2">
<div class="col-sm-4 px-2">
<div class="block2">
<!-- code -->
</div>
</div>
<div class="col-sm-8 px-2">
<div class="block">
<!-- code -->
</div>
</div>
</form>
</div>
Please let me know if it worked!

I am making a website using bootstrap, I have made the card responsive but i can't make the image in the card responsive

This is My Format right now on phone/dekstop
++img++ ++Title++
++SNIPPET++
I want to create it in such a way that it looks like this on phone
++img++
++Title++
++Snippet++
This is how i want to design in the card but i don't know how
This is The HTML code I am making this project on django so ignore this part {}
{% for post in object_list %}
{% if post.header_image %}
<div class="container-fluid col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-10 " onclick="location.href='{%url 'article-details' post.pk %}';" style="cursor: pointer;">
<div class="row">
<div class="col-12 mt-3">
<div class="card ">
<div class="card-horizontal">
<div class="img-square-wrapper col-sm-4">
<img class="responsive" src="{{post.header_image.url}}" alt="Card image cap">
</div>
<div class="card-body">
<h4 class="card-title"> {{post.title}}</h4>
<p class="card-text">{{post.snippets}}</p>
</div>
</div>
<div class="card-footer">
<small class="text-muted">{{post.post_date}}</small>
</div>
</div>
</div>
</div>
</div>
{%endif%}
{% endfor %}
THIS the CSS part I have been trying all sorts of thing but its not happening, I dont know know what to do.
.item{
margin: auto;
padding:auto;
}
.flex-container-center {
justify-content: center;
}
.text{
padding: 5px;
text-align: center;
color: black;
}
.text2{
color: black;
}
.list-col *{
padding-top: 5px;
margin-left: 10px;
margin-right: 10px;
outline: 5px black;
}
.card-horizontal {
display: flex;
flex: 1 1 auto;
}
.card-horizontal:hover{
border: 1px solid #777;
}
img {
border: 1% solid #ccc;
display: block;
margin-left: 10%;
width: 100%;
height: auto;
}
img:hover{
border: 1% solid #777;
}
.responsive{
width: 100%;
height: 300px;
object-fit: cover;
object-position: bottom;
}
Rendered in desktop:
Rendered on Mobile:
Can anyone help me to understand what is wrong with my code?
Here It is, I removed unnecessary classes from styles.
Used col-md-4 and w-100
.item{
margin: auto;
padding:auto;
}
.flex-container-center {
justify-content: center;
}
.text{
padding: 5px;
text-align: center;
color: black;
}
.text2{
color: black;
}
a{
text-decoration: none !important;
}
.list-col *{
padding-top: 5px;
margin-left: 10px;
margin-right: 10px;
outline: 5px black;
}
.card:hover{
border: 1px solid #777;
}
img:hover{
border: 1% solid #777;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div class="container-fluid col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-10 " onclick="location.href='#';" style="cursor: pointer;">
<div class="row">
<div class="col-12 mt-3">
<div class="card ">
<div class="card-horizontal row">
<div class="img-square-wrapper col-md-4">
<img class="w-100" src="https://via.placeholder.com/150C/O" alt="Card image cap">
</div>
<div class="card-body">
<a href="#">
<h4 class="card-title"> Title</h4>
</a>
<p class="card-text">Lorem Epsum</p>
</div>
</div>
<div class="card-footer">
<small class="text-muted">11-02-2021</small>
</div>
</div>
</div>
</div>
</div>
There's a Bootstrap class for making images responsive: img-fluid.
Put this class in your img tag, and it should work without having to use other classes to make it look as you want.
Refer to: https://getbootstrap.com/docs/5.0/content/images/#responsive-images.
This link is for Bootstrap 5, but it works the same in Bootstrap 4.

columns are not taking correct width on small screens

I am making a grid system with Bootstrap 3.3.7. The width of the container is 1200px.
When I resize the browser window to < 768 px the columns on "Grid 1 + 2 + 3" are not reacting to the col-xs-xx i set. See the demo here.
When I set the columns to have a width on800 px instead of 600 px the width is correct on smaller screens, but the columns do not fit on bigger screens, unless I set a very big height on the columns.
How can I set the columns to get the correct width when the screen is below 768 px?
body {
background-color: #f5f5f5;
}
div {
background-color: #fff;
}
.index-content a:hover {
color: black;
text-decoration: none;
}
.index-content {
/*margin-bottom: 20px;*/
/*padding: 50px 0px;*/
}
.index-content .row {
margin-top: 20px;
}
.index-content a {
color: black;
}
.index-content .card {
background-color: #FFFFFF;
padding: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}
.index-content .card:hover {
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
color: black;
}
.index-content .card img {
width: 100%;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
height: 350px;
}
.index-content .card h4 {
margin: 20px;
}
.index-content .card p {
margin: 20px;
opacity: 0.65;
}
.index-content .blue-button {
width: 100px;
-webkit-transition: background-color 1s, color 1s;
/* For Safari 3.1 to 6.0 */
transition: background-color 0.5s, color 0.5s;
min-height: 20px;
background-color: #002E5B;
color: #ffffff;
border-radius: 4px;
text-align: center;
font-weight: lighter;
margin: 0px 20px 15px 20px;
padding: 5px 0px;
display: inline-block;
}
.index-content .blue-button:hover {
background-color: #dadada;
color: #002E5B;
}
/* GRID ELEMENTS MEDIA QUERIES */
#media (min-width: 768px) {
.card {
position: relative;
}
.card-content {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.card-content h4,
.card-content p {
color: white;
width: 100%;
float: left;
margin: 0 0 5px;
}
.card-content a {
float: right;
}
.index-content .card h4,
.index-content .card p {
padding: 15px 20px;
margin: 0;
}
.index-content .card p {
padding: 0 20px 15px;
margin: 0;
}
}
.margin_bottom{
margin-bottom:10px;
}
.row [class*="col-"]{
padding-right: 5px;
padding-left: 5px;
}
.row {
margin-left: -5px;
margin-right: -5px;
}
.card-img-bottom {
color: #fff;
height: 20rem;
background: url(images/img1.jpg) center no-repeat;
background-size: cover;
}
<div class="container">
<h3>Grid 1</h3>
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-6 margin_bottom">
<img src="http://placehold.it/600x600" alt="5" class="img-responsive"></img>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12 margin_bottom">
<img src="http://placehold.it/600x300" alt="5" class="img-responsive"></img>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
</div>
</div>
<h3>Grid 2</h3>
<div class="row">
<div class="col-xs-12 col-sm-4 margin_bottom">
<img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-12 col-sm-4">
<div class="row">
<div class="col-xs-6 col-sm-12 margin_bottom">
<img src="http://placehold.it/400x245" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-6 col-sm-12 margin_bottom">
<img src="http://placehold.it/400x250" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-4 margin_bottom">
<img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img>
</div>
</div>
<h3>Grid 3</h3>
<div class="row">
<div class="col-xs-3 col-sm-3 margin_bottom">
<!-- I can change the width to 800px to fit the xs viewport. But then the height on the column om sm viewport have to be 1020 px, which is way to high after my opnion -->
<img src="http://placehold.it/300x610" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-9 col-sm-6 margin_bottom">
<img src="http://placehold.it/600x600" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-12 col-sm-3 margin_bottom">
<div class="row">
<div class="col-xs-6 col-sm-12 margin_bottom">
<img src="http://placehold.it/300x300" alt="5" class="img-responsive"></img>
</div>
<div class=" col-xs-6 col-sm-12">
<img src="http://placehold.it/300x300" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
</div>
Grids are reacting as they should be. When col-xx-xx are nested, they assume their parent containers width to be 100%. You'll find more info on bootstrap doc page See Two columns with two nested columns.
Your html code has lot of redundant html divs. For ex. your grid 1 can be like this
<h3>Grid 1</h3>
<div class="row">
<div class="col-sm-6 margin_bottom">
<img src="http://placehold.it/600x600" alt="5" class="img-responsive"></img>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12 margin_bottom">
<img src="http://placehold.it/600x300" alt="5" class="img-responsive"></img>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
<div class="col-xs-6 col-sm-6 margin_bottom">
<img src="http://placehold.it/300x290" alt="5" class="img-responsive"></img>
</div>
</div>
</div>
</div>
Your dont need both col-xs-6 col-sm-6, just col-xs-6 will get job done.

Vertical alignment of button [duplicate]

This question already has answers here:
Vertical Align Center in Bootstrap 4 [duplicate]
(20 answers)
Vertical alignment in Bootstrap 4
(2 answers)
Closed 5 years ago.
Hi I have created one button. I gave it bootstrap for centring. Now I need to get that button vertically align to centre of page without margin and padding. How would I do that?
HTML is given below
<div class="row">
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4"></div>
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4">
<button class="case-study-button">
CASE STUDY <span class="fa fa-angle-double-down"></span>
</button>
</div>
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4"></div>
</div>
CSS is give below
/* without margin and padding */
.case-study-button {
height: 61px;
width: 267px;
border-radius: 30px;
background: transparent;
border-color: white;
border-width: 2px;
}
You can position the button absolute to 50% and then use transform translate to center it. Using a fixed width on the button might cause problems with responsiveness.
.wrap {
border: 1px solid black;
height: 300px;
}
.case-study-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
height: 61px;
max-width: 267px;
border-radius: 30px;
background: transparent;
border-color: white;
border-width: 2px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4"></div>
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4 wrap"><button class="case-study-button"> CASE STUDY <span class="fa fa-angle-double-down"></span>
</button></div>
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4"></div>
</div>
You can set 'display:flex' to its parent div and 'align-items:center'.
.btnOuter{
display:flex;
align-items:center;
height:500px
}
.case-study-button {
height: 61px;
width: 267px;
border-radius: 30px;
background: transparent;
border-color: white;
border-width: 2px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4"></div>
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4">
<div class="btnOuter">
<button class="case-study-button"> CASE STUDY <span class="fa fa-angle-double-down"></span></button>
</div>
</div>
<div class="col-xs-12 col-lg-4 col-md-4 col-sm-4"></div>
</div>
Change the CSS part like this :-
.case-study-button {
height: 10%;
width: 267px;
border-radius: 30px;
background: transparent;
border-color: white;
border-width: 2px;
position:absolute;
top:45%;
}

Unable to get all columns on same on row

I am using Bootstrap and trying to center 3 div blocks using the bootstrap 12 columns style. So each div takes up 4 columns. I want some spacing between these columns thus I added 10px margin to the right. This pushes down the 3rd div to the next row. How do I get my spacing and still keep all 3 columns on the same row?
HTML
<div class="container">
<div class="form-group col-sm-4 col-lg-4 cust_box">
<h3>Something</h3>
</div>
<div class="form-group col-sm-4 col-lg-4 cust_box">
<h3>Something</h3>
</div>
<div class="form-group col-sm-4 col-lg-4 cust_box">
<h3>Something</h3>
</div>
</div>
CSS
.cust_box{
margin-top: 15px;
margin-bottom:15px;
padding-left: 10px;
padding-right:10px;
background-color: #1A284B;
color: #fff;
height: 290px;
max-width:100%;
border: 1px solid #162444;
margin-right: 10px; /*Line that causes issue*/
}
Problem recreated in CodePen
Place your class cust_box inside the the column. The h3 has margin so that may also be interfering with your layout. You may also want to just use the row class instead of form-group.
See working Example Snippet. (colors added so you can see what's actually happening)
.cust_box {
margin: 15px 2.5px;
padding: 25px;
height: 290px;
max-width: 100%;
background-color: #1A284B;
color: #fff;
border: 1px solid #162444;
}
.cust_box h3 {
margin: 0;
}
.red {
border: 2px solid red;
}
.yellow {
background: yellow;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row yellow">
<div class="col-sm-4 red">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4 red">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4 red">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
</div>
</div>
Example without Color
.cust_box {
margin: 15px 2.5px;
padding: 25px;
height: 290px;
max-width: 100%;
background-color: #1A284B;
color: #fff;
border: 1px solid #162444;
}
.cust_box h3 {
margin: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
</div>
</div>
with the additional margin you are destroying the bootstrap grid system.
have you tried using padding instead of margin?
apart from this you can customize bootrap a lot!
have a look on this:
http://getbootstrap.com/customize/#grid-system
EDIT:
i looked at your code and saw your struggle:
use a inner div like this:
<div class="form-group col-sm-4 col-lg-4 cust_box">
<div class="inner">
<h3>Something</h3>
</div>
</div>
and use your style on the inner div:
.cust_box .inner{
margin-top: 15px;
margin-bottom:15px;
padding-left: 10px;
padding-right:10px;
background-color: #1A284B;
color: #fff;
height: 290px;
max-width:100%;
border: 1px solid #162444;
margin-right: 10px; /*should not be an issue anymore*/
}