回答編集履歴

1

調整

2022/08/09 00:53

投稿

yambejp
yambejp

スコア114896

test CHANGED
@@ -1 +1,28 @@
1
1
  PHP側の処理、おなじIDで複数のimgを吐き出しているので破綻しています
2
+
3
+ # sample
4
+ ```javascript
5
+ <style>
6
+ .js-autoHeightTarget{
7
+ background-Color:gray;
8
+ }
9
+ </style>
10
+ <script>
11
+ window.addEventListener('DOMContentLoaded', ()=>{
12
+ document.querySelectorAll('.js-autoHeightBase').forEach(x=>{
13
+ const sib=x.nextElementSibling;
14
+ sib.style.height=x.height+"px";
15
+ sib.style.width=x.width+"px";
16
+ });
17
+ });
18
+ </script>
19
+ <div>
20
+ <img class="js-autoHeightBase" src="https://placehold.jp/ff0000/00000/150x100.png?text=1">
21
+ <div class="js-autoHeightTarget"></div>
22
+ </div>
23
+
24
+ <div>
25
+ <img class="js-autoHeightBase" src="https://placehold.jp/00ff00/00000/80x120.png?text=2">
26
+ <div class="js-autoHeightTarget"></div>
27
+ </div>
28
+ ```