Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Profile card solution using HTML and CSS

Feithersā€¢ 180

@Feithers

Desktop design screenshot for the Profile card component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hello there! I think I got this one pretty good, however any help trying to clean unnecessary code is helpful!

Thanks!

Community feedback

@0xabdulkhaliq

Posted

Hello there šŸ‘‹. Congratulations on successfully completing the challenge! šŸŽ‰

  • I have other recommendations regarding your code that I believe will be of great interest to you.

HEADINGS āš ļø:

  • This solution had generated accessibility error report due to lack of level-one heading <h1>
  • Every site must want at least one h1 element identifying and describing the main content of the page.
  • An h1 heading provides an important navigation point for users of assistive technologies, allowing them to easily find the main content of the page.
  • So we want to add a level-one heading to improve accessibility by reading aloud the heading by screen readers, you can achieve this by adding a sr-only class to hide it from visual users (it will be useful for visually impaired users)

.

I hope you find this helpful šŸ˜„ Above all, the solution you submitted is great !

Happy coding!

0
Rileyā€¢ 260

@rileydevdzn

Posted

Hi! Congrats on completing the profile card component!

Not much unnecessary code here, but one thing you could do is remove the <img> tag for the pattern and set a background-image on your first <div> instead, since the pattern on the card behind the profile photo is just decorative.

You do need an <h1> tag for your page. This one's a bit tricky, I'd replace your <p> for Victor Crest with an <h1>, since the whole page is about the profile card for Victor.

Hope this helps, good job tackling responsive layouts with both Flexbox and Grid!

0

Feithersā€¢ 180

@Feithers

Posted

@rileydevdzn Thanks for the answer! I have a question regarding the background that you proposed. If would do that, how can I position the background on top of the card, and does it affect the width of the overall card? Because at the moment, the width of the card is given basically by the background img inside of it, and I was wondering how it would interact if it would be a background instead of an img.

Thanks!

0
Rileyā€¢ 260

@rileydevdzn

Posted

@Feithers Great question!

Youā€™re exactly right, in your current code the width of the card is coming from the width of your image element (a child element). If you just substitute a background-image for the image, it will change the width of the card and you wonā€™t be able to see it!

One thing to be aware of is that in this project, the width of the image file provided is exactly the same as the width of the card (in the desktop design), but this isnā€™t always true IRL.

To fix this, first we would explicitly set the width of the card. You can find this width value by looking at the image file info or opening the svg in a browser and using Inspect Element.

Then use a background-image on the child element and make sure the child element takes up 100% of the available space (like you did with .stats). Since there isnā€™t any other content in this div and an empty div has a height of 0, weā€™ll also need to set the height of the div (you can also find this value by looking at the image file).

This will set the card width and add the semantically correct background-image.

To answer your question about how to position it on top of the card, since weā€™re setting a background-image on a child element inside the card, itā€™s already there. Itā€™s a little confusing since there are a lot of background-images in this project!

Let me know if that helps or if you have any other questions!

-Riley

Marked as helpful

0
Feithersā€¢ 180

@Feithers

Posted

@rileydevdzn Yes I understood everything perfectly, the only thing that I've read somewhere (maybe I'm wrong) is that I should try to avoid giving fixed width values to my elements, so they don't act weird on responsive media. Like I said, maybe I didn't understand and I'm wrong, but just a question. A second question would be, when would you do the background technique and when the img one?

Thanks!

0
Rileyā€¢ 260

@rileydevdzn

Posted

@Feithers

Yes, you are correct, avoiding fixed width values is generally a good rule of thumb. Fixed widths with absolute values (px, rem) can do some funny stuff as you change screen sizes.

There are a couple ways to both declare values and keep elements responsive, like using relative units (viewport units, percentages, em) instead of absolute units and/or using CSS functions. You could set a card width at 70vw (viewport width) units, for example, and it would adjust to be 70% of the viewport width at any size.

You can set some boundaries by explicitly declaring min-width and max-width values through CSS (min and max can apply to lots of things, not just widths). Another option for better control over the maximum and minimum values in fewer declarations (since the range of screen sizes is pretty big), is CSS functions. Math functions, specifically, since there are a ton of functions in CSS.

You can set widths with calculations, for example, like width: calc(100% - 2vw); There are also CSS min() and max() functions, and thereā€™s even more detailed functions like CSS clamp() that take a minimum, ā€œpreferred,ā€ and maximum value as arguments.

Definitely play around with all the different ways to declare widths, sometimes using relative units will be enough, or sometimes a simple calc() works and you donā€™t need something like clamp(). And sometimes clamp is just fun to play with šŸ˜Š

Another great question!

The rule of thumb I use is that purely decorative things like patterns and textures, things that are just there for ā€œvisual eye-candyā€ I usually put into background-image and everything else I put into an img (or picture) element with alt text. Personally I start with everything in img elements and think about what I would care about if someone were reading the page aloud to me. Would I care about ā€œpattern of repeating circles?ā€ Does it help me understand the page at all? If itā€™s a pattern or a texture like that, Iā€™ll move it into a background-image instead. But for something like the profile picture of Victor Crest in this project, Iā€™d keep that an img with alt text. Iā€™m not an accessibility expert, and Iā€™m working to improve my skills with alt text, but ā€œprofile photo of Victor Crestā€ is both simple and expresses exactly what the photo is.

A lot of the time itā€™s not that straightforward though. Hereā€™s some decorative image examples from W3C to show you what I mean. The first one with the border is something that can also be easily created using a div and CSS, but the next 3 are the ones I think are more helpful, for me at least.

The article is focused on when to use (or not use) alt text, which is another way you can make an image decorative. There are a LOT of opinions about when to use background-image vs. img element. That thread shows itā€™s age with some of the answers (donā€™t replace text this way, there are better options now).

I donā€™t like using ā€œit depends,ā€ but unfortunately it really does depend on the context/situation. Short version, I use an img for anything that is informative or functional, which is most things; the part that changes is whether to include alt text. FYI you can move forward or back in the W3C article (side nav or thereā€™s buttons at the bottom too) to see their recommendations with more examples of informative and functional images. I use a background-image if itā€™s a pattern or a texture thatā€™s just there to make the page look nice.

That was a super-long answer, but hopefully it helps!

Marked as helpful

0
Feithersā€¢ 180

@Feithers

Posted

@rileydevdzn

Thanks so much, all super clear!

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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