Jump to content
php.lv forumi

absouluted div centring


ziedinjsh

Recommended Posts

Sveiki!

 

Man ir problēma ar tādu lietu:

 

CSS:

.top{
background-color:#fff000;
width:100%;
height:100px;
}

.center{
border:1px solid #ff0000;
width:800px;
height:100%;
position:absolute;
z-index:1;
top:0;
margin-left:auto;
margin-right:auto;

}

.bottom{
background-color:#fff000;
width:100%;
height:100px;
position:fixed;
bottom:0px;
}

 

Vajag lai div ar clasi center atrodas pa vidu, bet ja ir:

margin-left:auto;
margin-right:auto;

VAI

margin:0 auto;

VAI

left:50%;
right:50%;

 

nevienā no variantiem div ar klasi center nenostājas pa vidu, kapēc tā? kā lai nocentrē?

 

Paldies jau iepriekš!

Link to comment
Share on other sites

absolūti pozicionētus elementus centrē tā:

 

.center {
 /* <CENTRĒ VERTIKĀLI> */
 height:200px;
 top:50%;
 margin-top:-100px; /* - (garums / 2) px */
 /* </CENTRĒ VERTIKĀLI> */

 /* <CENTRĒ HORIZONTĀLI> */
 width:200px;
 left:50%;
 margin-left:-100px; /* - (platums / 2) px */
 /* </CENTRĒ HORIZONTĀLI> */
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...