Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
filipz
11,063 PointsCSS Positioning Problem in Mobile?
I have a problem with a div that is in a flex container div. It has justify-content:center; and align-items:center; so the first div should be in the center of the screen. It works perfectly fine on the computer but when I access the site on mobile the div is improperly placed as if justify-content and align-items wasn't working. Hopefully that makes sense and hopefully someone can help.
1 Answer
Ryan S
27,276 PointsHey Filipz,
Depending on what browser you are using on mobile, you will likely need to use the "-webkit" prefix when dealing with flexbox. These help with cross-browser compatibility. Webkit is for Safari and Chrome, and there are a couple other prefixes like "-ms" and "-moz" for IE and firefox, respectively.
Typically you add them prior to the regular properties.
For example:
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-justify-content: center;
justify-content: center;
-webkit-align-items: center;
align-items: center;
}
Most, if not all, flexbox properties will require these extra prefixes in order to work on all browsers. I'd recommend keeping a close eye on the documentation when working with flexbox, and any other special properties like css animations, which will require these prefixes to work across all browsers.
If the webkit isn't solving your problem, take a look at this article at css-tricks.com for more information on what prefixes might help you.
Hope this helps.