1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
所以根據(jù)你的解釋。
我border-radius為你的班級(jí)添加了一個(gè)img如下:
border-radius: 1.25rem 1.25rem 0 0;
然后我在你的文本類中添加了一個(gè)填充,使它更好,最后。替換您的span設(shè)置p元素如下:
.text p{
margin: 0 7px;
}
這樣 text 就遠(yuǎn)離了border-radius.
你需要添加到你的班級(jí).text { width: fit-content}
所以我們最終添加了js來(lái)調(diào)整border-bottom-left-radius當(dāng)文本寬度等于img寬度時(shí)。我們創(chuàng)建類以在寬度相等的情況下添加:
.border-bottom-left-radius{
border-bottom-left-radius: 0 !important;
}
正如 hatef 在評(píng)論中提到的那樣。重新加載窗口是動(dòng)態(tài)的,但不調(diào)整大小。為此,我從這個(gè)答案中的現(xiàn)有代碼中改編了代碼:使用 javascript 檢測(cè)何時(shí)更改 div 寬度
通過(guò)添加這個(gè) js 來(lái)檢測(cè) body 元素的變化(如果它會(huì)被調(diào)整大小):
displayWindowSize();
window.addEventListener("resize", displayWindowSize);
function displayWindowSize(){
const imgEl = document.getElementById('img');
const textEl = document.getElementById('text');
if(imgEl.offsetWidth <= textEl.offsetWidth){
imgEl.classList.add("custom-radius");
}
if(imgEl.offsetWidth > textEl.offsetWidth){
imgEl.classList.remove("custom-radius");
}
}
.image {
border-radius: 1.25rem 1.25rem 0 1.25rem;
display: block;
margin-left: auto;
width: 70%;
}
.text{
float: right;
background-color: rgb(230, 236, 240);
border-radius: 0 0 0 1.25rem;
margin-left: auto;
width:fit-content;
max-width: 70%;
padding: 5px 0;
}
.text span{
display:block;
padding-left: 20px;
padding-right: 5px;
}
.custom-radius {
border-bottom-left-radius: 0 !important;
}
<img id="img" class="image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a3/Miscanti_Lagoon_near_San_Pedro_de_Atacama_Chile_Luca_Galuzzi_2006.jpg/512px-Miscanti_Lagoon_near_San_Pedro_de_Atacama_Chile_Luca_Galuzzi_2006.jpg" />
<div id="text" class="text">
<span>This is the text This is a text this is a text</span>
</div>
添加回答
舉報(bào)