您好,我想使用帶有影像的 boostrap(在我的 rails 應用程式中)Heroes 并使用它我需要使用 img 而不是 image_tag 但找不到我的影像。這里的代碼
<div class="px-4 pt-5 my-5 text-center border-bottom">
<h1 class="display-4 fw-bold">Centered screenshot</h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">Quickly design and customize responsive mobile-first sites with Bootstrap, the world’s most popular front-end open source toolkit, featuring Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful JavaScript plugins.</p>
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center mb-5">
<button type="button" class="btn btn-primary btn-lg px-4 me-sm-3">Primary button</button>
<button type="button" class="btn btn-outline-secondary btn-lg px-4">Secondary</button>
</div>
</div>
<div class="overflow-hidden" style="max-height: 30vh;">
<div class="container px-5">
<img src="/images/test2.png" class="img-fluid border rounded-3 shadow-lg mb-4" alt="Example image" width="700" height="500" loading="lazy">
</div>
</div>
</div>
我也測驗過 src="test2.png" , "/test2.png" 等...
image_tag 的問題我無法添加寬度、高度或加載引數。
uj5u.com熱心網友回復:
您可以使用image_path:
<img src="<%= image_path('test2.png') %>" class="img-fluid border rounded-3 shadow-lg mb-4" alt="Example image" width="700" height="500" loading="lazy">
請注意,您還可以使用image_tag和指定任何引數,包括寬度、高度、樣式、類...參見https://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag中的示例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/498045.html
