Vertically aligned with the Bootstrap 3

This translation from: Vertical Number of 3-align = left with Bootstrap

Bootstrap 3'm a using Twitter the I, the I have have Problems and the when the I want to align = left Vertically TWO div, for Example - JSFiddle Link : I'm using Twitter Bootstrap 3, and two vertically aligned to divencounter problems, such as -JSFiddle link :

 <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <div class="row"> <div class="col-xs-5"> <div style="height:5em;border:1px solid #000">Big</div> </div> <div class="col-xs-5"> <div style="height:3em;border:1px solid #F00">Small</div> </div> </div> 

Grid System uses in on Bootstrap of The float: left, Not display:inline-block, SO The Property vertical-aligndoes Not Work. On Bootstrap grid system is used float: leftinstead display:inline-block, so property vertical-aligndoes not work. Tried a using the I margin-topto FIX IT, But the I of Think the this IS not A Good Solution for Design at The responsive. I try to use margin-toprepair, but for responsive design, this is not a good solution.


#1st Floor

Reference: https://stackoom.com/question/1ODQR/ vertical alignment with Bootstrap-


#2nd Floor

Answer Presents A hack the this, the I Would Highly But the Recommend you to use flexbox (AS Stated in @Haschem answer ), we're now Supported Operating since Everywhere. The answer is a hack, but I strongly recommend that you use flexbox (such as @Haschem answer as above ), because now it anywhere are supported.

Demos link: Demo Link:
- on Bootstrap. 3 - the boot program. 3
- on Bootstrap. 4 Alpha. 6 -Bootstrap the Alpha. 6. 4

You still can use a custom class when you need it: You can still use when you need a custom class:

 .vcenter { display: inline-block; vertical-align: middle; float: none; } 
 <div class="row"> <div class="col-xs-5 col-md-3 col-lg-1 vcenter"> <div style="height:10em;border:1px solid #000">Big</div> </div><!-- --><div class="col-xs-5 col-md-7 col-lg-9 vcenter"> <div style="height:3em;border:1px solid #F00">Small</div> </div> </div> 

Bootply bootstrap

The using inline-blockADDS Extra Space Blocks BETWEEN A Real Space IF the let you in your code (like ...</div> </div>...). If the code in ...</div> </div>...real space (for example ...</div> </div>...), use inline-blockadds additional space between the blocks. This extra space breaks our grid if column sizes add up to 12: If the total size of the column 12, this additional space will destroy the grid:

<div class="row">
    <div class="col-xs-6 col-md-4 col-lg-2 vcenter">
        <div style="height:10em;border:1px solid #000">Big</div>
    </div>
    <div class="col-xs-6 col-md-8 col-lg-10 vcenter">
        <div style="height:3em;border:1px solid #F00">Small</div>
    </div>
</div>

Here Wallpaper, WE Extra Spaces BETWEEN've GOT <div class="[...] col-lg-2">and <div class="[...] col-lg-10">(A Carriage return tabs and 2/8 Spaces). Here, we <div class="[...] col-lg-2">and <div class="[...] col-lg-10">extra spaces (carriage return and tab characters 2/8 spaces) between. And so ... so ...

Enter here captions

Let's kick this extra space !! Let's kick the extra space!

<div class="row">
    <div class="col-xs-6 col-md-4 col-lg-2 vcenter">
        <div style="height:10em;border:1px solid #000">Big</div>
    </div><!--
    --><div class="col-xs-6 col-md-8 col-lg-10 vcenter">
        <div style="height:3em;border:1px solid #F00">Small</div>
    </div>
</div>

Enter here captions

At The Notice Seemingly Useless Comments <!-- ... -->? Note seemingly useless comments <!-- ... --> -...- <!-- ... --> it? Are They Important - the without Them, the BETWEEN at The whitespace at The <div>. Elements the Take up by Will at The Space in layout, at The Grid System Breaking they are important - without them, <div>the space between the elements will occupy space in the layout, thereby undermining the grid system .

Note: the Bootply has been updated 注意:Bootply已更新


#3rd floor

Try this in the CSS of the div : Try the following in a div in the CSS:

display: table-cell;
vertical-align: middle;

#4th floor

I genuinely find the following code works using Chrome and not other browsers than the currently selected answer: I did find the following code can be run on the Chrome browser, instead of running on a browser other than the currently selected answer:

.v-center {
    display:table!important; height:125px;
}

.v-center div[class*='col-'] {
   display: table-cell!important;
   vertical-align:middle;
   float:none;
}
.v-center img {
   max-height:125px;
}

