1 回答

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊
您的 CSS 設(shè)置position: absolute為該svg元素。與靜態(tài)定位的元素不同,絕對(duì)定位的元素不占用其容器所需的空間。top瀏覽器將它們放置在您用、left、right和指定的坐標(biāo)處bottom,無(wú)論它是在任何其他元素的下面還是上面。
從#seasonImage元素的角度來(lái)看,沒(méi)有任何東西占據(jù)其自身上方的空間。因此,瀏覽器將其放置在其容器的頂部,與絕對(duì)定位的 SVG 重疊。
如果我們注釋掉或刪除position: absolute;(及其相關(guān)屬性),瀏覽器會(huì)將圖像直接放置在 SVG 下方。
#svg {
/*position: absolute;
left: 0;
right: 0;*/
margin: auto;
/*z-index: -1;*/
display: block;
margin-bottom: 10px;
display: block;
}
#svgContainer {
display: block;
width: 90%;
margin: auto;
}
#seasonImage {
background-image: url('https://cataas.com/cat?26');
width: 120%;
margin-left: -30px;
height: auto;
background-repeat: no-repeat;
background-size: contain;
height: 200px;
display: block;
position: relative;
}
<div id="svgContainer">
<svg id="svg" viewBox="-10 -10 220 220" width="90%">
<text x="80" y="106" id="currentTemp" font-size="18" font-weight="bold" style="fill: #C9AC68">{{currentTemp}}°</text>
<circle class="background" cx="100" cy="100" r="35" stroke="#C9AC68" />
<circle class="background" cx="100" cy="100" r="55" stroke="#B25538" />
<circle class="background" cx="100" cy="100" r="75" stroke="#507282" />
<circle class="background" cx="100" cy="100" r="95" stroke="#7E8959" />
<circle id="line1" class="overlayLine" cx="100" cy="100" r="35" stroke="#C9AC68" stroke-dasharray="0, 3000" stroke-dashoffset="126" transform="rotate(-90,100,100)" />
<circle id="line2" class="overlayLine" cx="100" cy="100" r="55" stroke="#B25538" stroke-dasharray="0, 3000" stroke-dashoffset="188" transform="rotate(-90,100,100)" />
<circle id="line3" class="overlayLine" cx="100" cy="100" r="75" stroke="#507282" stroke-dasharray="0, 3000" stroke-dashoffset="251" transform="rotate(-90,100,100)" />
<circle id="line4" class="overlayLine" cx="100" cy="100" r="95" stroke="#7E8959" stroke-dasharray="0, 3000" stroke-dashoffset="314" transform="rotate(-90,100,100)" />
</svg>
</div>
<div id="seasonImage"></div>
- 1 回答
- 0 關(guān)注
- 109 瀏覽
添加回答
舉報(bào)