Copy link to clipboard
Copied
I know how to center an image with bootstrap .center-block but how do I center an image on a whole page?

If you just want an image centered vertically and horizontally on a page all by itself you can use Flexbox. Flexbox is supported in 97.5% of modern browsers - I cant think of a reason not to use it. Its been a main-stream workflow for a couple of years now in the professional developer world, so use it unless you need to support IE8 or IE9, which many have already dumped a long time ago.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Flexbox - Center Vertically and Horizontally</title>
<s
...Copy link to clipboard
Copied
Which version of Bootstrap are you using -- 3.7 or the newest 4?
Copy link to clipboard
Copied
3.3.7
Copy link to clipboard
Copied
Please give show us the code - HTML and the relevant CSS
Copy link to clipboard
Copied
My index.html code at: Index - Pastebin.com just changed background color and added an image, so I have not touched css yet.
Copy link to clipboard
Copied
Although you could use Flexbox, my preference goes out to a table cell because the latter is supported in ALL browsers. An example is
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
div.container {
height: 20em;
width: 800px;
display: table-cell;
vertical-align: middle;
background: yellow;
}
img {
display: block;
margin: auto;
}
</style>
</head>
<body>
<div class="container">
<img src="http://lorempixel.com/400/200" alt="">
</div>
</body>
</html>
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I just copy paste your code, into a blank document, place Dw in live view... and the image is centered.... but ... there is a but... if your screen resolution is wider than 800 ... necessarily this will block the width of the container and will cause a misaligned ...
same for the height ....
so in this case, and to fit the screen ... replace the container width and height CSS by
height: 100vw;
width: 100vw;
Copy link to clipboard
Copied
That worked but there is one problem...

Copy link to clipboard
Copied
you said that you was looking to center the image on the whole page ?... so it does it...no ? and AFAIK the page is sized by your browser window.. isn't it ?
Copy link to clipboard
Copied
If you just want an image centered vertically and horizontally on a page all by itself you can use Flexbox. Flexbox is supported in 97.5% of modern browsers - I cant think of a reason not to use it. Its been a main-stream workflow for a couple of years now in the professional developer world, so use it unless you need to support IE8 or IE9, which many have already dumped a long time ago.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Flexbox - Center Vertically and Horizontally</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow:hidden;
}
</style>
</head>
<body>
<img src="images/image.jpg" alt="">
</body>
</html>
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more