简体   繁体   中英

Positioning sticked (fixed) element relatively

How can I positionate a fixed element at the left side of the div with processing resize events?

Here's example: http://jsfiddle.net/yHErk/10/

Now on my screen resolution .skicked is right at the left side of .container . But if I'll simply resize the result window, it'll change. Is there a simple way to do that thing I want?

Thank you.

Currently your .sticked div has no relative parent to hold it so it is moving according to the re-size.

Add .sticked div inside the container div.

CSS

.container {
    width: 300px;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid;
    background: #dedede;
    padding: 10px; position:relative
}

.sticked {
    position: absolute;
    top: 100px;
    left: -50px;
    border: 1px solid;
    border-radius: 5px;
    padding: 10px;
    background: white;
}

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM