Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 5 months ago

Responsive card design using html and css

omarrrefaatt1•20
@omarrrefaatt1
A solution to the Blog preview card challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)
Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Aakash Verma•9,500
    @skyv26
    Posted 5 months ago

    Hi @omarrrefaatt1, 👋

    Your project has some great foundational work! However, I noticed a few areas where you can improve, and I'd love to share some suggestions to help you polish your code further. 🚀 Let's dive in:


    1. Move inline styles to a CSS file

    • Observation: Your GitHub code includes internal styles in your HTML file lines 13-158.
    • Why it's important: Keeping styles in a separate CSS file makes the code cleaner, easier to maintain, and reusable across multiple pages. Think of it as organizing your tools in a toolbox instead of scattering them around your workspace—easier to find, right? 🛠️
    • Suggestion: Move the styles to a CSS file and link it in the HTML. This also helps in collaborative development, making the HTML more readable.

    Refactored Example: HTML:

    <link rel="stylesheet" href="styles.css">
    

    CSS (in styles.css):

    .card {
      max-width: 350px;
      padding: 20px;
      border-radius: 15px;
      background-color: white;
      display: grid;
      grid-template-rows: auto;
      gap: 10px;
      border: solid black 2px;
      box-shadow: 10px 10px 10px rgb(0, 0, 0);
    }
    

    2. Avoid redundant properties

    • Observation: Properties like margin and height in .card are not essential. Similarly, other properties in .cardimg, .cardtitle, .date, etc., can be removed without altering the design.
    • Why it matters: Redundant code is like carrying unnecessary baggage on a trip—it weighs you down and serves no real purpose. Keeping your CSS lean improves readability and performance.
    • Suggestion: Remove unused or redundant properties to streamline your styles.

    Refactored Example:

    .card {
      max-width: 350px;
      padding: 20px;
      border-radius: 15px;
      background-color: white;
      display: grid;
      grid-template-rows: auto;
      gap: 10px;
      border: solid black 2px;
      box-shadow: 10px 10px 10px rgb(0, 0, 0);
    }
    .cardimg {
      border-radius: 15px;
      width: 100%;
      object-fit: cover;
    }
    

    3. Use semantic HTML tags

    • Observation: It’s unclear if you’re leveraging semantic HTML tags properly, especially for navigation elements like buttons or anchor links.
    • Why it matters: Semantic tags are like using clear labels on jars in your kitchen—they tell browsers and assistive technologies what each element does. For example:
      • <button> is for actions like submitting a form.
      • <a> is for navigation to another page or section.
    • Use-Case Example: If you're creating a card with a "Read More" button, use <a> for linking to another page and <button> for triggering JavaScript actions like toggling content.

    Refactored Example:

    <!-- Use <a> for navigation -->
    <a href="/more-info" class="card-button">Read More</a>
    
    <!-- Use <button> for actions -->
    <button onclick="toggleContent()">Show Details</button>
    

    4. Understand grid usage

    • Observation: You're using unnecessary grid-row and grid-column properties in several classes like .cardimg, .cardtitle, etc.
    • Why it matters: Over-using these properties can complicate your layout. Think of it like over-planning every step of a walk when a simple path exists—it's extra work for no added value.
    • Suggestion: Remove unused grid properties unless you're explicitly positioning items.

    Refactored Example:

    .cardtitle {
      width: max-content;
      padding: 5px 20px;
      border-radius: 5px;
      font-size: 16px;
      background-color: hsl(47, 88%, 63%);
      font-weight: 800;
    }
    

    Closing Thoughts 🌟

    Simplifying and cleaning up your code not only enhances readability but also saves development time in the long run. As you build more projects, keeping these best practices in mind will ensure you're writing efficient and maintainable code.

    Let me know if you need further clarification or assistance! 😊

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub