0

I am trying to build a simple card to display a button and a text.

I can't make the alignment proper. perhaps too much overload of css.

it looks like:

enter image description here

I just want the content centered vertically and horizontally with the text and the button below the text

here is the code:

import React from 'react';
import {Button} from 'react-bootstrap';
import './EmptyTile.css';

class EmptyTile extends React.Component {

    render() {
        return (
            <div className="empty-tile">
                <h1>{this.props.text}</h1>
                <Button bsPrefix="button-empty-tile" href={this.props.url}>Start</Button>
            </div>
        );
    }
}

export default EmptyTile;

and css


 .empty-tile {
    width: 240px;
    height: 360px;
    border-radius: 20px;
    box-shadow: 0px 8px 18px 0 rgba(0,0,0,0.14);
    align-items: center;
    text-align: center;
    justify-content: center ;
    display: flex;
}


.empty-tile h1 {
    font-family: Fredoka One;
    font-size: 18px;
    font-weight: normal;
    font-stretch: normal;
    font-style: normal;
    line-height: normal;
    letter-spacing: -0.44px;
    text-align: center;
    color: #cacaca;
    padding-left: 15px;
    padding-right: 15px;
}

.button-empty-tile {
    border-radius: 21px; 
    background-color: #f4f7f8; 
    border-color: #cacaca;
    font-family: Source Sans Pro;
    font-size: 16px;
    text-align: center;
    color: #cacaca;
    padding-top: 5px;
    padding-bottom: 7px;
    padding-left: 20px;
    padding-right: 20px;
}

Any idea ? the code is very simple

Alan M
  • 616
  • 5
  • 15
Seb
  • 2,929
  • 4
  • 30
  • 73

2 Answers2

3

Adding flex-direction: column to .empty-tite should solve the issue.

.empty-tile {
  width: 240px;
  height: 360px;
  border-radius: 20px;
  box-shadow: 0px 8px 18px 0 rgba(0,0,0,0.14);
  align-items: center;
  text-align: center;
  justify-content: center ;
  display: flex;
  flex-direction: column; // by default, flex-direction is row
}
...

Check out this Code Sandbox link, if this is what you are looking for.

himayan
  • 784
  • 3
  • 9
2

Add flex-direction: column to the container:

 .empty-tile {
    width: 240px;
    height: 360px;
    border-radius: 20px;
    box-shadow: 0px 8px 18px 0 rgba(0,0,0,0.14);
    align-items: center;
    text-align: center;
    justify-content: center ;
    display: flex;
    flex-direction: column;
}

Here a snippet:

 .empty-tile {
    width: 240px;
    height: 360px;
    border-radius: 20px;
    box-shadow: 0px 8px 18px 0 rgba(0,0,0,0.14);
    align-items: center;
    text-align: center;
    justify-content: center ;
    display: flex;
    flex-direction:column;
}


.empty-tile h1 {
    font-family: Fredoka One;
    font-size: 18px;
    font-weight: normal;
    font-stretch: normal;
    font-style: normal;
    line-height: normal;
    letter-spacing: -0.44px;
    text-align: center;
    color: #cacaca;
    padding-left: 15px;
    padding-right: 15px;
}

.button-empty-tile {
    border-radius: 21px; 
    background-color: #f4f7f8; 
    border-color: #cacaca;
    font-family: Source Sans Pro;
    font-size: 16px;
    text-align: center;
    color: #cacaca;
    padding-top: 5px;
    padding-bottom: 7px;
    padding-left: 20px;
    padding-right: 20px;
}
<div class="empty-tile">
<h1>I am an h1 tag!</h1>
<button class="button-empty-tile">And I am a button under it</button>
</div>
Raffobaffo
  • 2,806
  • 9
  • 22