Select Page

Original & Concise Bullet Point Briefs

Learn Flexbox in 15 Minutes

Flexbox: Achieving Easy Alignment of Elements Across Browsers

  • Flexbox is a layout system that allows elements to flexibly grow and shrink to fit within the browser
  • It has properties such as justify content, align items, and align content which allow for easy alignment of elements in a horizontal or vertical manner
  • Flex direction can be set to row or column based layouts, allowing for main and cross axes to flip.

Understanding Flexbox: Navigating Container Elements, Alignment and Spacing

  • Flexbox is a container for laying out spacing between elements and positioning items
  • Flexstart aligns elements at the start of the container, justify content adjusts alignment along the main axis and align items adjusts alignment along the cross axis
  • Flex grow takes leftover space and divides it proportionately between flexbox items, while flex shrink prevents an item from shrinking
  • Align self overrides align content.

Original & Concise Bullet Point Briefs

With VidCatter’s AI technology, you can get original briefs in easy-to-read bullet points within seconds. Our platform is also highly customizable, making it perfect for students, executives, and anyone who needs to extract important information from video or audio content quickly.

  • Scroll through to check it out for yourself!
  • Original summaries that highlight the key points of your content
  • Customizable to fit your specific needs
  • AI-powered technology that ensures accuracy and comprehensiveness
  • Scroll through to check it out for yourself!
  • Original summaries that highlight the key points of your content
  • Customizable to fit your specific needs
  • AI-powered technology that ensures accuracy and comprehensiveness

Unlock the Power of Efficiency: Get Briefed, Don’t Skim or Watch!

Experience the power of instant video insights with VidCatter! Don’t waste valuable time watching lengthy videos. Our AI-powered platform generates concise summaries that let you read, not watch. Stay informed, save time, and extract key information effortlessly.

