Bootstrap `justify-content-center` isn't centering without explicit column number - html

I have:
<div id="root" class="container-fluid">
<div>
<div class="row justify-content-center">
<div class="col">
<form>
and the form (which is small widthwise) is not centering. If I add a number to the col div (ie. col-4) then the small column will be centered but the form left-justified within it and starts wrapping weirdly in a small viewport. Moving the justify-... part to the col didn't do anything either.
How am I supposed to go about centering that form element?

I had to include the form-inline class on the form and put the justify-content class on the form as well. the justify class didn't need to go anywhere else.

Related

Equal space between elements INSIDE a column bootstrap 5

So imagine a bootstrap column full of elements (divs, paragraphs, links.. ) how do I space those elements equally inside that column, like space-between alignment or space-around. I don't want margins or padding. I want elements to automatically equally space around the free space vertically inside a column.
In the documentation for flex everything seems to be focused on rows and what little there is for columns it's aligning elements inside a column horizontally.
Any ideas how I can get the desired effect?
The solution could be adding flex positioning to your column as well. So you can add those additional classes that are provided by bootstrap.
<div class="container">
<div class="row">
<div class="col d-flex flex-column justify-content-between">
<!-- Here comes your content -->
</div>
</div>
</div>
Since you want to evenly space the element is the y axis, you need to add flex-column. Also remember you can nest any number of flex boxes inside another.

Must all content, even if it is just one column, be placed inside rows?

In Bootstrap, must all content- even just a basic block of text placed in the middle of a page for example, be placed inside columns and rows. My website seems to work just fine doing this:
<div class="container-fluid">
<h2>My Heading</h2>
<p>This Is Content On the page</p>
</div>
Yet, I have been told it should be like this:
<div class="container-fluid">
<h2>My Heading</h2>
<div class="row">
<div class="col">I'm content inside the grid</div>
</div>
</div>
Yet, on some of the templates on the bootstrap site itself, they don't always use columns and rows.
I'm really confused...
Thanks
No, not all content needs to be placed in .rows.
.rows and .cols simply provide you with a customizeable grid system (i.e.: number of columns, gutter sizes, responsiveness breakpoints are a few of the things one could customize) aimed at displaying content differently at various page widths. That (and also the division of the row in 12 columns) are what it was designed for.
The only purpose of rows and cols is to divide the space differently at different page widths and to provide some minor padding (gutters). If you don't need that for a part of your content, don't use it. Whenever you have a section which you want displayed according to your own custom rules, you can simply include and style it as you want.
So, for example, this is perfectly valid and can be seen in various Bootstrap examples:
<div class="container">
<div class="row">
<div class="col">
... normal layout cols here
</div>
</div>
<div>
your custom stuff here. you need to provide responsiveness CSS rules for this content.
Out of the box, being a `<div>`, this will fill all the available width
if, for example, it was included in a `.container-fluid`,
it would span the entire browser window, at all screen widths.
</div>
<div class="row">
<div class="col">
... more normal layout here...
</div>
</div>
But whenever you want to use .cols, you should place them as direct children of .rows. If you do not, you will see some nasty horizontal scrollbars across your content, because the grid has a system of negative margins and (positive) padding to cater for gutters at various width sizes.
With this basic example everything works fine, especially when the heading is centered. Using different approach for Bootstrap grid is usually not a good idea.
From Bootstrap docs:
In a grid layout, content must be placed within columns and only
columns may be immediate children of rows.
As alignment problems will occur in the long run.
Secondly when you start using SASS with Bootstrap and change grid variables then everything stays aligned and is controlled from
one place.
In your example if you want to align the heading you need to add a margin-left so that is would be aligned with I'm content inside the grid.
Look at this example how everything is aligning with and without rows/columns: https://codepen.io/LaCertosus/pen/KKKzVqR
<div class="container-fluid mt-5">
<div class="row">
<div class="col">
This text is inside <b>row</b> and <b>col</b>
</div>
</div>
<div class="row">
This text is only inside <b>row</b>
</div>
<div class="col">
This text is only inside <b>col</b>
</div>
<div>
This text is only <b>container</b>
</div>
</div>
<div>
This text is outside <b>container</b>
</div>
It is the right question to ask why I have to generate so much boilerplate but it will come out in the long run when elements need to align and scale in different screen sizes.

Vertical alignment of columns in bootstrap 4

