I have this html:
<div class="col-xs-12">
<div class="row">
<div class="col-xs-8">
<h2>Some big header</h2>
</div>
<div class="col-xs-4 select">
<select class="form-control">
<option>TMP</option>
</select>
</div>
</div>
<div class="row">some more text</div>
</div>
and I am getting this result:
There is margin property on tag h1 so there are some blank space above h1. There are no such space above select, so this elements are not centered.
"What you've tried?"
I've tried bad and monstrouse method. I know it can be used to center divs. But not in this case... I have added line-height and height properties to the select:
.select {
height: 80px;
line-height: 80px;
}
.form-control {
display: table-cell;
}
Yes, it worked, but it is not relative at all. What if on left column there will be h2 text, not h1?
jsFiddle example of "what you tried?"
Also, "what you've tried?" 2: I tried to use form-horizontal class. Look this:
And the code:
<div class="col-xs-12 form-horizontal">
<div class="row form-group">
<div class="col-xs-8">
<h2 class="control-label">Some big header</h2>
</div>
<div class="col-xs-4 ">
<select class="form-control">
<option>TMP</option>
</select>
</div>
</div>
</div>
Also, text in the left column is right aligned (as form label, obvious). I don't want this.
jsFiddle example of "what you tried?" 2
So the question is: how I can center both elements vertically? Highly prefer using bootstrap classes and approaches. Don't suggest methods, where you specifying height of div, margins or paddings: it is not relative at all.
To be able to use vertical alignment, I think you need to override the floating used by bootstrap classes, and use inline-block for the columns. It's not exactly a bootstrap approach, but I think it works and is responsive. There is one disadvantage that can be a bit annoying, is that you need to make sure there is no space between the divs...
<div class="col-xs-12">
<div class="row">
<div class="col-xs-8 vcenter-col">
<h2 class="control-label">Some big header</h2>
</div><!-- comment required to prevent line break...
--><div class="col-xs-4 vcenter-col">
<select class="form-control">
<option>TMP</option>
</select>
</div>
</div>
</div>
.vcenter-col {
display: inline-block;
vertical-align: middle;
float: none;
}
Jsfiddle
Did I understand correctly your question?
Try this CSS :
h2 {
margin: 0;
}
BootStrap does a lot off things in CSS, so be careful to correcty set your CSS selector to not override all BootStrap CSS.
But, does your HTML can't change ? Is seems to me that the H2 element should have been a LABEL.
Related
I am pretty new to bootstrap and have been beating my head up with the following problem. Whenever I use the following code, the padding between the columns is getting lost.
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-4 col"></div>
<div class="col-sm-4 col"></div>
<div class="col-sm-4 col"></div>
</div>
</div>
</body><!--end body-->
But whenever I move the class col inside the column, then the code works exactly as expected.
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-4">
<div class="col"></div>
</div>
<div class="col-sm-4">
<div class="col"></div>
</div>
<div class="col-sm-4">
<div class="col"></div>
</div>
</div>
</div>
</body><!--end body-->
Following is the CSS class that I am using
<style>
.col{
min-height: 500px;
background-color: gray;
}
</style>
Bootstrap does not add space between the columns, it adds space inside each column. So if you put another div inside each column that will give the space you want.
The way I look at it is the columns only act as containers for the actual content, which goes inside them.
jsfiddle of the kind of thing I think you should do instead: https://jsfiddle.net/bqadptzL/
CSS:
.col {
/* just to demonstrate */
background-color: red;
}
.box {
background-color:gray;
min-height: 500px;
}
HTML:
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-4 col">
<div class="box">
Content
</div>
</div>
<div class="col-sm-4 col">
<div class="box">
Content
</div>
</div>
<div class="col-sm-4 col">
<div class="box">
Content
</div>
</div>
</div>
</div>
</body><!--end body-->
If you look at the grid system examples, you will see there is no space between the columns, only inside them. http://getbootstrap.com/css/#grid
Hope that helps.
Sidenote: you should not put columns inside columns, you should only put columns inside rows. But you can put rows inside columns. So you can alternate row - column - row - column, not row - column - column. This is how Bootstrap system is meant to work.
When you use the second version you get a margin created by the div you added,
if you add a margin to the .col css class you should see the difference.
You can take a look here for a more detailed answer about how to work with the columns in bootstrap with a similar issue
The padding is not getting lost. In Bootstrap, col-sm-* has 15px padding. Remember, the background color fills entire the width of the cell, padding included.
You're putting the bg color on the column with padding, and in the other case it's on the inner column that doesn't have padding.
Put the background-color and a border, only on the col-sm-4. and you'll see the difference. The padding is there, and the same in both cases...
http://www.codeply.com/go/lf2V9vlIsr
So I am building a page using twitter bootstrap 3. I am trying to get the div to fill the container, but with no luck. This is what the div looks like:
Now the html for that bit is:
<div class="container-fluid no-padding">
<div class="row">
<div class="col-lg-4"><img src="images/block-1.jpg" alt="Send Bulk SMS Today"/></div>
<div class="col-lg-4 world">
<h4>SEND BULK SMS</h4>
<div class="world-map"></div>
<select>
<option>south africa</option>
<option>sri lanka</option>
<option>pakistan</option>
</select>
<div class="world-note">Bulk sms is an international service. Please select your country to view applicable rates.</div>
</div>
<div class="col-lg-4"><img src="images/block-3.jpg" alt="Receive Faxes on the Go"/> </div>
</div>
</div>
And the CSS:
.container-fluid.no-padding div{
padding: 0px;
}
div.world {
background:black;
color:white;
height:100%;
min-height:100%;
}
div img {
max-width:100%;
}
Here's a fiddle: http://jsfiddle.net/wu6svxgg/1/
Due to bootstrap, use this link to view because bootstrap small screen rules are applied: http://fiddle.jshell.net/wu6svxgg/1/show/
I have tried using min-height and height on both the container and div.world, but no luck. Any idea how I can get the black bit to fill up the rest of the container?
Try changing your html to this:
<div class="container-fluid no-padding">
<div class="row row-same-height">
<div class="col-lg-4 col-xs-height col-top"><img src="http://www.nobelis.co.za/sandbox/temp/block-1.jpg" alt="Send Bulk SMS Today"/></div>
<div class="col-lg-4 col-xs-height col-top world">
<h4>SEND BULK SMS</h4>
<div class="world-map"></div>
<select>
<option>south africa</option>
<option>sri lanka</option>
<option>pakistan</option>
</select>
<div class="world-note">Bulk sms is an international service. Please select your country to view applicable rates.</div>
</div>
<div class="col-lg-4 col-xs-height col-top"><img src="http://www.nobelis.co.za/sandbox/temp/block-3.jpg" alt="Receive Faxes on the Go"/> </div>
</div>
</div>
And then adding this css code:
.row-same-height > div:first-child {
text-align: right;
}
.row-same-height {
display: table;
width: 100%;
}
.col-xs-height {
display: table-cell;
float: none !important;
}
.col-top {
vertical-align:top;
}
jsfiddle: https://jsfiddle.net/wu6svxgg/9/
Take a look at this link if you need more info.
You have two options:
Set html and body to 100%, plus all elements that wrap around the target element, in your example, the div world.
Example: http://www.bootply.com/uq2MmhkOvR
A problem with the above method is that the height fits the visible viewport only. If you scroll down, you will notice that the div "world" no longer reaches the bottom of the screen.
Another method is to use absolute positioning on the target element.
Example: http://www.bootply.com/Vk6A7IoVqj
In the above method, make sure to reset the position property of "world" to relative using media queries so as to benefit from Bootstrap's responsive features.
You can also simply set the background color of the page to **black*.
I'll start off by stating that I know this question has been asked a lot, but none of the answers I saw seemed to work for me.
Basically, I have some divs inside of a larger div. They'll have dynamic text, so I don't know how many lines each will be. The problem is that I can't seem to get the divs to size themselves to the parent's height. I want the column divs to take up the entire height of the row div (basically, I want that blue part to fill all the space between the bars).
HTML:
<div class="container">
<div class="row divOne">
<div class="col-xs-3 divTwo">Some Text</div>
<div class="col-xs-3">
Some text that could wrap to multiple lines
</div>
</div>
<div class="row divOne">
<div class="col-xs-3 divTwo">Different Text</div>
<div class="col-xs-3 divThree">
With some more text
</div>
</div>
</div>
CSS:
.divOne
{
border-top:10px solid black;
}
.divTwo
{
background-color: #32649b;
height:100%;
color:white;
}
jsfiddle:
Now, what I've learned from other versions of this question are that
float:left might be screwing it up
height:100% doesn't work if the parent's height is defined
position:relative might help on the parent
The problem with the float is that I'm using bootstrap, and that's where the float is coming from, so I don't really want to mess with that.
I can't really define parent height, because it'll be dynamic based on the children.
I also tried messing around with position:relative on the parent and absolute on the child, but that seemed to get really screwy. I'm also guessing this won't work because I'm using bootstrap. It's possible that I'm just missing something, though. I'll admit to not being the greatest with CSS.
I don't know if I'm having these issues because I'm using bootstrap, or because I'm just being an idiot right now.
Something else that seems to be throwing a wrench into things: These columns will be laid out differently on smaller screens vs. larger ones. I actually want something along the lines of col-xs-12 col-md-3 for these.
The short answer is that you can't really achieve this within the constraints of the bootstrap framework. There are plenty of articles that explain why div elements can't stretch to the height of their container, and how to get around this problem. One of the solutions I'm most fond of is Faux Columns.
But, let's get a little more creative then that.
I came up with something that might work for your scenario, but requires a bit of change to your markup. Here's a solution that wraps the bootstrap grid with display: table.
http://jsfiddle.net/Wexcode/13Lfqmjo/
HTML:
<div class="table-container">
<div class="table-row divOne">
<div class="col-xs-3 divTwo">Some Text</div>
<div class="col-xs-3">
Some text that could wrap to multiple lines
</div>
<div class="col-xs-6"></div>
</div>
</div>
CSS:
.table-container {
margin: 0 -15px;
}
.table-row {
display: table;
width: 100%;
}
.table-row [class^="col"] {
display: table-cell;
padding: 0 15px;
float: none;
}
Note that for this solution to work, you must include enough col elements to stretch it all 12 columns (see that I added an empty .col-xs-6 div).
You can add
display:flex;
to divOne , and will act like you wanted.
in bootstrap 4 'row' class applies this on div, but in ealier versions you need to add manually if you expect such behavior.
Give .divOne a display: flex and remove the height: 100% from .divTwo:
.divOne
{
border-top:10px solid black;
display: flex;
}
.divTwo
{
background-color: #32649b;
/*height:100%;*/
color:white;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row divOne">
<div class="col-xs-3 divTwo">Some Text</div>
<div class="col-xs-3">
Some text that could wrap to multiple lines
</div>
</div>
<div class="row divOne">
<div class="col-xs-3 divTwo">Different Text</div>
<div class="col-xs-3 divThree">
With some more text
</div>
</div>
</div>
I use Bootstrap 3 on a form with the following HTML, containing 4 panels with the same structure as the example below.
My problem here is that each panel contains a different and therefore appears with a different height. I tried adding style="height:100%" to them but that didn't change anything.
Can someone tell me how I can set them to always take the full height, independent of their content? Basically, what I am trying to achieve is to have all 4 panels take the same height as they appear in one row - they only thing the differ is the paragraph with the variable text, everything else is the same for all panels and takes the same height for each of them.
Example panel:
<form role="form">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="thumbnail thumbnail-hover">
<div class="txtcntr" style="width:100%"><span>Placeholder for icon</span></div>
<div class="caption">
<h3 class="text-primary">Title</h3>
<p>Some variable text</p>
<p>View</p>
</div>
</div>
</div>
</div>
// ...same structure for other panels...
</form>
Here is what I did: http://jsfiddle.net/o7p1jtjv/1/
By setting the .row to have a hidden overflow, and then giving each column div a margin-bottom equalling the padding-bottom, you force them to all be larger than the .row, but none of the overflowing content (extra div space) is shown.
For comparison, here is one without the extra rules: http://jsfiddle.net/o7p1jtjv/2/
<div class="container-fluid">
<div class="row">
<div class="col-xs-4">
<p>text</p>
</div>
<div class="col-xs-4">
<p>text</p>
</div>
<div class="col-xs-4">
<p>text</p>
</div>
</div>
</div>
.row
{
overflow: hidden;
}
.row > div
{
background: red;
margin-bottom: -999999px;
padding-bottom: 999999px;
}
To adjust the height of your thumbnail use a fixed pixel height like 300px.
.thumbnail {
height: 300px;
}
The thumbnail class does not respond to percentage height changes.
Like #Dan said, the panel class would be a better option. If you prefer not to use fixed height, you can use CSS flexbox like this..
http://www.bootply.com/IwBoyELqpx
Is there a way in Bootstrap 3 to right align a div?
I am aware of the offsetting possibilitys but I want to align a formatted div to the right of its container while it should be centered in a fullwidth mobile view. The class 'pull-right' is not working anymore. Did they forgot to replace it or am I missing something obvious?
<div class="row">
<div class="container">
<div class="col-md-4">
left content
</div>
<div class="col-md-4 col-md-offset-4">
<!-- The next div has a background color and its own paddings and should be aligned right-->
<!-- It is now in the right column but aligned left in that column -->
<div class="yellow_background">right content</div>
</div>
</div>
</div>
Shure I know how to do this in CSS, but can it be done in pure bootstrap 3?
The class pull-right is still there in Bootstrap 3
See the 'helper classes' here
pull-right is defined by
.pull-right {
float: right !important;
}
without more info on styles and content, it's difficult to say.
It definitely pulls right in this JSBIN
when the page is wider than 990px - which is when the col-md styling kicks in,
Bootstrap 3 being mobile first and all.
Bootstrap 4
Note that for Bootstrap 4 .pull-right has been replaced with .float-right
https://www.geeksforgeeks.org/pull-left-and-pull-right-classes-in-bootstrap-4/#:~:text=pull%2Dright%20classes%20have%20been,based%20on%20the%20Bootstrap%20Grid.
Do you mean something like this:
HTML
<div class="row">
<div class="container">
<div class="col-md-4">
left content
</div>
<div class="col-md-4 col-md-offset-4">
<div class="yellow-background">
text
<div class="pull-right">right content</div>
</div>
</div>
</div>
</div>
CSS
.yellow-background {
background: blue;
}
.pull-right {
background: yellow;
}
A full example can be found on Codepen.
i think you try to align the content to the right within the div, the div with offset already push itself to the right, here some code and LIVE sample:
FYI: .pull-right only push the div to the right, but not the content inside the div.
HTML:
<div class="row">
<div class="container">
<div class="col-md-4 someclass">
left content
</div>
<div class="col-md-4 col-md-offset-4 someclass">
<div class="yellow_background totheright">right content</div>
</div>
</div>
</div>
CSS:
.someclass{ /*this class for testing purpose only*/
border:1px solid blue;
line-height:2em;
}
.totheright{ /*this will align the text to the right*/
text-align:right;
}
.yellow_background{
background-color:yellow;
}
Another modification:
...
<div class="yellow_background totheright">
<span>right content</span>
<br/>image also align-right<br/>
<img width="15%" src="https://www.google.com/images/srpr/logo11w.png"/>
</div>
...
hope it will clear your problem
Bootstrap 4+ has made changes to the utility classes for this. From the documentation:
Added .float-{sm,md,lg,xl}-{left,right,none} classes for responsive floats and removed .pull-left and .pull-right since they’re redundant to .float-left and .float-right.
So use the .float-right (or a size equivalent such as .float-lg-right) instead of .pull-right for your right alignment if you're using a newer Bootstrap version.
Add offset8 to your class, for example:
<div class="offset8">aligns to the right</div>