Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css calc with center offset

Tags:

html

css

Here is what I am trying

I have an element in the center that i want to stay in the center. Now i want an element to hug the left side of this element.

so in reality where i want the left most position of the left div would be right:calc(50%-200px-(lefts width));

my problem is doing right:50%; does something but right:calc(50% +100px) does not.

How can i make it so the div with the left class is always hugging the guy in the center?

<div class="left"> hug this center element </div>
<div class="middle"> this stays in the middle</div>
like image 678
Frank Visaggio Avatar asked Aug 26 '14 01:08

Frank Visaggio


People also ask

Can I use Calc in CSS?

calc() The calc() CSS function lets you perform calculations when specifying CSS property values. It can be used anywhere a <length> , <frequency> , <angle> , <time> , <percentage> , <number> , or <integer> is allowed.

What is the CSS code for center alignment?

To just center the text inside an element, use text-align: center; This text is centered.

How do you center an object in CSS?

Like last time, you must know the width and height of the element you want to center. Set the position property of the parent element to relative . Then set the child's position property to absolute , top to 50% , and left to 50% . This just centers the top left corner of the child element vertically and horizontally.


1 Answers

left: 50%; //->  align center
margin-left: -30px;  //-> your element width / 2 when element = 60px
like image 87
Abdo-Host Avatar answered Oct 20 '22 02:10

Abdo-Host