Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the right margin twice the size of the left margin

Tags:

html

css

I have a fixed-size inner div within a variable-width outer div.

#outer { width: 100%; }
#inner { width: 80px; }
<div id="outer">
  <div id="inner"></div>
</div>

I want the inner div to be placed inside outer div as follows:

[Npx of empty space][80px fixed-size inner div][2Npx of empty space]

where N is some number. As the window size changes, N will change, but the right will remain twice the size of the left. Is it possible to do with CSS?

like image 786
George Avatar asked Sep 01 '16 18:09

George


People also ask

What is the size of the left margin?

Required Margins: The top, bottom, and right margins are required to be 1 inch, but the left margin can either be 1 inch or 1.25 inches.

How do you set the top left and bottom right of a margin?

The syntax for the CSS margin property (with 2 values) is: margin: top_bottom left_right; When two values are provided, the first value will apply to the top and bottom of the element. The second value will apply to the left and right sides of the element.

Is left the same as margin-left?

Left is the position of your entire element, margin-left is the amount of your left margin. For example if your are not in a normal document flow, your left margin is not going to let anything occupy that space.


1 Answers

As an alternative to Mr Lister's positioning option we can use calc on the margins.

#outer {
  width: 100%;
}
#inner {
  width: 80px;
  height: 35px;
  background: rebeccapurple;
  margin-top: 1em;
  margin-left: calc((100% - 80px) / 3);
  margin-right: calc((100% - 80px) / (3 * 2));
}
<div id="outer">
  <div id="inner">
  </div>
</div>
like image 56
Paulie_D Avatar answered Sep 22 '22 20:09

Paulie_D