채택완료

갤러리 리스트 썸네일을 이미지가 아닌 배경이미지로 표현 부탁드립니다.

2021-02-15 (월) 07:46:30 5,042

안녕하세요. 고수님들

갤러리 리스트에서 썸네일을 이미지로 아래 코드로 불러오게 되어 있는데요.

Copy
$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true);
                        
                        if($thumb['src']) {
                            $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" >';
                            } else {
                            $img_content = '<i>이미지가 없습니다.</i>';
                            }
                        echo $img_content;

이 부분을 아래 처럼 해 보았는데 안되더라고요.

background-image:url(이미지) contatin  로 불러오고 싶습니다.

부탁드립니다.

Copy
$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], false, true);
                        
                        if($thumb['src']) {
                            $style=';background:url(\''.$thumb['src'].'\') no-repeat center center;background-size:contain;';
                            $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px;'.$style.'"></span>';
                            } else {
                            $img_content = '<i>이미지가 없습니다.</i>';
                            }
                        echo $img_content;

답변 3개 / 댓글 1개

채택된 답변
+20 포인트
2021-02-15 (월) 09:39:10

올려주신 소스는 정상적인 소스인데

$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], false, true);
                        
                        if($thumb['src']) {
                            $style=';background:url(\''.$thumb['src'].'\') no-repeat center center;background-size:contain;';
                            $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px;'.$style.'"></span>';
                            } else {
                            $img_content = '<i>이미지가 없습니다.</i>';
                            }
                        echo $img_content;

span 을 div로 바꿔보세요

네 . 이렇게 처리했습니다. 감사합니다.

Copy
$thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true);
                        
     $style=';background:url(\''.$thumb['src'].'\') no-repeat center center;background-size:contain;';
     $img_content = '<div style="margin:0 auto;;width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px;'.$style.'"></div>';
       } else {
      $img_content = '<i>이미지가 없습니다.</i>';
      }
      echo $img_content;

block 요소로 해야 width height가 적용되지 않을까요? 

<span> style에 display: block; 이나 display: inline-block; 

혹은  <span> 대신 <div>

답변에 대한 댓글 1개

감사합니다. 덕분에 처리했습니다. 즐거운 하루보내세요.

답변을 작성하려면 로그인이 필요합니다.