I’m not sure I understand your question, but from what I understand you want to keep yours form
always in the center of the screen no matter the resolution of the screen, and that it fits your content (my example is for a content of measurable size, I do not know if it meets you).
What my solution has more than its example is the following (follow the code comments):
left: 50%; /* metade da pagina */
top: 50%; /* metade da pagina */
width: 400px; /* utilize um tamanho que seja suficiente para seu conteúdo horizontal */
height: 260px; /* utilize um tamanho que seja suficiente para seu conteúdo vertical */
margin-left: -200px; /* utilize a metade do valor setado no width para trazer o elemento ao centro horizontal da tela */
margin-top: -130px; /* utilize a metade do valor setado no height para trazer o elemento ao centro vertical da tela */
In addition to the amendments I pointed out earlier the element should continue with the position: relative;
or absolute
if applicable.
Follows online example to help you understand the proposed solution.
For smaller screens like tablets and smartphones you can create media queries, adding a similar rule to that in your css
:
@media (max-width: 410px) {
form {
width: 260px;
height: 340px;
margin-left: -130px;
margin-top: -170px;
}
}
Accompany online example updated (decrease the screen to a width
less than 410px
, to test).
Example in Plunker, in case jsFiddle is having problems with cited by @brasofilo.
Hey, Zebra, it’s important to put the code here, the Fiddle is not functioning properly all day...
– brasofilo
@brasofilo, our thought it was my network that was in trouble. I sifted to save my example there. Hehe.
– Fernando Leal
I will put here, sorry, the time I was hosting was no problem, now I really noticed the error on the site.
– HiHello
@Zebra, check in Meta: I can only show a link to my website with problems? and also Questions only with Fiddle
– brasofilo