I've searched on google and this site for answers on how to vertically align columns to be centered. I've found entries with this exact title but none of them work, they all show how to align horizontally. Even the bootply's etc. links to examples which centers horizontally and not vertically.
I've followed the guide on bootstraps official site, and it is telling me to just use the class align-items-center on the row, or adding align-content-center on the column, but these doesn't work for me at all, I get no response.
Can someone tell me what I am doing wrong here?
This is the guide I used: http://getbootstrap.com/docs/4.0/layout/grid/#alignment
And I am using the latest bootstrap v4.0.0.beta-2.
Example from my code:
<div class="container">
<div class="row align-items-center">
<div class="col-3"><span>test</span></div>
</div>
</div>
Expected result: Column with the text "test" should be located vertically centered on my page.
Actual result: Text is showing in the left upper corner of the page.
Bootstrap row will contain flex property. With that only we can able to use flex properties for child divs. But here in your example you haven't used row class or d-flex class in your code.
I suggest you to add row into your code..
<div class="container">
<div class="row align-items-center">
<div class="col-3"><span>test</span></div>
</div>
</div>
Now your code will center the text vertically, But within the container height. It won't be center to your html page.
Vertical Center: JS Fiddle
To make Your text to center of your page, make row div to full height 100vh

CSS alternative to overflow:hidden

I have an issue with my CSS layout
I have a form that is contained in a 500 pixel fixed width. It is set to be centered in the page with margin auto;
Inside that div I made a table using div's. Since each div's that act as a table row have different height, I have used the overflow:hidden property. I did that to minimize the size of the form.
Inside that div I have 3 other divs that act like table data "td". They are floating inside the row.
What I am trying to achieve is to display another div on top of them all when there is an error in the form. Just like the one you see on Stackoverflow reminding you that you have code in your text that need to be set as code. The red div on the right. Now I am a bit stuck because I can't overflow that div to the sides.
So what other option do i have to set the height of the "row" div without using overflow:hidden. I dont want to use tables and the content is always changing.
Any solution is welcome.
Here is simple code so you get the picture;
<div class="row">
<div class="overflowing"></div>
<div class="float_left"></div><div class="float_left"></div> <div class="float_right"></div>
</div>
The overflowing div should not push the floating divs around and is not visible until I change it's property and fill it with content.
Use clearfix class with row if you are using bootstrap
<div class="row clearfix">
OR
<div class="clearfix"></div>
before end of row tag
If it is not using bootstrap
<div style="clear:both;"></div>
before end of row tag
`
<div class="float_left"></div><div class="float_left"></div> <div class="float_right"></div>
</div>`
I think it will work, and about the alternative to overflow use fixed height width thenoverflow:auto wolud be useful

Forced wrapping of floated divs with CSS

I'm working with OpenLayers mapping. OpenLayers draws maps on a webpage, and has a mechanism for placing UI controls on those maps. One of its controls is the Panel control, which contains some number of button controls.
A Panel control is rendered as a div, with a bunch of child divs within it - one for for each button. The appearance of the Panel control, and of all of the button controls, is configured with CSS. My problem is with how to write the CSS to get what I want. (Note, I can't change the rendered html without hacking at the OpenLayers sourcecode, which I'd rather avoid.)
So I've put together a sample of the kind of html I need to work with, here
I want the buttons to be laid out horizontally, from left to right, at the top right of the map. I can do that with float:right, and position:absolute.
I want the buttons to be laid out on multiple lines. If I add a width: to the panel, the child button divs will wrap. But I don't want over-flow wrapping, I want to wrap between specific buttons. And I can't figure out how to do that in css.
If you take my example, for example, I can cause it to put the first five buttons on the first line, and the last two on the second, by change the width. But suppose I wanted to put the first three buttons on the first line, and the last four on the second. If I set the width so that the buttons wrapped after the third, I'd get the seventh button on a third line, which I don't want.
Using set-width and automatic wrapping to position the child buttons always puts the same number of child buttons on every line, with the last line possibly short. That's not what I need.
Thinking about it, I could use position:absolute on every button, but that starts to seem very tedious. Anyone have a simpler approach?
If you can alter the CSS of a specific element, you could just set clear: right:
<div id='contents'>
<div id='panel'>
<div id='button1'>1</div>
<div id='button2'>2</div>
<div id='button3'>3</div>
<div id='button4' style='clear: right'>4</div>
<div id='button5'>5</div>
<div id='button6'>6</div>
<div id='button7'>7</div>
</div>
</div>
You could alternatively insert a clearing element between the buttons:
<div id='contents'>
<div id='panel'>
<div id='button1'>1</div>
<div id='button2'>2</div>
<div id='button3'>3</div>
<br style='clear: right' />
<div id='button4'>4</div>
<div id='button5'>5</div>
<div id='button6'>6</div>
<div id='button7'>7</div>
</div>
</div>