Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div margin-bottom of a proportion of its own height?

Tags:

For example, I have a div that has a height of 100px (I don't know the height, but let's suppose I did). I want to set the margin-bottom to a percent, so 25% would be 25px assuming the previous height. However, the percent seems to be of the document, not the element:

<div style="height:100px;margin-bottom:100%"></div> 

The margin should be 100px but it isn't, it is 100% of the height of the page.

The element is just a line of text that has no background, so using height:150% theoretically could also work.

like image 291
JCOC611 Avatar asked Feb 05 '11 21:02

JCOC611


People also ask

What is a margin-bottom?

The margin-bottom property is used to specify the width of the bottom area of the element's margin box. That is, it specifies the area of space required at the bottom of the element, outside any defined border. Every element on a web page is rectangular.

How do you lower the bottom margin?

Change or set page marginsOn the Page Layout tab, in the Page Setup group, click Margins. Click the margin type that you want. For the most common margin width, click Normal. Note: When you click the margin type that you want, your entire document automatically changes to the margin type that you have selected.

Does setting margin top and margin-bottom have an affect?

Top and bottom margins do not affect inline elements because inline elements flow with content on the page. You can set left and right margins/padding on an inline element but not top or bottom because it would disrupt the flow of content.

What is the value of bottom margin?

top margin is 10px. right and left margins are 5px. bottom margin is 15px.


1 Answers

How about a CSS3 solution:

div {            -webkit-transform: translateY(-50%);    -moz-transform: translateY(-50%); } 
like image 173
ShibbyUK Avatar answered Sep 30 '22 18:09

ShibbyUK