This question already has an answer here:
- How to horizontally center a <div>? 93 answers
I'm trying to horizontally center a <div>
block element on a page and have it set to a minimum width. What is the simplest way to do this? I want the <div>
element to be inline with rest of my page. I'll try to draw an example:
page text page text page text page text
page text page text page text page text
-------
| div |
-------
page text page text page text page text
page text page text page text page text
as ck has said, min-width is not supported by all browsers
You should use
position: relative
andtext-align: center
on the parent element and thendisplay: inline-block
on the child element you want to center. This is a simple CSS design pattern that will work across all major browsers. Here is an example below or check out the CodePen Example.Here I add proper answer
You can use this snippet code and customize. Here I use 2 child block.This should show center of the page. You can use one or multiple blocks.
JsFiddle
Add this class to your css file it will work perfectly steps to do:
1) create this first
2) add this to your css
you can use
margin: 0 auto
on your css instead ofmargin-left: auto; margin-right: auto;