I want the text of a div to be some lines bellow of the first line of the div if the length is little.
How can I set this text to have a distance form the first line of the div?
The check of the length of this text can be done with css and not with javascript?
I want this
<div>{little text is here}
{I want it here}
</div>
Now I use this (with mootools)
m= $('content_text').innerHTML;
if (m.length<400)
$('content_text').setStyle("text-align","center");
$('content_text').setStyle("margin-top","10em");
$('content_text').setStyle("margin-bottom","-10em");
padding is the one you look for, not margin, and for the bottom use positive values also.
em will not give you flexibility, neither %. Both are variable in calculations, but fixed in the value they take. So CSS has no straight up option, other then making your div display:table-cell; and use vertical alignment to center the content in the div.
Use padding since it’s related to the inside of div, while margin is related to the outside of div. Or a min-height value for the div.
If you are talking about vertically aligning text to the middle of a fixed height div then you can use the display table properties for IE8+ and other modern browsers.
To cater for IE6 and 7 makes it a little complicated.
My problem is that bellow this div is another div with a photo.
So I do not want this div to move as it done with positive padding-bottom or with no padding-bottom.I want just to move the text inside this div.
How can I set the other div not to move?
The problem was with my code at javascript and padding-bottom.
Also I use javascript to find the len of text.
Can I ignore the * at your css code and use javascript?
maybe with
if (navigator.appName=="Microsoft Internet Explorer" & if parseInt(navigator.appVersion)<7)
{
$('content_text').setStyle("position","relative");
$('content_text').setStyle("top","50%");
$('content_text').setStyle("zoom","zoom:1.0");
}
put in a CSS file those CSS declarations that are not “dynamic”, like “position:relative;”, “zoom:1.0”, “padding:0 15em”.
use JS to add a CSS style when needed, like for the necessary top offset, since the power with JS is that: to inspect, calculate and then assign LIVE, which you can’t do in CSS.
you don’t need “display:table-cell;” if going for relative positioning.