Jump to content
  • 0

Текст в центре div'а (по горизонтали и вертикали).)


lolka84
 Share

Question

Привет :)


window.onload = function () {

var wheight = (window.innerHeight) ? window.innerHeight : ((document.all) ? document.body.offsetHeight : null);

document.getElementById("center_v").style.height = (document.getElementById("content").scrollHeight - 50)+"px";
document.getElementById("center_v").style.width = (document.getElementById("content").scrollWidth)+"px";
}


#content {
width:56%;
min-height:500px;
margin:0 0 0 0;
padding:50px 2% 0 2%;
float:left;
}
* + html #content {
width:55%;
}
#center_v {
width:100%;
height:100%;
min-height:500px;
display:table-cell;
vertical-align:middle;
}
#center_h {
width:100%;
height:auto;
text-align:center;
font-size:13px;
color:#888;
}


<div id="content">

<div id="center_v">

<div id="center_h">

Текст

</div>

</div>

</div>

Можно может это реализовать без участия js ? Как заставить display:table-cell; центрироваться по вертикали, если высота задана в процентах ?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Ничего не понятно...

js у вас ничего не центрирует. Да и css что-то противоречит замыслам.

Может тут display:inline-block проще использовать? Вобщем загляните сюда: "Верстка дивами. Выравнивание по вертикали."

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.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   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.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy