Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS absolute position where top left of div is at the top right of the parent [closed]

Tags:

html

css

I want to absolute position a div such that the top left corner of the div is attached to top right corner of the parent div (relative positioned).

Do you have any solutions how to do that ?

Here is a fiddle to start

like image 410
Ashwin Avatar asked Jul 11 '12 13:07

Ashwin


People also ask

How do you position an absolute element in a div?

position : absolute Inside Other Positioned ElementsThe inner div element has position set to absolute and top to 0px and right to 0px . This places the inner div at the top right corner inside its parent element (because the parent element has position: relative set).

Is absolute position relative to parent?

Absolute However, an absolutely positioned element is relative to its parent. An element with position: absolute is removed from the normal document flow. It is positioned automatically to the starting point (top-left corner) of its parent element.

How do you position an element to the left in CSS?

If position: absolute; or position: fixed; - the left property sets the left edge of an element to a unit to the left of the left edge of its nearest positioned ancestor. If position: relative; - the left property sets the left edge of an element to a unit to the left/right of its normal position.

How do you position an element on top of another element?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).


2 Answers

I think you want something like this

http://jsfiddle.net/kdcmq/

<div id = "parent">
     <div id = "child"></div>
</div>


#parent {
    position: relative;
    width: 500px;
    height: 500px;
    background: red;
    display: block; /* fix for opera and ff */
}

#child {
    position: absolute;
    width: 100px;
    height: 100px;
    background: blue;
    top: 0;
    left: 100%; /* this line of code will sort things out for you :) */
}
like image 159
madeye Avatar answered Sep 29 '22 11:09

madeye


Simple as this?

http://jsfiddle.net/ZeSF8/2/

CSS:

div {border:1px solid #000}
.p {
    position:relative;
    width:100px; /*width will be unknown*/
    height:80px;
    background:#999;
}

.c {
    position:absolute;
    width:40px;
    height:30px;
    background:red;
    top:0;
    left:100%;
}

​ HTML:

<div class="p">
    <div class="c"></div>
</div>​
like image 23
silentw Avatar answered Sep 29 '22 10:09

silentw