str.Append("<div class=\"rect\" style=\"top:" + (rectangles.ElementAt(i).Y + 50).ToString() + "px;left:" + (rectangles.ElementAt(i).X + 50).ToString() + "px;width:" + (rectangles.ElementAt(i).Width - 1).ToString() + "px;height:" + (rectangles.ElementAt(i).Height - 1).ToString() + "px;position:absolute;\"</div>");
I am creating this div and more divs that has been positioned absolute and then send the created html to another div(container). So that it creates a map the image is attached
You can enclose your dynamic
<div>
inside a parent<div>
wide and tall 0 pixels and absolutely positioned at the center of the page withleft: 50%; top: 50%;
CSS:
HTML with static dimensions:
HTML with dynamic dimensions:
To positionate your dynamic
<div>
you can use jQuery'scss()
function like this:And here is a demo for you