Bootstrap 4 Content Won't Horizontally and Vertically Align Center [duplicate] - html

This question already has answers here:
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Why doesn't height: 100% work to expand divs to the screen height?
(12 answers)
How to vertically center a container in Bootstrap?
(10 answers)
Vertical Align Center in Bootstrap 4 [duplicate]
(20 answers)
Closed 2 years ago.
I can't seem to get my content to vertically and horizontally center in the body of the page itself in Bootstrap 4. I've used the documentation and multiple answers throughout StackOverflow with those with the same problem to no avail. I'm unsure why this won't work. Help and explanations are appreciated.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<div class="container-fluid h-100">
<div class="row h-100 justify-content-center align-items-center">
<div class="col-sm-12">
<h1>This is the test</h1>
Let's get started
</div>
</div>
</div>

Hope fully it will help to you easily
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Align Center Examples</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron text-center">
<h1>Working In center</h1>
<p>Well, Hope your Issue is Solved..</p>
</div>
</body>
</html>

Related

how to vertically center the content of a table with bootstrap [duplicate]

This question already has answers here:
Vertical Align Center in Bootstrap 4 [duplicate]
(20 answers)
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 2 years ago.
I want to vertically center a table using just bootstrap, but I can't. I have managed to align it horizontally but vertically I don't know how. This is the code I have:
<html>
<head>
<meta charset="UTF-8">
<title></title>
<LINK REL=StyleSheet HREF="css/bootstrap.css" TYPE="text/css">
<script src="js/jquery-3.5.1.slim.min.js" type="text/javascript"></script>
<script src="js/popper.min.js" type="text/javascript"></script>
<script src="js/utilidades.js" type="text/javascript"></script>
</head>
<body>
<div class="container d-flex flex-row justify-content-center alig-items-center">
<table border="1">
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
</table>
</div>
</body>
</html>

Doctype bootstrap vertical alignment [duplicate]

This question already has answers here:
Percentage Height HTML 5/CSS
(7 answers)
Why does height 100% work when DOCTYPE is removed?
(5 answers)
Closed 3 years ago.
I've downloaded bootstrap 4.3.1 and for the life of me I can't get vertical alignment to work under any circumstance if I have a <!DOCTYPE html> tag at the head of the html.
EDIT: With the body tag, results are the same.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="stylesheets/bootstrap.min.css" type="text/css">
</head>
<body>
<div class="container">
<div class="row h-100 justify-content-center align-items-center">
<div class="mx-auto col-sm-6" style="border: 2px solid red">
<h3 class="text-center">Heading3</h3>
<h4 class="text-center">Heading4</h4>
</div>
</div>
</div>
</body>
</html>
This divs are still stuck to the top of the screen unless I comment out the doctype. I have tried adding a custom css with body{height:100%} and body{min-height:100%} and no matter what, the doctype breaks vertical alignment. This happens in both Chrome and Safari. Any ideas?

Not working vertically centering bootstrap 4 [duplicate]

This question already has answers here:
Vertical Align Center in Bootstrap 4 [duplicate]
(20 answers)
Closed 5 years ago.
I want to center vertically text on page, i found the way to do that and rewrite -on codesnippet it's working, but not for me. Here is my code:
<html lang="pl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="./css/bootstrap.min.css">
<title>Strona w przebudowie</title>
</head>
<body>
<div class="row h-100">
<div class="col-sm-12 my-auto">
<h1 class="display-4">STRONA W PRZEBUDOWIE</h1>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
</body>
It is recommended to use Bootstrap 4 classes (instead of css hacks) for simple tasks of this nature because css hacks have the tendency to require even more css hacks down the road to fix the problems caused by the original css hacks.
A clean solution using Bootstrap 4 classes for vertical centering would be to use the align-items-center class on the row. However, you'll also need to give that row some height if you don't have much content in that row. To achieve that, you add style="height: 100vh" to the row which gives it 100% viewport height.
Finally, if you want to center the text horizontally also, you can use the text-center class on the column.
Here's the complete code snippet (click the "run code snippet" button below and expand to full screen):
<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-fluid">
<div class="row align-items-center" style="height: 100vh">
<div class="col-sm-12 text-center">
<h1 class="display-4">STRONA W PRZEBUDOWIE</h1>
</div>
</div>
</div>
Try This:
.col-sm-12.my-auto {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.col-sm-12.my-auto {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row h-100">
<div class="col-sm-12 my-auto">
<h1 class="display-4">STRONA W PRZEBUDOWIE</h1>
</div>
</div>

how to make two divs next to each other [duplicate]

This question already has answers here:
How to place two divs next to each other? [duplicate]
(13 answers)
Closed 5 years ago.
unfortunately i dont know how to make these divs(Boxes) next to each other like the picture and put the images of the cars like the image , can anyone please help me
if there is a way with tables or divs please help me to do it
here is the image
.block1{
background: red;
height: 150px;
padding-top: 30%;
}
.block2{
background: green;
height: 150px;
padding-top: 30%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-xs-12 text-center">
<div class="col-xs-6">
<div class="block1">
text
</div>
</div>
<div class="col-xs-6">
<div class="block2">
text
</div>
</div>
</div>
you can use float:left for your 2 divs inside a parent div
Try this html+bootstrap will work fine for mobile views :
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<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">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4">
Image 1
</div>
<div class="col-sm-4">
Image 2
</div>
<div class="col-sm-4">
Image 3
</div>
</div>
</div>
</body>
</html>

Vertical and Horizontal Alignment in fullscreen with bootstrap 3 [duplicate]

This question already has answers here:
How to center an element horizontally and vertically
(27 answers)
Closed 8 years ago.
I'm beginner in this world, and have some tricks I still need to learn, I'm playing in this design and the most thing I've been crushed is the align. I'm trying to make this align vertically and horizontally in a full screen style. I've tried some different things but it always break in some point.
I'm using latest Bootstrap.
The base is the following one:
http://i.stack.imgur.com/RUL9K.png
Thanks for your time.
You can try it by this code below:
<!DOCTYPE html>
<html>
<head>
<title>Centering</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script>
jQuery(document).ready(function(){
window_height=jQuery(window).height();
my_div_height=jQuery(".col-centered").height();
center_value=(window_height-my_div_height)/2;
jQuery(".col-centered").css('margin-top',center_value);
});
// script for responsive;
jQuery(window).resize(function(){
window_height=jQuery(window).height();
my_div_height=jQuery(".col-centered").height();
center_value=(window_height-my_div_height)/2;
jQuery(".col-centered").css('margin-top',center_value);
});
</script>
<style type="text/css">
.col-centered {
margin:auto;
float: none;
text-align:center;
}
</style>
</head>
<body>
<section class="custom_name">
<div class="container-fluid">
<div class="row">
<div class="col-lg-10 col-centered">
fsadfljsd
</div>
</div>
</div>
</section>
</body>
</html>
you can control horizontal alignment by creating a div class="row" then put need space divs with class col-md-*
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-md-8">col-md-8.. This will occupy 8/12th space. but will occupy full width in small screens.</div>
<div class="col-md-4">You can also add more colomuns. this one is 4/12th space.</div>
</div>
<hr>
<div class="row">
<div class="col-md-4 col-md-offset-3">if you add some offset to beginning you can use .col-md-offset-*. here there will be 3/12th space offset. again in small screen it will be full width</div>
</div>