First project v1.1: Vanilla CSS/HTML from XD design
Design comparison
Solution retrospective
Update as of 1/24/2021:
- updated the HTML tags so they're not all divs
- removed some overflow properties to mobile doesn't look broken on landscape
- removed explicit img tags for the 2 background images and placed them both as background-images similar to ApplePieGiraffe's solution but took it one step further and also scaled the image size accordingly
- made the footer fixed that tucks underneath the card if they collide
- refactored some codes and removed redundant codes
Original post as of 12/29/2020: Hi all,
This is my first project so there's most likely a lot that needs to be cleaned up so I'll keep it to just a few questions!
- HTML: I feel like I was spamming divs here, are there more specific tags that I could be using?
- CSS variables: I learned by watching SCSS and to put variables in a separate variables partial. But I wanted to practice vanilla CSS here. Having that said what is the best practice for where to put the variables. In <HTML> or <body> I'm guessing? (probably not * which is where I dumped them as everything will have it)
- CSS class naming: When I learned SCSS it was done using BEM style, which I guess I could have used in regular CSS here. Are there naming conventions for vanilla CSS that is commonly used professionally that I should look into?
- CSS redundant code: Are there any redundant coding that I'm doing like setting the same property and value in multiple places that would have been inherited that I could tighten up and refactor? (ignore the scss/js folder)
- Viewport: I mostly tested this using the discrete design viewports given in the firefox mobile viewer (ctrl-shift-M). 1440x720 for desktop and 375x667 for mobile but I find that if I just look at it normally in my full screen browser then the background images don't quite line up properly. Should I worry about viewports other than the ones given in the design in future challenges?
Thanks all!
Community feedback
- @grace-snowPosted almost 4 years ago
Hi again Jeremy :)
I've had a chance to look through your code as requested and have some more suggestions for you now. I hope you find these helpful - please upvote comments if they are helpful as that helps me learn how to mentor well too
-
Yes you need to be using html tags designed for text for your text elements, such as paragraphs, headings or list items. You can place classes on spans inside these tags if you need to adjust styling for each part, like in the statistics. e.g.
<div class="item-number bold-blue-font">80K</div><div class="item-text">Followers</div>
could become<p><span class="item-number bold-blue-font">80K</span><span class="item-text">Followers</span></div>
with some css or a line break in the middle to make them stack. -
It's most common to put variables (css custom properties) on the :root element, but if you set up any that are specific to a particular component, you can put them inside that class and they will be scoped to it. This is handy if you need to override an existing variable for a one-off use case, for example.
-
BEM is used in css as well, it's not a scss thing. So go for it if you want to use it!
-
I think you could refactor this yes. Rather than duplication though, it's more that you're setting position absolute on things that wouldn't be necessary if you use background images, and giving some elements properties like z-index, height and width when they don't need it (see other points below)
-
I've already covered for you. Because of the hidden overflow, you cannot see the card when you change to landscape orientation on a phone. So I would revisit this a bit more...
Other general points
- You shouldn't need to do anything to make this responsive, except maybe reposition the bg images for some screen sizes. You definitely don't need explicit widths and heights on your card. A max-width and a width of 100% would be fine, with the height not needing to be defined.
- I would make the background images into background images, not place them in the html. In fact I think that's what i did in my solution for this
- The profile image of Victor should have alt text. That is a meaningful image I think.
- Some of your font is smaller than it should ever go. 10px is unreadable for a lot of people. This is a common issue with these challenges as the designer seems to favour very small fonts, but I would always overrule that and agree a sensible minimum with a designer.
There you go, all done!
1@grace-snowPosted almost 4 years agoHere is my version of this challenge if you want to take a look: https://github.com/grace-snow/fmentor_profile-card-component
I recommend inspecting in devtools, including emulating mobile in different orientations. As you can see, no media-queries required on this one
1@lanechangerPosted almost 4 years ago@grace-snow Thanks so much Grace!
- I think I take the paragraph tag too literally and was hesitant about using it for a single word but that's good to know.
- Funny enough I started off using background image for those 2 bg circles instead of <img> but had some z-index issues with the circles overlapping the card so ended up hacking it the way I did. I'll re-visit them as background images then!
Yeah I was very literal with the design regarding that font 10 size. So in the "real world" it sounds like you're expected to make a lot more of these judgement calls then. Good to know.
This has been very helpful, thanks again for taking time out of your day to go through my newbie code, I appreciate it! I will check out your solution and do some analysis from there :)
0 -
- @grace-snowPosted almost 4 years ago
Hi Jeremy, that's a lot of questions, all great ones to be asking though!
I'm just off to bed so will only touch on one answer for you for now.
No 5 - yes you need to consider all viewport sizes, including smaller and larger than the supplied designs, and Everything in between. Design files are just meant to be a guide for us, and outside of those provided screen sizes frontend devs are meant to make sensible decisions about how best to present the content.
You'll probably find it best if you try to work from the smallest screen sizes first as those will usually be the simplest and give a good base for your css. Then start to enlarge your viewport and add a min-width media query in when needed to adjust styles for larger screens. This may seem counterintuitive at first but will result in cleaner and easier to understand css with fewer overrides needed.
Good luck with it! I'll try and take a look at your code tomorrow ☺
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord