我打算在背景圖像上放置一些DIV,但似乎效果不好。當屏幕尺寸改變時,DIV的位置會改變。媒體查詢不是解決方案。任何幫助?具有背景圖像的DIV的絕對位置
HTML
<div class="div-bg" style="background-image:url('https://image.ibb.co/f1qio5/insights_indiamap.jpg')">
<div class="cities Delhi"></div>
<div class="cities Bangalore"></div>
</div>
CSS:
.div-bg {
height: 85vh;
min-height: 500px;
background-size: contain;
background-repeat: no-repeat;
background-position: 50% 50%;
position: relative;
}
.cities {
border: 1px solid red;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: red;
}
.cities.Delhi {
position: absolute;
top: 150px;
left: 175px;
}
.cities.Bangalore {
position: absolute;
top: 250px;
left: 275px;
}
.cities CSS左側位置應該是百分比。 –
這可能比它看起來更復雜一些,這取決於你希望如何擴展,檢查這個答案(第二部分有一個CSS版本):http://stackoverflow.com/a/36097410/2827823 – LGSon
這是更好爲您的位置使用%而不是px,因此它是有響應的。而這些點應該與img而不是'absolute'相對' –