3

I want to use flex box model in my html

I have a div container with three buttons inside.

<div id="viewport" class="linearlayout horizontal" data-am-control="vertical-layout" > 
 <!-- El div "container_buttons" estaría centrado en el medio del padre --> 
 <button id="twitter" class="btn item" data-am-control="button" >Twitter dinámico</button>
 <button id="spinnerSimple" class="btn item" data-am-control="button" >Spinner simple</button>
 <button id="spinnerCustom" class="btn item" data-am-control="button" >Spinner personalizado</button>
</div><!-- END VIEWPORT-->

I use display: box and orientation: vertical...but i see my buttons inline insted of vertical..

My problem is with all browsers.

Css is this:

#viewport{
width: 480px;
height: 800px;
background-image: linear-gradient(#a8a8a8, #ebebeb);
margin: 0 auto;
}
.linearlayout{
display: -webkit-box; 
display: -moz-box; 
display: box;
}
.horizontal{
-webkit-box-orient: horizontal; 
-moz-box-orient: horizontal; 
box-orient: horizontal;
}
.vertical{
-webkit-box-orient: vertical; 
-moz-box-orient: vertical; 
box-orient: vertical;
}

http://jsfiddle.net/adUD9/

asked Jun 6, 2013 at 11:39
4
  • What is flex box model? Is it this: html5rocks.com/en/tutorials/flexbox/quick ? Commented Jun 6, 2013 at 11:57
  • If your problem is with a specific browser, it is helpful to mention it. Commented Jun 6, 2013 at 12:04
  • @Kasyx yes, it's flex box model!. Commented Jun 6, 2013 at 14:12
  • @cimmanon sorry!i add it to my post. My problem is in all browsers.. :( Commented Jun 6, 2013 at 14:14

1 Answer 1

5

You have a few things working against you.

  1. You're only using the legacy properties from the 2009 draft, which not every browser has an implementation of. IE10 is the first IE browser to support Flexbox, and it implemented the March 2012 draft. Every other browser has an implementation of either the 2009 draft or the standard draft, and some have both.

  2. Webkit's 2009 Flexbox implementation just doesn't work on buttons. If you add other sibling elements, they'll be placed vertically as you would expect. Chrome has both the 2009 and standard implementation, but Safari, Android, iOS only have the 2009 implementation.

You can fix #1 by using the correct collection of properties, but there's nothing you can do about #2 for Webkit browsers that only support the 2009 properties.

http://jsfiddle.net/adUD9/3/

.linearlayout {
 display: -webkit-box;
 display: -moz-box;
 display: -ms-flexbox;
 display: -webkit-flex;
 display: flex;
}
.horizontal {
 -webkit-box-orient: horizontal;
 -moz-box-orient: horizontal;
 -webkit-flex-direction: row;
 -ms-flex-direction: row;
 flex-direction: row;
}
.vertical {
 -webkit-box-orient: vertical;
 -moz-box-orient: vertical;
 -webkit-flex-direction: column;
 -ms-flex-direction: column;
 flex-direction: column;
}

If all you want is to make your buttons display vertically, I would recommend not using Flexbox for this purpose:

http://jsfiddle.net/adUD9/1/

button {
 display: block;
 width: 100%;
}
answered Jun 6, 2013 at 12:00

1 Comment

Thanks! This helps me. I need to use flexbox because it's similar to linearlayouts of android and i want to translate what you see in HTML5 + CSS3 files to a native interface in android...so i need found similar patterns to Linearlayout and relativelayout in CSS....

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.