Best way to center a div on a page vertically and horizontally

0 votes
What is the best approach to vertically and horizontally centre a div element on a page?

What is the ideal approach to centre on the vertical axis as well? I know margin-left: auto; margin-right: auto; will centre on the horizontal.
Jun 23 in CSS by Edureka
• 8,060 points
7 views

1 answer to this question.

0 votes

The legitimate way to do that irrespective of size of the div for any browser size is :

   div{
    margin:auto;
    height: 200px;
    width: 200px;
    position:fixed;
    top:0;
    bottom:0;
    left:0;
    right:0;
    background:red;
   }
answered 2 days ago by Edureka
• 9,540 points

Related Questions In CSS

0 votes
1 answer
0 votes
1 answer

I want to create a small square colour filled box in HTML & CSS. And most important - I want to write one line after the box

Try using the square html entity: <div style="color:blue">&a ...READ MORE

answered 2 days ago in CSS by Edureka
• 9,540 points
4 views
0 votes
1 answer

How to convert a web page(html,css,js) into android app?

I used Phonegap a lot for this, ...READ MORE

answered 2 days ago in CSS by Edureka
• 9,540 points
10 views
0 votes
0 answers

How to make a back-to-top button using CSS and HTML only?

I want to scroll down and up ...READ MORE

18 hours ago in CSS by Edureka
• 8,060 points
5 views
0 votes
0 answers

How can I vertically center a div element for all browsers using CSS?

I want to center a div vertically with CSS. ...READ MORE

Jun 22 in CSS by Edureka
• 8,060 points
11 views
0 votes
1 answer

Set cellpadding and cellspacing in CSS?

For controlling "cellpadding" in CSS, you can ...READ MORE

answered Jun 10 in CSS by Edureka
• 9,540 points
9 views
0 votes
0 answers

Set cellpadding and cellspacing in CSS?

In an HTML table, the cellpadding and ...READ MORE

Jun 8 in HTML by Ashwini
• 200 points
11 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
4,482 views
0 votes
1 answer

Is there any way to colorize a white PNG image with CSS only?

Filters can be used with -webkit-filter and ...READ MORE

answered May 27 in CSS by Edureka
• 9,540 points
27 views
0 votes
1 answer

What is the proper way to display a logo with CSS?

An <img> element is the proper way ...READ MORE

answered Jun 10 in CSS by Edureka
• 9,540 points
18 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP