Giter VIP home page Giter VIP logo

code-refactor's Introduction

Code Refactor - Accessibilty Standards

Technology Used

Technology Used Resource URL
html HTML https://developer.mozilla.org/en-US/docs/Web/HTML
css CSS https://developer.mozilla.org/en-US/docs/Web/CSS
git Git https://git-scm.com/

Description

Visit the Deployed Site

This project is an introduction to code refactoring and the importance of creating websites that adhere to accessibilty standards. I was given starter code (HTML and CSS) to analyze, refactor, and deploy the finished product on github pages.

Web accessibility is an increasingly important consideration for businesses. It ensures that people with disabilities can access a website using assistive technologies such as video captions, screen readers, and braille keyboards. Making a website accessible is also good for business for many reasons, one of them being that accessible sites are better positioned in search engines like Google. It also helps companies avoid litigation that can occur when people with disabilities can't access their website.

Code Refactor Example

The below HTML code does not include any semantic elements and is poorly constructed.

    <div class="content">
        <div class="search-engine-optimization">
            <img src="./assets/images/search-engine-optimization.jpg" class="float-left" />
            <h2>Search Engine Optimization</h2>
            <p>
                Place text here
            </p>
        </div>
        <div id="online-reputation-management" class="online-reputation-management">
            <img src="./assets/images/online-reputation-management.jpg" class="float-right" />
            <h2>Online Reputation Management</h2>
            <p>
                Place text here
            </p>
        </div>
        <div id="social-media-marketing" class="social-media-marketing">
            <img src="./assets/images/social-media-marketing.jpg" class="float-left" />
            <h2>Social Media Marketing</h2>
            <p>
                Place text here
            </p>
        </div>

Converting the above non-semantic div with the class of 'content' to a semantic main tag and changing child div tags to semantic article tags (Semantic Elements).

    <main class="content">
        <article>
            <img src="./assets/images/search-engine-optimization.jpg" class="float-left" alt="search engine optimization image"/>
            <h2>Search Engine Optimization</h2>
            <p>
                Place text here
            </p>
        </article>
        <article>
            <img src="./assets/images/online-reputation-management.jpg" class="float-right" alt="online reputation management image"/>
            <h2>Online Reputation Management</h2>
            <p>
                Place text here
            </p>
        </article>
        <article>
            <img src="./assets/images/social-media-marketing.jpg" class="float-left" alt="social media marketing image"/>
            <h2>Social Media Marketing</h2>
            <p>
                Place text here
            </p>
        </article>
    </main>

This change allowed us to delete unnecessary html class elements and their associated css selectors.

.search-engine-optimization {
    margin-bottom: 20px;
    padding: 50px;
    height: 300px;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    background-color: #0072bb;
    color: #ffffff;
}

.online-reputation-management {
    margin-bottom: 20px;
    padding: 50px;
    height: 300px;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    background-color: #0072bb;
    color: #ffffff;
}

.social-media-marketing {
    margin-bottom: 20px;
    padding: 50px;
    height: 300px;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    background-color: #0072bb;
    color: #ffffff;
}

.search-engine-optimization img {
    max-height: 200px;
}

.online-reputation-management img {
    max-height: 200px;
}

.social-media-marketing img {
    max-height: 200px;
}

.search-engine-optimization h2 {
    margin-bottom: 20px;
    font-size: 36px;
}

.online-reputation-management h2 {
    margin-bottom: 20px;
    font-size: 36px;
}

.social-media-marketing h2 {
    margin-bottom: 20px;
    font-size: 36px;
}

Now we can avoid code redundancy by utilizing the article and img tags.

.content article {
    margin-bottom: 20px;
    padding: 50px;
    height: 300px;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    background-color: #0072bb;
    color: #ffffff;
}

.content img {
    max-height: 200px;
}

.content h2 {
    margin-bottom: 20px;
    font-size: 36px;
}

Learning Points

  • Writing HTML code with semantic elements can greatly improve code readability and site performance
  • Looking for code redunancy is a great starting place for refactoring code
  • A clear understanding of how each piece of code interacts with each other is required before any modifications are made
  • There is always an opportunity to improve your code even if the overall functionality is the same

code-refactor's People

Contributors

mccoydidericksen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.