Bootply Link bootstrap link

May need to git commit amend at The by You Heights (SPECIFICALLY ON .v-center) and the Remove / Change div ON div[class*='col-']for your Needs. You may need to modify the height (especially in .v-center), and according to the need to delete / change div[class*='col-']on div[class*='col-'].


#5th Floor

I ran into the same situation where I wanted to align a few div elements vertically in a row and found that Bootstrap classes col-xx-xx applies style to the div as float:. Left I encountered the same situation, I think in a row several vertical alignment div elements, found Bootstrap class col-xx-xx as the style applied div float: left.

I had to apply the style on the div elements like style = "Float: none" and all my div elements started vertically aligned. I have to apply styles such as style =: the div element "Float none" and the like, and all div elements begin vertically aligned. Here is the working example: This is a working example:

<div class="col-lg-4" style="float:none;">

Link jsFiddle jsFiddle link

Just in case someone wants to read more about the float property: for more information in case someone wants to read about the float property:

W3Schools - Float W3Schools- float


#6th floor

Flexible box layout flexible box layout

At The Advent of at The With CSS Flexible Box , MANY of Web Designers' Nightmares 1 have have been resolved. With the CSS Flexible Box came out, many Web designers nightmare 1 has been resolved. One of the most hacky ones, the vertical alignment. One hacky, vertical alignment. IT IS the even in Possible Now Unknown Heights . Now even at an unknown height is also possible.

"Two of Decades of layout Hacks are Coming to End AN. Maybe not Tomorrow, But Soon, and for at The REST of Our Lives." "Two decades layout hacking coming to an end. Maybe not tomorrow, but soon, as well as rest of our lives. "

- Legendary CSS Eric Meyer AT W3Conf 2013 - CSS legend Eric Meyer in the W3Conf 2013

Flexible Box (or in short, Flexbox ), is a new layout system that is specifically designed for layout purposes. The new system is a flexible box arrangement (or simply flexbox) it is specifically for layout purposes. At The Specification States : Specifications :

Similar layout IS superficially to the Flex Block layout. The Flex block layout similar to a layout on the surface. It lacks many of the more complex text- or document-centric properties that can be used in block layout, such as floats and columns. It lacks many more complex documents, or text attribute can be used as the center of the layout block, e.g. floating points and columns. In return it gains simple and powerful tools for distributing space and aligning content in ways that webapps and complex web pages often need. In return, it received a simple but powerful tool that can be in accordance with the way Web applications and complex web pages often need space allocation and alignment of content.

How can it help in this case? How to provide help in this case? Well, let's see. Okay, wait and see.


Vertical aligned columns vertically aligned columns

Twitter Bootstrap WE have have the Using .rowS the HAVING some .col-*S. Use Twitter Bootstrap, we .rowhave some .col-*. WE need to do IS All to Run the display at The Desired .row 2 AS A flex Container Box and the then align = left All the ITS flex Item S (at The the Columns) Vertically by align-itemsProperty. We need to do is the desired .row 2 is shown as flex container box, and then through align-itemsall its properties flex items s (each column) vertically align-items.

HERE the EXAMPLE (Please Comments with the Read at The Care) example here (please read carefully reviews)

<div class="container">
    <div class="row vertical-align"> <!--
                    ^--  Additional class -->
        <div class="col-xs-6"> ... </div>
        <div class="col-xs-6"> ... </div>
    </div>
</div>
.vertical-align {
    display: flex;
    align-items: center;
}

The Output Output

Are aligned vertical columns Twitter Bootstrap

Colored area displays the padding-box of columns. Color display column filling frame region.

Clarifying on align-items: center clarificationalign-items: center

Cross-Axis the Alignment 8.3: The align-itemsProperty 8.3 cross-axis alignment: align-itemsProperties

Items the Flex CAN BE in the aligned The Cross Axis of The Current Line of Container The Flex, Similar to justify-contentBut. The Perpendicular direction in telescopic item may be telescopic in the current row of containers horizontal axis aligned in similar justify-contentbut in the vertical direction justify-content. align-itemsThe default for Alignment All sets of Container The flex apos items, Including Anonymous flex items . align-itemsSet all containers flex align-itemsdefault alignment, including anonymous flex items .

align-items: center; Center value by, The Flex Item 'centered in IS S The margin Box Cross Axis . The Line WITHIN through the center value, the elastic project margin frame within the line intersecting the axis centered.


Big Alert big alarm

