Center card vertically on background using Bootstrap

bootstrap cards
bootstrap 4 center div vertically and horizontally
bootstrap 4 vertical center div
bootstrap 4 card-body vertical center
bootstrap 4 center p vertically
bootstrap center card on page
bootstrap center card in middle
bootstrap 3 vertical-align

Just to make it clear before flagging as repost, all this doesn't work : How to center cards in bootstrap 4? How to align an image dead center with bootstrap Centering the image in Bootstrap How can I center an image in Bootstrap? How do I center an image in Bootstrap? How to align a <div> to the middle (horizontally/width) of the page How to horizontally center a <div>?

Having said that, my issue is simple, I have two divs, the background div and the card div from bootstrap. mx-auto will center vertically just fine, however impossible to unfix from the top the card. So that I also have space above and below the card. I've tried all m and p classes. As well as custom classes. Could someone help me please. I would like my card to be in the middle of the screen.

<div class="bg">
<div class="card card-design success-design mx-auto">
<div class="card-body">

Now it looks like this:

ooooxxxoooo
ooooxxxoooo
ooooooooooo
ooooooooooo

I would like :

ooooooooooo
ooooxxxoooo
ooooxxxoooo
ooooooooooo

try this:

body, html {
  height: 100%;
}

h3, h4, p, a, label {
        color: #001f3f;
}

.bg {
  /* The image used */
  background-image: url('exemple.png');

  /* Full height */
  height: 100%;

  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  /* i added following code */
  display:flex;
  justify-content:center;
  align-items:center;
}

.card-design {
        background-color: rgba(245, 245, 245, 0.7);
        width: 23rem;
        font-family: 'Roboto', sans-serif;
        font-weight: 300;
        border-radius: 0 !important;
}

.success-design {
        background-color: rgba(245, 245, 245, 0.8);
}

.nbr-apt {
        font-size: 220%;
        font-weight: 100;
}

.rdv {
        font-size: 160%;
}

.num {
        font-weight: bold;
<body>
        <div class="bg">
                <div class="card card-design success-design mx-auto">
                        <div class="card-body">
                        <h3 class="card-title"> bla bla bla</h3>
                        <h4 class="card-subtitle mb-2 text-muted"> bla bla bla</h4>
                        <h4 class="card-subtitle mb-2 text-muted"> bla bla blam</h4>
                        <br>
                        <br>
                        <p class="card-text nbr-apt">Merci bla bla bla</p>
                        </div>
                </div>
        </div>
  </body>

Bootstrap 4 Vertical Center - WDstack, How do I make my Div center vertically and horizontally in bootstrap? 1 — Vertical Center Using Auto Margins One way to vertically center is to use my-auto. This will center the element within it’s flexbox container (The Bootstrap 4.row is display:flex). For example,

You might need to use some CSS to get the body to stretch to full height, so you can center the card, this is an example using flexbox

html, body {
	height: 100%;
}

body {
	margin: 0;
	display: flex;
	align-items: center;
	justify-content: center;
}

.card {
	padding: 1rem;
	border: 1px solid;
}
<div class="card">I am a card</div>

bootstrap center div vertically and horizontally, How to Vertically Center Elements with Bootstrap. <section class="section mt-5"> <div class="container"> <div class="row"> <div class="col-md-6"> <div> <img alt="Web Studio" class="img-fluid" src="https://raw.githubusercontent.com/solodev/vertically-centering/master/images/vc-img-1.jpg" /> </div> </div> Vertical align in Bootstrap 4 will be dealt with in this article. Vertically centering objects in web design come with its own complications. Well, you can vertically center objects in a simple manner with the help of default Bootstrap and simple HTML.

If you're using Bootstrap 4 then you should utilize its utility classes.

Just add d-flex justify-content-center align-items-center classes to the root div and its content will be centered horizontally and vertically:

.bg {
  background-color: #fff0f0;
  width: 300px;
  height: 300px;
}

.card {
  width: 50%;
  height: 50%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="bg d-flex justify-content-center align-items-center">
  <div class="card">
    <div class="card-header">My card</div>
    <div class="card-body">Some text</div>
  </div>
</div>

How to Align Text Vertically Center in a DIV Using CSS, This demo shows examples of vertical align within a full height container, vertical <h5 class="text-muted">Vertical center using flexbox (align-self-center)..</h5> background: #eee; Vertical and horizontal center using auto-margins.. Card​  Bootstrap Image Align Center Example. You can use the following method to align center the image. Method 1 : Image align center Using the text-center Class. Using the text-center class you can align center the images. Here is an example –

How to Vertically Center Elements with Bootstrap, Quickly jumpstart your next project with this Bootstrap CSS compatible code samples. <h5 class="text-center">Use Vertical align for inline elements</h5> <​div  Use .card-title to add card titles to any heading element. The .card-text class is used to remove bottom margins for a <p> element if it is the last child (or the only one) inside .card-body . The .card-link class adds a blue color to any link, and a hover effect.

Cards · Bootstrap, Centering an HTML element horizontally with CSS, be it a “div” or a and align them in the center, vertically and horizontally, using Bootstrap 4 Example 3: Align a “Form” in the Center of the Page, Full Screen, Image Background Free Buttons · Free Cards · Free Fonts · Free Icons · Free WordPress  Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. w3schools .com THE WORLD'S LARGEST WEB DEVELOPER SITE

Bootstrap 4 Vertical Center on Codeply, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  Option 3 – Bootstrap Width Utility In this example, I am using Bootstrap’s width utility class of .w-50 to make the div 50% wide all the time. Then I added a utility class of .mx-auto that sets the margin left and right to auto centering it horizontally inside the .row container.

Comments
  • You "images" show that you want to center it vertically, but you're talking about "horizontally".
  • well this is the limit of language, I thought about it, and it seems that both can be true at the same time
  • with 3 line code. i added in .bg { } i showed there.
  • Thanks, this made my background image stop being diplayed beyond the card. However the card is still attached to the top.
  • could you provide a code example? maybe codepen. It would help better understand the issue
  • here is a codepen but the generated display is false of course codepen.io/ilanoh/pen/rodvVM