Rumah > Soal Jawab > teks badan
P粉0546168672023-08-14 00:35:03
Letak sahaja position: relative
添加到您的#container
dalam pemilih. Ini akan meletakkan elemen kanak-kanak berbanding dengan elemen ini.
Jika perlu, anda juga boleh menambah overflow:hidden
untuk memotong kandungan di luar skop elemen ini. Walau bagaimanapun, jika anda tidak memerlukannya, padamkannya.
const image = document.getElementById("pic"); image.classList.add("rotate"); const clone = image.cloneNode(true); clone.classList.add("rotate-negative"); clone.classList.add("top-image"); clone.classList.add("shadow-lg"); document.getElementById("container").appendChild(clone);
img { transition: 0.5s; max-height: 600px; } .rotate{ transform: rotate(15deg); position: absolute; top: 0; left: 0; } .rotate-negative{ transform: rotate(-5deg); position: absolute; top: 0; left: 0; } .top-image:hover{ transform: rotate(0deg); transition: 0.5s; max-height: 620px; } #container{ margin-left: auto; margin-right: auto; height: 500px; width: 30%; background-color: black; /*added*/ position: relative; /*overflow:hidden;*/ }
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous"> <div id="container"> <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcToJI-yx2dCcsVf3fYDDRF908iRO_dlTsL9H32iWWIkT_1dYuimsdBUZKTIZgYC61z6Vik&usqp=CAU" id="pic"> </div>