Monday 6 November 2017

html - True Center Vertical and Horizontal CSS Div

itemprop="text">



How is it
possible to create a true center CSS div cross browser for example to use within a
holding page?



I have tried this 2007 css trick -
href="http://css-tricks.com/quick-css-trick-how-to-center-an-object-exactly-in-the-center/">How
To Center an Object Exactly In The Center
but as you can see
from my href="http://jsfiddle.net/P4RVD/">JSFiddle of
the code its not 100%
center.



HTML:




            class="center">

Text





CSS:



.center{

position: fixed;
top: 50%;

left: 50%;

margin-top: -50px;
margin-left: -100px;
border:5px solid
black;
}

class="post-text" itemprop="text">
class="normal">Answer



That
technique requires the element to have a fixed width and height. You are not setting the
width and height. Based on your border and margins, to center it, the width would need
to be 190 pixels and the height would need to be 90 pixels. Using
line-height and text-align in
combination with a fixed width and height makes the text and border centered.
Try
it.



CSS




.center{

position: fixed;
top: 50%;
left: 50%;
width:
190px;
height: 90px;
line-height: 90px;
text-align:
center;
margin-top: -50px;

margin-left:
-100px;
border:5px solid
black;
}


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...