Мне трудно центрировать текст внутри кнопки Bootstrap. Вот что я пробовал
<div class = "d-grid gap-2 col-6 mx-auto">
<a class = "btn btn-primary d-flex align-items-center" type = "button" style = "height: 200px;margin-bottom: 150px;font-size: 3rem; text-align: center; font-weight: bold;" href = "all-listings.html"> Browse All Listings</a>
</div>
Результат показан на картинке:
Любой совет о том, как это исправить?
Добавьте style = "text-align: center;"
в контейнер div.
<div class = "d-grid gap-2 col-6 mx-auto" style = "text-align: center;">
<a class = "btn btn-primary d-flex align-items-center" type = "button" style = "height: 200px;margin-bottom: 150px;font-size: 3rem; text-align: center; font-weight: bold;" href = "all-listings.html"> Browse All Listings</a>
</div>
Вместо этого вы можете использовать кнопку, которая действует как ссылка.
<button class = "btn btn-primary"
style = "height: 200px; margin-bottom: 150px; font-size: 3rem; font-weight: bold;"
onclick = "window.location.href = 'all-listings.html';">
Browse All Listings
</button>
Кнопки Bootstrap уже имеют текст по центру по умолчанию, поэтому вы можете просто применить класс btn btn-primary
, и это должно сработать. Не нужно ничего добавлять, просто убедитесь, что вы не перезаписываете стили начальной загрузки своими собственными стилями.
Для получения дополнительной информации ознакомьтесь с документацией на веб-сайте bootstrap .
<a class = "btn btn-primary text-center" type = "button" style = "height: 200px;margin-bottom: 150px;font-size: 3rem; font-weight: bold;" href = "all-listings.html"> Browse All Listings</a>