Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How would one move an absolute position element through CSS ideally by its center instead of its top left corner?

I currently have a circular element that I am adjusting via absolute positioning. I would like to move it based off of the center of the circle so that I can align it with a line on the background. The size of the circle is dynamic, and so is the background. Trying to get the red circle aligned to where the indigo meets the grey.

//Heres the code

https://jsfiddle.net/4akwe208/4/

Image For Reference

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
701 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think this is what you are trying to do is to use CSS transforms property with the value translate.

#your-div-id {
    -ms-transform: translate(-50%, 50%); /* IE 9 */
    -webkit-transform: translate(-50%, 50%); /* Safari */
    transform: translate(-50%, 50%);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...