How can I align this div in left using CSS? - css

I have this site:
link
I want to left align this div. I attached bellow a pic to understand what i want to do.
CODE HTML:
<div class="alt-service-grid">
<div class="row">
<div class="col-sm-6 col-md-3 col-lg-3">//SOME CODE HTML</div>
<div class="col-md-6 col-lg-6 hidden-xs hidden-sm">//SOME CODE HTML</div>
<div class="col-sm-6 col-md-3 col-lg-3">
<div class="alt-service-wrap">
//SOME CODE HTML
</div>
<div class="alt-service-wrap">
//SOME CODE HTML
</div>
<div class="alt-service-wrap">
//This is myDiv,align-left
</div>
</div>
</div>
</div>
This site is made with Wordpess and I use a paid template.
I have tried at last div to add the fallow html code float:left;
Can you help me to solve this problem please?
Thanks in advance!

You need to place it after row class div
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="alt-service-grid">
<div class="row">
<div class="col-sm-6 col-md-3 col-lg-3">//SOME CODE HTML</div>
<div class="col-md-6 col-lg-6 hidden-xs hidden-sm">//SOME CODE HTML</div>
<div class="col-sm-6 col-md-3 col-lg-3">
<div class="alt-service-wrap">
//SOME CODE HTML
</div>
<div class="alt-service-wrap">
//SOME CODE HTML
</div>
</div>
</div>
<div class="alt-service-wrap">
//This is myDiv,align-left
</div>
</div>

You can change the place of your div and make it in the first col-sm-6 col-md-3 col-lg-3 div:
<div class="alt-service-grid">
<div class="row">
<div class="col-sm-6 col-md-3 col-lg-3">
<div class="alt-service-wrap">
//SOME CODE HTML
</div>
<div class="alt-service-wrap">
//This is Your Div
</div>
</div>
<div class="col-md-6 col-lg-6 hidden-xs hidden-sm">//SOME CODE HTML</div>
<div class="col-sm-6 col-md-3 col-lg-3">//SOME CODE HTML</div>
</div>
</div>

Related

Bootstrap responsive container (like columns)

This might be a bit of a silly question - but I could not find an answer to what I'm trying to do..
I'm trying to make the entire container div responsive (like a column inside a row).
e.g. I want to have the effect that this would produce:
<div className="container">
<div className="row justify-content-center">
<div className="col-lg-6 cold-sm-10">
...
</div>
</div>
</div>
but in one line... something like:
<div className="container-lg-6 container-sm-10">
...
</div>
Is there something in Bootstrap that could achieve this?
I tried the classes container-sm but they are not working like what I want.
That is not how the containers work. But you can easily achieve the layout by just nesting everything inside of a .col-12.col-sm-10.col-lg-6 inside a .row inside a .container-fluid
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<div class="container-fluid p-0">
<div class="row justify-content-center">
<div class="col-12 col-sm-10 col-lg-6">
<div class="row">
<div class="col bg-primary">
<h1>1</h1>
</div>
<div class="col bg-secondary">
<h1>2</h1>
</div>
<div class="col bg-info">
<h1>3</h1>
</div>
</div>
<div class="row">
<div class="col bg-info">
<h1>4</h1>
</div>
<div class="col bg-primary">
<h1>5</h1>
</div>
</div>
</div>
</div>
</div>

Grid columns doesn't wrap as expected

I have the following bootstrap-4 column structure:
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-4">A</div>
<div class="col-xs-6 col-sm-4">B</div>
<div class="col-xs-6 col-sm-4">C</div>
</div>
</div>
The expected column layout according to screen size is:
XS:
[ A ]
[B][C]
SM and up:
[A][B][C]
However, at XS each div takes the full width like this:
[A]
[B]
[C]
Check JSFiddle snippet here.
What could be wrong here?
col-xs-* simply does not exists on Bootstrap
The grid options are:
col-*
col-sm-*
col-md-*
col-lg-*
col-xl-*
Soucre: https://getbootstrap.com/docs/4.0/layout/grid/#grid-options
So probably what you wanted to use is col-*
.row {
background: #E2E2E2;
}
.card {
border: solid 1px #6c757d;
}
<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">
<div class="row">
<div class="col-12 col-sm-4 text-center">
<div class="card">
<div class="card-body">
A
</div>
</div>
</div>
<div class="col-6 col-sm-4 text-center">
<div class="card">
<div class="card-body">
B
</div>
</div>
</div>
<div class="col-6 col-sm-4 text-center">
<div class="card">
<div class="card-body">
C
</div>
</div>
</div>
</div>
</div>
You're using col-xs- but it doesn't exist in Bootstrap version 4.x.
So the small breakpoint is actually the first one defined mobile and up.
If you intend to have B & C to be half the size on mobile, I suggest to program it like this:
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="card text-center">
<div class="card-body">
A
</div>
</div>
</div>
<div class="col-6 col-sm-4">
<div class="card text-center">
<div class="card-body">
B
</div>
</div>
</div>
<div class="col-6 col-sm-4">
<div class="card text-center">
<div class="card-body">
C
</div>
</div>
</div>
</div>
</div>
If not, move the breakpoint of sm up to md.
Moving "div class row" one line below will solve your problem.
I've tested your code on "codepen.io", and works just fine. Maybe the "CDN" that "jsfiddle" uses is some version that does not render the classes in the appropriate manner. It is important whether you are using a "CDN" or you are downloading the files on you pc (.js, .css, etc.), that they support the Bootstap version you are using.

bootstrap two column in same line all devices

I am trying to use two column divisions in same line.
Check my code:
<div class="col-md-12">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
Left Div
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
Right Div
</div>
</div>
</div>
this structure responsive for till 574px. but when i reduce browser size after 574px, divisions show in two rows. but my requirement show it in same line (left & Right)
please check above image. that the issue.
You can set same divided columns for every screen using col class
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col bg-success">
Left Div
</div>
<div class="col bg-warning">
Right Div
</div>
</div>
</div>
</div>
bg-success and bg-warning is just for color
<div class="col-12 ">
<div class="row">
<div class="col-6">
Left Div
</div>
<div class="col-6">
Right Div
</div>
</div>

How can I get the nth-child of a Bootstrap .card body

I'm trying to set the background-color of card-body in bootstrap 4, however I'm not sure how I can obtain the card-body element as each body has a different parent (I think my understanding of this is correct), is it possible to do this using the below code?
I've put a sample snippet below which shows the paragraphs working, but the cards are not working here:
.bg-alt:nth-child(5n+1){background-color: #5bc0de;}
.bg-alt:nth-child(5n+2){background-color: #ed9c28;}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p class="bg-alt"><span>test 1</span></p>
<p class="bg-alt"><span>test 1</span></p>
<p class="bg-alt"><span>test 1</span></p>
<p class="bg-alt"><span>test 1</span></p>
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-6 grid-margin ">
<div class="card">
<div class="bg-alt">
98787667f
</div>
</div>
</div>
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-6 grid-margin">
<div class="card">
<div class="bg-alt">
45645656u57u5
</div>
</div>
</div>
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-6 grid-margin">
<div class="card">
<div class="bg-alt">
456456456456
</div>
</div>
</div>
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-6 grid-margin">
<div class="card">
<div class="bg-alt">
123123123
</div>
</div>
</div>
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-6 grid-margin">
<div class="card">
<div class="bg-alt">
123123
</div>
</div>
</div>
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-6 grid-margin">
<div class="card">
<div class="bg-alt">
324234234
</div>
</div>
</div>
</div>
</body>
</html>
The "card-body" is always the ONLY child (never the fifth), as the "nth-child" selector only references immediate siblings.
Try:
.col-xl-2:nth-child(5n+1) .bg-alt {background-color: #5bc0de;}
.col-xl-2:nth-child(5n+2) .bg-alt {background-color: #ed9c28;}

Bootstrap 3 two responsive rows next to each other?

I'm using Bootstrap 3 and trying to solve this what's mocked on the image. I used one row with two cols, and they are next to each other like in the image, but when I resize to mobile I want the right side to fall beneath the left. Any help is appreciated, thank you.
Code sample:
<div className="container">
<div className="row">
<div className="col-xs-4 col-offset-xs-1">
<h1>1</h1>
</div>
<div className="col-xs-4">
<div className="row">
<h1>2</h1>
</div>
</div>
.black{background-color:#000; height:320px;}
.red{background-color:#F00; height:100px;margin-bottom:10px;}
<!-- 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">
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12 black">
black
</div>
</div>
</div>
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12 red">
one
</div>
</div>
<div class="row">
<div class="col-xs-12 red">
two
</div>
</div>
<div class="row">
<div class="col-xs-12 red">
three
</div>
</div>
</div>
</div>
</div>
Bootstrap allows nesting your elements easily, here you go: https://jsfiddle.net/denea/DTcHh/25594/
<div className="container">
<div class="row">
<div class="col-sm-6 col-xs-12" id="first">
<h1>1</h1>
</div>
<div class="col-sm-6 col-xs-12" id="second">
<div class="row">
<h1>2</h1>
</div>
<div class="row">
<h1>3</h1>
</div>
<div class="row">
<h1>4</h1>
</div>
</div>
</div>
and read this: http://getbootstrap.com/css/#grid-nesting
Bootstrap allows for nesting which will provide what you need:
<div class="row">
<div class="col-sm-6">
Left column
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12">
Right column, row 1
</div>
</div>
<div class="row">
<div class="col-sm-12">
Right column, row 2
</div>
</div>
<div class="row">
<div class="col-sm-12">
Right column, row 3
</div>
</div>
</div>
</div>
More info here.
You can achieve this by using flexbox and media query
#media (max-width: 360px) {
.container > .row {
display:flex;
flex-flow: row-reverse wrap;
}
}
Demo: https://jsfiddle.net/xs3joev8/1/

Resources