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 trialAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsHow to float labels
I was trying to learn "how to float label
in input. I came around this pen on CSS Tricks.
Here , at first input
has been written after label
element and then flex-flow:column-reverse
has been used. Why this reverse approach has been used.
Why not label
element has been used before input
element and flex-direction:column
is used as both will give the same output.
Please help. My whole day has been gone in learning about this concept and I still have doubt in it.
Please help Treehouse.
Thanks.
1 Answer
Steven Parker
229,204 PointsThis trick uses some pretty advanced concepts!
The reason for the reverse flex layout is to display the label before the input, and the reason that the label must come after the input in the HTML is to make it possible to use an "adjacent sibling" selector in the CSS ("input:placeholder-shown + label
").
The nice thing about having a CodePen example is that you can easily play around with it to help your understanding. Try making changes to some of the settings (like removing the reverse or changing the direction) and see what happens.
Also note that the word "float" here is being used to describe the particular animation effect being produced and has nothing to do with the CSS "float" property.
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsOk got this. Thanks I have some more questions about this pen -
input: placeholder-shown+label
select onlylabel
who are next adjacent sibling of "input" with "placeholder"?-::webkit-input-placeholder
- MDN says "don't use this attribute as this is recognised by only WebKit , then why it's been used here and is there any limitations of using this element? What is the main role of this element?Steven Parker
229,204 PointsSteven Parker
229,204 PointsDid you see his blog post where he explains the limitations of the demo?