Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS Issue on React project

I’m starting to play with CSS and I’m struggling to center my "tasks". To debug I used a colored border and it’s centered, but the elements aren’t.

.App {
  display: block;
  text-align: center;
  align-items: center;
}

.done {
  color: red;
}

.task {
  text-align: center;
  align-items: center;
  display: flex;
  margin: auto;
  width: 50%;
  border: 3px solid green;
  padding: 10px;
}

Here is where the CSS is targetting:

import React, { Component } from "react";

class Task extends Component {

    render() {
        return (
            <div className={`task ${this.getClass()}`}>
                <div>{this.props.task.text}</div>

                <button className="task-element" onClick={() => this.props.onDone(this.props.task.id)}>
                    <span className="material-symbols-outlined">check_box</span>
                </button>

                <button className="task-element" onClick={() => this.props.onDelete(this.props.task.id)}>
                    <span className="material-symbols-outlined">
                        delete
                    </span>
                </button>
            </div>
        );
    }

    getClass() {
        return this.props.task.isDone ? 'done' : 'notDone';
    }
}

export default Task;

Here is the Output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Tryed to center elements and can’t.

>Solution :

You need to use the justify-content property to center the elements inside the flexbox

Try this

.task {
  align-items: center;
  justify-content: center;
  display: flex;
  margin: auto;
  width: 50%;
  border: 3px solid green;
  padding: 10px;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading