I have this : http://www.bootply.com/apUgehnGLq
Why width of red box is so big ? I want it to finish immediately after last box, which is a box with tag CCC and then center the whole red box.
Since you're working with % in the inner div you are going to have to make the percentages bigger and the div smaller till you have the size you prefer, like so:
http://www.bootply.com/juFV1xgpNY
Just play around with the withs of the .inner and the divs inside of it.
The border adds pixels to the width of the box, so the last box goes on a new line. You can set box-sizing: border-box; on the body and a padding on the .border instead of a margin to achieve what you want.
I updated your code: http://www.bootply.com/1s5ESfKlod
Read more about what the box-sizing property can do at Mozilla Developer Network.
Update
See code here: http://www.bootply.com/ASWCuTHrZy
You can control the items in this example using flex-basis, where the X items is 3.
flex-basis: calc(100% * 1/3);
So 100 divided by 1/3 makes 33.333..%, that's the width of the AAA, BBB, CCC containers. DDD will go to the next line.
All used CSS:
body * {
box-sizing: border-box;
}
.border {
padding: 5px;
border: 2px solid black;
}
#inner {
border: 2px solid red;
width: 80%;
}
.container-fluid {
display: flex;
flex-flow: row wrap;
align-content: flex-start;
}
.border {
flex-basis: calc(100% * 1/3);
}
The issues you are having with the 4 columns not lining up is due to the margin you have set in the .border class, as well as the class for #inner id. So, if you remove the border margin we should be able to resolve all the issues. Like so:
<div id="center" class="col-lg-7">
<div class="col-md-4 border">AAA</div>
<div class="col-md-4 border">BBB</div>
<div class="col-md-4 border">CCC</div>
<div class="clearfix"></div>
<div class="col-md-12 border">DDD</div>
</div>
Alternatively, if you would like to have all the 4 columns to line up, you can just code it like so:
<div id="center" class="col-lg-7">
<div class="col-md-3 border">AAA</div>
<div class="col-md-3 border">BBB</div>
<div class="col-md-3 border">CCC</div>
<div class="col-md-3 border">DDD</div>
</div>
You can view the sample code here: http://www.bootply.com/GZJwteX6yT
I hope this helps you!
Related
Good day, I believe that this is not possible, but asking to be shure. I do not know how to DuckDuckGo similar questions, and I have an example:
.wrapper {
border: 1px solid red;
margin: 10px;
}
<div class='wrapper'>
<div>xxx</div>
<div>xxx</div>
<div>xxx</div>
</div>
<div class='wrapper'>
With CSS only: how to have this element the same height, without hardcode?
</div>
Maybe I can wrap this to table (or display as a table) where the height of one row with, say, 5 children will be the same as height of another row with 9 children? I need this for table data representation where I can have empty rows - I need to have them the same height as another rows with data. Looks like now I will need to use Javascript to get computed height :(
CSS grid can do it:
.wrapper {
border: 1px solid red;
margin: 5px;
}
.container {
display:grid;
grid-auto-rows:1fr; /* The magic property */
}
<div class="container">
<div class='wrapper'>
<div>xxx</div>
<div>xxx</div>
<div>xxx</div>
</div>
<div class='wrapper'>
With CSS only: how to have this element the same height, without hardcode?
</div>
</div>
I'm trying to control border bottom of flex-child 2 only.
So if I give display: flex to parent and border to both the childs, border will remain same for both depending on the height of any child div.
I don't want to increase height(border bottom) of child 2 as child 1 but I want it to have height as it's content only.
.one {
border: 1px solid black;
}
.parent {
display: flex;
}
.two {
border: 1px solid;
}
<html>
<body>
<div class="parent">
<div class="one">
Testing One<br> Testing One<br> Testing One<br> Testing One
</div>
<div class="two">
Testing Two
</div>
</div>
</body>
</html>
Is it really possible using flexbox
i ma having trouble to play with boostrap 4 css.
I would like to have in a row two jumbotron with the same height no matter what is inside and with the inside of the div vertically aligned center.
my code is the following :
<div class="container">
<div class="row">
<div class="col-8">
<div class="jumbotron greenback">
<h7>Welcome to the Project test Detail page</h7>
</div>
</div>
<div class="col-4">
<div class="jumbotron greenback">
<div class="inner-score">
<div class="score-title">
<h6>Team Score</h6>
</div>
<div class="score-value">
<h4>85</h4>
</div>
</div>
</div>
</div>
</div>
</div>
I created a jsfidlle to show you https://jsfiddle.net/kscv67kt/2/
As you can see now the two jumbotron have vertical text align center but are not full row height..
Have you tried adding height: 100% to the jumbotron elements?
.jumbotron.greenback {
height: 100%;
}
This will cause both elements to fill the height of the container (the .row in this case).
Worth noting that setting height: 100% would cause the element's bottom margin to overflow it's container, so for neatness you could adjust the jumbotron's and their container's margin-bottom properties accordingly...
.container {
margin-bottom: 32px /* Moving the margin-bottom value of the
.jumbotron to it's outer container. */
}
.jumbotron.greenback {
height: 100%;
margin-bottom: 0;
}
Alternatively with jQuery...
$(document).ready(function() {
var jumboMaxHeight = 0
$(".jumbotron").each(function(){
if ($(this).height() > jumboMaxHeight) {
jumboMaxHeight = $(this).height() }
})
$(".jumbotron").height(jumboMaxHeight)
})
Edit: To centre the text elements within the .jumbotron, there are a number of ways you could do it, one is using flexbox properties on the parent element (in conjunction with the jQuery solution)...
.jumbotron.greenback {
text-align: center;
display: flex;
align-items: center;
justify-content: space-around;
}
I have a row in Bootstrap 3 and 3 columns in that row. I want to align two of the columns to the bottom of the row and keep the first column at the top. When I use the traditional approach with position relative in the parent and absolute for both columns I get a weird behavior which I imagine is because of something in twitter bootstrap. Here's a bootply of what's happening:
http://www.bootply.com/125735
The absolute forces all the columns on top of eachother, can anyone help me out? The end result is to have something like so:
http://fahadalee.wordpress.com/2013/12/31/bootstrap-3-help-how-to-alin-div-in-bottom/
Thanks
You can use display: table-cell and vertical-align: bottom, on the 2 columns that you want to be aligned bottom, like so:
.bottom-column
{
float: none;
display: table-cell;
vertical-align: bottom;
}
Working example here.
Also, this might be a possible duplicate question.
Vertical align bottom and remove the float seems to work. I then had a margin issue, but the -2px keeps them from getting pushed down (and they still don't overlap)
.profile-header > div {
display: inline-block;
vertical-align: bottom;
float: none;
margin: -2px;
}
.profile-header {
margin-bottom:20px;
border:2px solid green;
display: table-cell;
}
.profile-pic {
height:300px;
border:2px solid red;
}
.profile-about {
border:2px solid blue;
}
.profile-about2 {
border:2px solid pink;
}
Example here: http://www.bootply.com/125740#
When working with bootsrap usually face three main problems:
How to place the content of the column to the bottom?
How to create a multi-row gallery of columns of equal height in one .row?
How to center columns horizontally if their total width is less than 12 and the remaining width is odd?
To solve first two problems download this small plugin https://github.com/codekipple/conformity
The third problem is solved here http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-responsive-centered-columns
Common code
<style>
[class*=col-] {position: relative}
.row-conformity .to-bottom {position:absolute; bottom:0; left:0; right:0}
.row-centered {text-align:center}
.row-centered [class*=col-] {display:inline-block; float:none; text-align:left; margin-right:-4px; vertical-align:top}
</style>
<script src="assets/conformity/conformity.js"></script>
<script>
$(document).ready(function () {
$('.row-conformity > [class*=col-]').conformity();
$(window).on('resize', function() {
$('.row-conformity > [class*=col-]').conformity();
});
});
</script>
1. Aligning content of the column to the bottom
<div class="row row-conformity">
<div class="col-sm-3">
I<br>create<br>highest<br>column
</div>
<div class="col-sm-3">
<div class="to-bottom">
I am on the bottom
</div>
</div>
</div>
2. Gallery of columns of equal height
<div class="row row-conformity">
<div class="col-sm-4">We all have equal height</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
</div>
3. Horizontal alignment of columns to the center (less than 12 col units)
<div class="row row-centered">
<div class="col-sm-3">...</div>
<div class="col-sm-4">...</div>
</div>
All classes can work together
<div class="row row-conformity row-centered">
...
</div>
I don't know why but for me the solution proposed by Marius Stanescu is breaking the specificity of col (a col-md-3 followed by a col-md-4 will take all of the twelve row)
I found another working solution :
.bottom-column
{
display: inline-block;
vertical-align: middle;
float: none;
}
http://twitter.github.com/bootstrap/scaffolding.html
I tried like all combinations:
<div class="row">
<div class="span7 offset5"> box </div>
</div>
or
<div class="container">
<div class="row">
<div class="span7 offset5"> box </div>
</div>
</div>
changed span and offset numbers...
But I cant get a simple box perfectly centered on a page :(
I just want a 6-column-wide box centered...
edit:
did it with
<div class="container">
<div class="row" id="login-container">
<div class="span8 offset2">
box
</div>
</div>
</div>
But the box is too wide, is there any way I can do it with span7 ?
span7 offset2 gives extra padding to the left span7 offset3 extra padding to the right...
Bootstrap's spans are floated to the left. All it takes to center them is override this behavior. I do this by adding this to my stylesheet:
.center {
float: none;
margin-left: auto;
margin-right: auto;
}
If you have this class defined, just add it to the span and you're good to go.
<div class="span7 center"> box </div>
Note that this custom center class must be defined after the bootstrap css. You could use !important but that isn't recommended.
besides shrinking the div itself to the size you want, by reducing span size like so... class="span6 offset3", class="span4 offset4", etc... something as simple as style="text-align: center" on the div could have the effect you're looking for
you can't use span7 with any set offset and get the span centered on the page (Because total spans = 12)
Bootstrap3 has the .center-block class that you can use. It is defined as
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
Documentation here.
If you want to go full-bootstrap (and not the auto left/right way) you need a pattern that will fit within 12 columns e.g. 2 blanks, 8 content, 2 blanks. That's what this setup will do.
It only covers the -md- variants, I tend to snap it to full size for small by adding col-xs-12
<div class="container">
<div class="col-md-8 col-md-offset-2">
box
</div>
</div>
Sounds like you just wanted to center align a single container.
The bootstrap framework might be overcomplicating that one example, you could have just had a standalone div with your own styling, something like:
<div class="login-container">
<!-- Your Login Form -->
</div>
and style:
.login-container {
margin: 0 auto;
width: 400px; /* Whatever exact width you are looking for (not bound by preset bootstrap widths) */
}
That should work fine if you are nested somewhere within a bootstrap .container div.
add the class centercontents
/** Center the contents of the element **/
.centercontents {
text-align: center !important;
}
#ZuhaibAli code kind of work for me but I changed it a little bit:
I created a new class in css
.center {
float: none;
margin-left: auto;
margin-right: auto;
}
then the div become
<div class="center col-md-6"></div>
I added col-md-6 for the width of the div itself which in this situation meant the div is half the size, there are 1 -12 col md in bootstrap.
Follow this guidance https://getbootstrap.com/docs/3.3/css/
Use .center-block
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
wrap the div in a parent div with class row then add style margin:0 auto; to the div
<div class="row">
<div style="margin: 0 auto;">center</div>
</div>