英文:
Bootstrap 5 carousel carousel-caption text overlapped when I use JavaScript to append html content to the <div class="carousel-inner">
问题
I was able to get the Bootstrap 5 carousel with carousel-caption working in a static pages with multiple <div class "item"> Here is the page with static contents and it works.
<div class="carousel-inner">
<div class="item active">
<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" alt="Los Angeles" style="width:100%;">
<div class="carousel-caption">
<h3>CAPTION 1123</h3>
<p>LA is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" alt="Chicago" style="width:100%;">
<div class="carousel-caption">
<h3>CAPTION 235</h3>
<p>OC is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" alt="Chicago" style="width:100%;">
<div class="carousel-caption">
<h3>CAPTION 555</h3>
<p>SD is always so much fun!</p>
</div>
</div>
</div>
But if If I replace the page with this
<div class="carousel-inner">
</div>
Then I filled the div class="item" with dynamic contents using PHP fetching from a mysql database.
Then I used JavaScript to append all the div class="item" as follow :
const divBtag = index === 0 ? '<div class="carousel-item active">' : '<div class="carousel-item">';
//const divBtag = '<div class="carousel-item">';
var photoHtml =
divBtag +
'<img src="' + photo.photo_path + '" class="d-block"
style="width:100%" />' +
'</div>' +
'<div class="carousel-caption">' +
'<h5>' + photo.photo_description + '</h5>' +
'<p>' + photo.photo_datetime + '</p>' +
'</div>' +
'</div>';
$('.carousel-inner').append(photoHtml);
The "carousel-caption" text in "h3" tag will show overlapped with item 0 and item 1 and only the last item 2 work fine. and the text in "p" tag also show overlapped text with item 0 and item 1 only the last item 2 work fine. Is that a way to fix that?
英文:
I was able to get the Bootstrap 5 carousel with carousel-caption working in a static pages with multiple <div class "item"> Here is the page with static contents and it works.
<div class="carousel-inner">
<div class="item active">
<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" alt="Los Angeles" style="width:100%;">
<div class="carousel-caption">
<h3>CAPTION 1123</h3>
<p>LA is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" alt="Chicago" style="width:100%;">
<div class="carousel-caption">
<h3>CAPTION 235</h3>
<p>OC is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" alt="Chicago" style="width:100%;">
<div class="carousel-caption">
<h3>CAPTION 555</h3>
<p>SD is always so much fun!</p>
</div>
</div>
</div>
But if If I replace the page with this
<div class="carousel-inner">
</div>
Then I filled the div class="item" with dynamic contents using PHP fetching from a mysql database.
Then I used JavaScript to append all the div class="item" as follow :
const divBtag = index === 0 ? '<div class="carousel-item active">' : '<div class="carousel-item">';
//const divBtag = '<div class="carousel-item">';
var photoHtml =
divBtag +
'<img src="' + photo.photo_path + '" class="d-block"
style="width:100%" />' +
'</div>' +
'<div class="carousel-caption">' +
'<h5>' + photo.photo_description + '</h5>' +
'<p>' + photo.photo_datetime + '</p>' +
'</div>' +
'</div>';
$('.carousel-inner').append(photoHtml);
The "carousel-caption" text in "h3" tag will show overlapped with item 0 and item 1 and only the last item 2 work fine. and the text in "p" tag also show overlapped text with item 0 and item 1 only the last item 2 work fine. Is that a way to fix that ?
答案1
得分: 0
在以下HTML代码中,将
const divBtag = (index === 0) ? '<div class="carousel-item active">' : '<div class="carousel-item">';
const photoHtml =
divBtag +
'<img src="' + photo.photo_path + '" class="d-block" style="width:100%" />' +
'<div class="carousel-caption">' +
'<div>' +
'<h5>' + photo.photo_description + '</h5>' +
'<p>' + photo.photo_datetime + '</p>' +
'</div>' +
'</div>' +
'</div>';
$('.carousel-inner').append(photoHtml);
英文:
Add a div wrap around the "h5" and "p" tag as shown in the following html code resolve the overlapped text issue.
const divBtag = (index === 0) ? '<div class="carousel-item active">' : '<div class="carousel-item">';
const photoHtml =
divBtag +
'<img src="' + photo.photo_path + '" class="d-block" style="width:100%" />' +
'<div class="carousel-caption">' +
'<div>' +
'<h5>' + photo.photo_description + '</h5>' +
'<p>' + photo.photo_datetime + '</p>' +
'</div>' +
'</div>' +
'</div>';
$('.carousel-inner').append(photoHtml);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
- css
- html
- javascript
评论