Note # 1 Important: Twitter Bootstrap does not the Specify at The widthof the Columns in Extra Small Devices One of The unless you give .col-xs-#. Classes to the Columns at The Important Note # 1: unless you .col-xs-#provide one class to the column, otherwise it will not be over Twitter Bootstrap small equipment in the specified column width.

THEREFORE in the this Particular Demo, the I have have Used .col-xs-*classes in the Order for the Columns to BE displayed Properly in Mobile the MODE, Because IT specifies at The widthof at The column Explicitly. Therefore, in this particular demo, I use the .col-xs-*class to correct in mobile mode display column, because it explicitly specifies the column width.

You could alternatively But Switch OFF at The Flexbox layout Simply by Changing display: flex; However, you can only change the display: flex; closed Flexbox layout display: flex; to display: block; in specific Screen sizes. Specific screen size. For instance: For example:display: block;

/* Extra small devices (767px and down) */
@media (max-width: 767px) {
    .row.vertical-align {
        display: block; /* Turn off the flexible box layout */
    }
}

You could Or the Specify .vertical-align only ON specific Screen sizes like SO: Or, you can only specify a specific screen size .vertical-align, as shown below:

/* Small devices (tablets, 768px and up) */
@media (min-width: 768px) {
    .row.vertical-align {
        display: flex;
        align-items: center;
    }
}

Case that the In, the I'd Go with @KevinNelson 'S Approach . In this case, I will use @KevinNelson the method .

Note # 2 Important: Vendor prefixes Omitted Due to brevity. Important Note # 2: Because of brevity vendor prefixes. During syntax has been changed flexbox at The Time. Flexbox syntax has changed in the meantime. The new written syntax will not work on older versions of web browsers (but not that old as Internet Explorer 9! Flexbox is supported on Internet Explorer 10 and later). The new grammar can not afford in writing on the old version of the Web browser action (but not as old as the Internet Explorer 9! Internet Explorer 10 and later versions support flexbox).

Should Also means you use the this Vendor-The prefixed like the Properties display: -webkit-boxand Production's SO ON in the MODE. This means that you should also use vendor prefixes attribute in production mode, for example, display: -webkit-boxand so on.

You the Click ON IF "Compiled Toggle View" in at The Demo , you'll See at The Version of The prefixed CSS Declarations (Thanks to Autoprefixer ). If the demo , click "Switch to compile View" , you will see the CSS declarations prefix version (thanks Autoprefixer ).


Full-height columns with vertical aligned contents full height columns having vertically aligned content

See you in at The AS Previous Demo , the Columns (at The Flex items) are NO longer AS AS Their High Container (Flex Container at The Box. IE at The .rowElement). If you are on a demonstration can see, the columns (elastic Project) not its container (elastic container block, i.e., .rowas high as the element).

Because the using IS of the this centervalue for align-itemsProperty. This is because align-itemsthe attribute use centervalue. IS default value of The stretchSO The items that CAN Fill The Entire The height of parent Element. The default value of stretchthe entire project may be filled so that the height of the parent element.

In order to fix that, you can add display: flex; To solve this problem, you can add display: flex; to the columns as well: as well as columns:

HERE the EXAMPLE (Again, at The Mind Comments) Here example (again, note the comment)

.vertical-align {
  display: flex;
  flex-direction: row;
}

.vertical-align > [class^="col-"],
.vertical-align > [class*=" col-"] {
  display: flex;
  align-items: center;     /* Align the flex-items vertically */
  justify-content: center; /* Optional, to align inner flex-items
                              horizontally within the column  */
}

The Output Output

Twitter Bootstrap full height columns having vertically aligned content

Colored area displays the padding-box of columns. Color display column filling frame region.

Last, But not Least , at The Notice that the Demos and code Snippets are Meant to give you here Wallpaper A Different IDEA, to the Provide A MODERN at The Approach to the Achieve. Goal. Last but not least, the point is , please note that the demo here and code segments are designed to provide you with different ideas to provide a modern method for achieving goals. At The Mind Please " Big Alert " Section IF you are going to use the this Approach in Real world Websites or Applications. If you want to use this method in the real world of website or application, please note that " great alarm " section.


For further reading including browser support, these resources would be useful: For further reading, including browser support, these resources will be useful:


1. Vertically align = left AN Inside Image A div with height responsive 2. It Better to use apos AN Additional Order class in ALTER on Twitter on Bootstrap apos Not to default .row. 1. The height of the vertical image in response aligned div 2. preferable to use other classes, so as not to change the default Twitter Bootstrap .row.

Original articles published 0 · won praise 73 · views 560 000 +

Guess you like

Origin blog.csdn.net/w36680130/article/details/105360311