hello everybody in this video we'regoing to dive into the different partsof flexbox starting with what flexbox isand how flexbox works and then we'regoing to dive into the differentproperties that we can apply to flexboxin order to lay out in style ourelements as we want so to get startedlet's add a div inside of our body herewe'll give it a class of flexboxcontainer since this will be thecontainer that all our fluxboxitems will reside inside then inside ofthis container we'll add another divgive it a class and we'll call this oneflux box item and we'll also give it aclass of flexbox item one I will we knowwhich item we're referring to when westyled it individually if you save thatyou'll see that we have a gray box showup on the right here and that's becauseI've already applied some styles tothese flux box items so that we candistinguish them and see them now let'scopy this and add in two more flux boxitems and save that and you'll see thatwe have now three flux box items insteadof our flexbox container but we don'thave any styling to actually make this aFlex container so to get started withcreating a Flex container what's goingto our Styles here we have our flex boxcontainer selector and we can just saydisplay and set it to flex and this ishow we create a Fox box container now ifI save that you'll see that all of ouritems are now the same height and theyall show up in one row you'll alsonotice that if I shrink our browseryou'll see that these items will scaletheir size to fit within the browser andas I make it wide enough for them to allfit you'll just show up on the left sideof the screen and this is really themain thing that flex box has going forit it allows you to style theflexibility and sizing of differentelements in the container from theactual container selector here thisflexbox container without ever having tostyle the actual flex box items soinside of the container for flex box youcan do things such as laying out yourdifferent elements across the differentrows and columns as well as aligningthem inside of that layout and then theitems themselves you can specify how youwant them to flexibly grow inside of thecontainer or how you want them to shrinkinside of the container to make thiseasier to see I've created somebackground styles here and if we savethis you'll see that we now have ourfluxbox container which is this yellowbackground item and then are differentfluxbox items with theirembers in the corner as these grayishcolored with a border that is a littlebit darker gray this way we can see whenwe shrink our browser you can see thatthese items shrink together and as weincrease it they'll grow again nowbefore we get started with actuallylaying out and styling a differentelements inside of our container wefirst need to understand the concept ofthe main axis and the cross axis insideof a flexbox container I have thesestyles here that will show us the mainaccess and cross access for our flexboxcontainer and as you can see this mainaccess goes horizontally across theentire flexbox container while the crossaccess goes vertically this is becauseour flexbox container is laid out in arow as opposed to a column fluxbox givesus a property on the container calledthe Flex direction where we can set ifwe want our flex box to be a row orcolumn based layout and depending onthis these main axis and cross accesswill actually flip so in a column basedlayout the cross access will gohorizontally and the main axis will govertically all you really need toremember is that this main axis will gothe same direction as your layout so ina row layoutit'll be horizontal and a column layoutit'll be vertical and in order to stylethe layout of these elements you stylethem based on the axis this so the mainaxis or the cross axis and not based onvertical or horizontal so if we wantedto style our elements on the main axiswe would use the justified contentproperty inside of our flexbox containerright now our main axis has a flex startattribute applied to which means thatall the elements will align at the startof the main axis if for example wewanted to Center these items inside ofthis main axis we would change this fromflex start to center and if you say thatyou see that now all of our fluxboxitems are in the center of our containeranother thing that we can do is if wewanted to layout our elements with spacebetween them we could use the spacebetween property here and now all theextra space inside of our Flex containerwill be put evenly between all thedifferent items inside of our containerand if we wanted to have space on theoutside of our container as well wecould use space around which puts aneven amount of space on all sides of theFlex items and not just in between themthis makes laying out items in ahorizontal manner very easy inside offlux boxdue to this justify content property butif we wanted to for example lay outthings on this cross access we would usethe align items property and right nowthe default for this is stretch whichmeans our items will stretch to fill themost amount of space vertically thatthey can that's why some of our itemsthat were smaller grew to full size ifwe wanted to keep the size of our itemswe would use flex start and then all ofour items would align themselves at thevery top of our flexbox container basedon this cross axis we could also useCenter here in order to Center themvertically which is one of the mostimportant things that you can do withFlex box before flexbox aligning itemsvertically inside of a container wasnearly impossible both fluxbox is aseasy as one line of CSS and it willperfectly align all of your items insideof this container the last way to alignour items inside of our flexboxcontainer is to use the align contentproperty and this property is only forusing on multi-line fluxbox containersbut as you saw when we shrink ourbrowser size these items just shrink totake up the amount of space needed butif we change our flex box here to usethe Flex wrap property and tell it towrap you'll see that our items will wrapon two different lines instead ofshrinking their size as you can see hereand this aligned content property tellsit how much space to put between linesfor example if we use flex start all ofour items will line up at the top of thecontainer while flex and we'll line themall up at the bottom of the container aneasy way to see this is if we add aheight property to our flexbox containerso if we put the height here and we justmake it let's say 700 pixels now you cansee that the Lex end for a wine contenthas made our flex box items all wine atthe bottom of our container voila flexstart will make them aligned at a startand this has very similar properties tojustify content for example we could putspace between here and now we havespacing between our flex box item rowsand if we shrink this even furtheryou'll see that there's now even spacebetween them as well which is great butaligned content is something that Idon't really use that often and reallyjustify content and align items are theproperties I use most since they alignyour individual rowsalong the main and cross axis now let'srevert that height back to the defaultget rid of our line content justifiedcontent a line items and wrap so we justhave a normal fox box container here andwe'll increase that size a little bitand we'll also remove these accessessince we no longer actually need themnow if we go back into our stylist hereand let's say we want a column layoutinstead we'll just use our flexdirection change it to column and nowyou see that are different fluxbox itemsshow up in a column as opposed to thedifferent row and if we used justifiedcontent and we say Center for exampleyou'll notice that they don't Centerhorizontally and that's because they'recentering inside of the columnvertically and if we put that heightback onto our Flex container let's makeit 800 pixels save that you'll see thatnow they're centered vertically andthat's because justify content is usingthe main axis which in this case iscolumn as opposed to row if we usedalign items we put Center in here andsave it you'll see that now our itemsare centering horizontally because thecross axis is horizontal inside of acolumn based flexbox container now wecan revert all that back to normal so wejust have our standard fluxbox containerhere and we can start to talk about thedifferent properties you can apply it toour different flexbox items as opposedto the flexbox container as I mentionedthe container is really only for layingout spacing between your items as wellas the positioning of your items insideof the container the actual flexbox itemproperties are meant to either overridethose positioning and layout propertiesor to apply different flexible sizing tothese elements as you can see by defaultwhen we decrease the size of our browseror items shrink in size but if we wantedto prevent that on let's say only ourfirst item we could go in here use theFlex rink property and set it to zero tosay we don't want it to shrink at alland if we say that you now see our firstitem does not shrink no matter how smallour browser gets but these other twoitems shrink together we could also usethe Flex grow property if we wanted totell our items to grow bigger so if weincrease our size here we have all thisextra space let's say we wanted ourthird flexbox item to fill that spaceall we would do is that flex grow to bewon and now that item takes up all theextra space no matter what size ourbrowser is we can also use flex grow onmultiple items so let's say we want oursecond item to also grow we can justapply it to here and as we increase ourbrowser size you'll see that they'llboth grow proportionately to one anotherso that way this item the Flex box itemtwo and fluxbox item three are the sameexact size since they have the sameexact flex grow number if we for examplechange this to be two and increase thesize of our browser you now see that ourfluxbox item two is about twice the sizeof our fluxbox item three you willnotice however that fluxbox item two isnot exactly twice the size of fluxboxitem three as you would think by makingflex grow twice as big but all the Flexgrow property actually does is take allof the leftover space so if we removethese folks grows here you see we haveall this leftover space and it dividesit between all the different flex growsso if we have a flex grow of two hereand we have a flux grow of one on thethird item fluxbox item two will gettwice the amount of available space thatfluxbox item three gets so if we saythat you'll see that this fluxbox itemtwo has gained twice of the availablespace that was left over as flexbox itemthree and the reason that fox box itemtwo is not actually twice the size offluxbox item three is because we have awidth set on our flex box items so ittakes this 200 pixels and then adds theamount of available remaining space ontothat 200 pixels if we wanted to overridethat we could use what is called theFlex basis property and this tells ourflex box where to start growing from soif we change this to zero our objectwill imagine that it is zero pixels widewhen it starts adding an additionalspace to it and if we did this for bothof our items here and saved it you'llsee that now Fox box item 2 is exactlytwice the size of bucks box item 3because it started adding additionalspace onto them in a two-to-oneproportion so it added twice as much tofluxbox two as it did to flex box threebut they had no starting point at allthey started at zero which means thatfluxbox2 here is twice the size ofbox three when they started at 200pixels it still added twice as muchspace to Fox box two as Fox box threebut they had a 200 pixel beginning sizeso they weren't actually exactly twicethe size as the other onefor the most part flex Gro flex shrinkand the different justify content andalign item properties or all you reallyneed in order to create dynamic andcomplex layouts in either a row or acolumn based container but if you neededto override the cross access alignmentof a property you can do that with thealigned self property and let's say wewanted our second Fox box item to be inthe center of the container instead ofstretching the full height of thecontainer we can just use that and nowyou can see that this aligns selfproperty overrides are aligned contentof our other containers and you can seethat it aligns in the center here whilethese other items are aligning stretchand this can be applied to all of ourdifferent containers for example wecould go up to our flex box item onehere and make this one flex and andyou'll see that now this aligns itselfat the end of the container instead ofstretching which is the default for ourline items applied to our Fox boxcontainer the very last property that isleft to talk about is the order propertythat can be applied to our Fox box itemsthis allows us to change the order ofour items inside of our flexboxcontainer without actually changing ourHTML so for example if we wanted Fox boxitem 1 to be our third item we wouldchange the order to three Fox box itemtwo let's say we want to be our firstitem so we change the order here to 1and then we'll change the order of thisFox box 3 to be an order of two and ifyou say that you now see that our seconditem is at the beginning of ourcontainer our third item is the seconditem in our container and our first itemis the very last item in our containerand this is because we use the orderproperty to rearrange the order visuallyof our items without changing the orderin our actual HTML this is a property Ihighly advise not using unless youreally need it because this actuallymesses up the flow for people usingscreen readers since the screen readerwill still go in the order the HTMLwhich means they'll get eight Fox boxitem one first Fox box item two secondand Fox box item three third even thoughthe order of display is different thanthatthis also messes up when you're tabbingthrough different form items for exampleif this was an input element for a textbox our tab would go to the flux boxitem one first and then flux box item tosecond even though they're displayed inorder where it should be to first andthen three second so that's why I highlyadvise not using the order propertyunless you really need to rearrange theorders visually without actually messingwith the HTML of the document and that'sreally all there is to a flexboxcontainer for the most part you justneed to have a container that wraps yourdifferent flux items you give it adisplay of flex to say that you're usinga flux box container you then use thejustified content properties and thealign item properties inside of yourcontainer in order to tell it how youwant to line these items inside of acontainer and then lastly you can usethe different Flex trink grow and vasesproperties in order to layout your itemsindividually inside of the flexboxcontainer to grow or shrink as you needa shorthand for these different flexshrink grow and basis properties is justthe straight-up flex property where thefirst number as your flex grow thesecond number is your flex ring and thelast number is your flex basis this is agreat shorthand property that you canuse in order to apply all three of thosedifferent properties in one line you canalso leave off the later properties suchas if we only wanted to flex grow to beone we just put flex one and it willintelligently assign the Flex trink andflex basis properties without us havingto actually manually set them so I hopeyou guys enjoyed this video and learnsomething new about flex box and how youcan use flex box in order to createdynamic layouts for your site if youguys did enjoy it please make sure toleave a like down below and in thecomments let me know if there's anythingelse about flex box you want me to talkabout in more depth in either a futurevideo or in a comment for you guys thankyou guys very muchhave a good day