I am trying to use Bootstrap to quickly whip up a small internal site and I'm having some issues with a specific layout on it's home page.
I have two rows and the first row is filled with link anchors dressed up as buttons. I want them all to be the same width and height, word wrap their contents and have a strong 'title' text with summary text, all text vertically aligned to the middle of the button.
I've achieved fixed width buttons and word wrap but I can't work out where to go from here to get them all the same height and then, of course, vertically align that text to the middle. I'm sure that line break element isn't helping things either.
HTML
<div class="container">
<div class="row">
<div class="col-md-2">
<a href="#" class="btn btn-default btn-lg btn-fill" role="button">
<strong>Button A</strong><br/>
<span>Long Summary That's Annoyingly Long</span>
</a>
</div>
<div class="col-md-2">
<a href="#" class="btn btn-default btn-lg btn-fill" role="button">
<strong>Button B</strong><br>
<span>Very Long Summary</span>
</a>
</div>
</div>
</div>
CSS
.btn-fill {
width: 100%;
white-space: normal;
}
I have a Bootply example here
You could use .btn-toolbar with .btn-group-justified to make it easily (the rendering differs a little bit) :
<div class="container">
<div class="btn-toolbar" role="toolbar">
<div class="btn-group btn-group-lg btn-group-justified btn-group-fill-height">
<a href="#" class="btn btn-default" role="button">
<strong>Part A</strong><br>
<span>Summary</span>
</a>
<a href="#" class="btn btn-default" role="button">
<strong>Part B</strong><br>
<span>Very Long Summary</span>
</a>
<a href="#" class="btn btn-default" role="button">
<strong>Part D</strong><br>
<span>Summary</span>
</a>
<a href="#" class="btn btn-default" role="button">
<strong>Part E</strong><br>
<span>Long Summary That's Annoyingly Long</span>
</a>
<a href="#" class="btn btn-default" role="button">
<strong>Part F</strong><br>
<span>Summary</span>
</a>
<a href="#" class="btn btn-default" role="button">
<strong>Part G</strong><br>
<span>Very Long Summary</span>
</a>
</div>
</div>
</div>
.btn-group-fill-height .btn {
white-space: normal;
}
Bootply
Why not add "text-center" to the anchor class and do something like:
.btn {
height: 170px;
}
For the height problem you're running into. That's an arbitrary number I picked but it worked when I punched it into your example.
Hope that helps.
Related
I have 3 divs, I want to align "div2" to the center of the page and "div3" at the end while being in the same row.
I've been trying some things like the "d-flex justify-content-center" that I'm currently using or making "div1" a row and giving "div3" the class "ml-auto" but then I don't know how to align "div1" to the center.
I'm using Bootstrap 5.
My actual result
<div class="text-center mt-2" id="div1">
<div class="d-flex justify-content-center" id="div2">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div class="d-flex justify-content-end" id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
One way is to use nested flexbox items. For this you'll need an empty spacer for the left, and each child item needs flex: 1:
.flex1 {
flex: 1;
}
<div class="text-center mt-2 d-flex w-100" id="div1">
<div class="d-flex flex1"><!--spacer --></div>
<div class="d-flex flex1 justify-content-center" id="div2">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div class="d-flex flex1 justify-content-end" id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
dead center using flexbox nesting
Another way is to use absolute position:
<div class="text-center mt-2 d-flex justify-content-center" id="div1">
<div class="d-flex" id="div2">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div class="ms-auto position-absolute end-0" id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
dead center using absolute position
Read more: aligning flexbox items is explained here
This solution should help you:
div2 is in the center of the row
div3 is at the end of the row
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex justify-content-end" id="div1">
<div id="div2" class="position-absolute" style="left:50%;width:100px;margin-left:-50px">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
I need your help for an issue I want to create some button with the same size (no matter of the text) and add the arrow icon on the right corner of the button.
But the arrow is not align with the other button because the number of caracters of the text.
I am using bootstrap here is the code:
<div class="col-md-6">
<div class="item" style="text-align: center">
<a class="btn btn-programs" style="width:230px" href="#">My 1st button with longer text<span class="btn-label"><i class="glyphicon glyphicon-chevron-right"></i></span></a>
</div>
</p>
<div class="item" style="text-align: center">
<a class="btn btn-programs" style="width:230px" href="#">My 2nd Button <span class="btn-label"><i class="glyphicon glyphicon-chevron-right"></i></span></a>
</div>
</p>
</div>
</div>
use the class
btn-block
<a class="btn btn-programs btn-block" href="#">My 1st button<span class="btn-label btn-block"><i class="glyphicon glyphicon-chevron-right"></i></span></a>
Add following css to your page
.item a span.btn-label
{
float: right;
}
I'm trying to create a responsive splash page, but it's not responding, no matter how much I try to manipulate it. What I'm mostly trying to do is fit the image with no margin or padding. I want it similar to Adele's mobile site. Also, I'm not sure if the code is clean and I'm naming the classes correctly. I created a codepen so you can check it out there.
<div class="featurette">
<img class="featurette-image img-responsive pull-left center-block" src="http://www.placehold.it/400/F84065/000" alt="#">
<div class="purchase-album">
<div class="album">
<img class="img-responsive" src="http://www.placehold.it/200/fa8ca2" />
<div class="lead">available now:</div>
</div>
<div class="space">
</div>
<p class="lead text-center available "></p>
<a href="#" target="_blank">
<button type="button" class="btn btn-default btn-lg outline" type="submit">iTunes</button>
</a>
<a href="#" target="_blank">
<button class="btn btn-default btn-lg outline" type="submit">loudr</button>
</a>
</div>
</div>
<div class="enter">
<button type="button" class="btn btn-default btn-lg outline" type="submit">
enter
</button>
</div>
</div>
Adeles page is a background image with the content displayed on top.
You can achieve this in many ways.
Try using this and playing about with the CSS to get everything in the desired place.
codepen here example
<header>
<div class="overlay">
<div class="header-content">
<div class="header-content-inner">
<h1>Your image here</h1>
<p>buttons here etc</p>
</div>
</div>
</div>
Shrink the page to see the responsive-ness
Using bootstrap v3 the goal is to create a row of fixed width href buttons for navigation. The code, using nothing but bootstrap styled HTML, achieves this in JSFiddle using
.nav_btn
{
width: 82px !important;
margin-right: 5px;
}
<div class="col-md-10">
<div class="btn-toolbar">
<div class="btn-group">
<a href="#" class="btn btn-default nav_btn" disabled>
<span><strong>Portfolio</strong></span>
</a>
<a href="#" class="btn btn-primary nav_btn">
<span><strong>Quote</strong></span>
</a>
<a href="#" class="btn btn-success nav_btn">
<span><strong>BUY</strong></span>
</a>
<a href="#" class="btn btn-success nav_btn">
<span><strong>SELL</strong></span>
</a>
<a href="#" class="btn btn-info nav_btn">
<span><strong>History</strong></span>
</a>
</div>
</div>
</div>
http://jsfiddle.net/SBSgN/12/
The exact code shown, with custom .nav_btn styling as shown, displays the buttons... stacked vertically :( when inserted into HTML for an actual web page. The code is inside a container. No other div specifying a grid size (e.g. col-md-10) appears before the code in question.
What am I missing.
I use Bootstrap 3 and the grid system. I have following HTML to display a sort of navigation.
The problem is my button group cannot be centered. I already tried the built in class "center-block" and different CSS approaches, but failed.
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="btn-group btn-group-lg">
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
</div>
</div>
</div>
</div>
<p class="text-center">Center aligned text.</p>
This will align contents in Bootstrap.
Taken directly from the bootstrap documentation.
You can center the button group div by applying
display:inline-block
Then applying to the parent div
text-align:center
Example here: http://jsfiddle.net/u7g3p/
You can assign text-akign: center; to the class .btn-group
DEMO http://jsfiddle.net/D2RLR/6159/
You can add a class 'text-center' which is bootstrap default class to define text-align:center,
But 'btn-group' class in bootstrap is defined as display:inline-block by default, so width of this div wont be 100% to make your inner links center align.
How to fix -
DOM changes, add class text-center to this div- <div class="btn-group btn-group-lg text-center">
CSS changes -
.btn-group{
width:100% (or) display:block;
}
Just add 'text-center' class to the 'btn-group' parent.
<div class="col-xs-12 text-center">
<div class="btn-group btn-group-lg">
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
</div>
</div>
Alternatively you can add tag before and after the div
<center>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="btn-group btn-group-lg">
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
<a class="btn btn-default"><span class="glyphicon glyphicon-shopping-cart"></span></a>
</div>
</div>
</div>
</div>
</center>
Here's a modified link :http://jsfiddle.net/sunilkjt/4bq1f320/
Thanks