DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Subtitles: The Good, the Bad, and the Resource-Heavy
  • Loader Animations Using Anime.js
  • Next.js Theming: CSS Variables for Adaptive Data Visualization
  • Creating Scrolling Text With HTML, CSS, and JavaScript

Trending

  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • Agile and Quality Engineering: A Holistic Perspective
  • Top Book Picks for Site Reliability Engineers
  1. DZone
  2. Coding
  3. Languages
  4. Create a Flag With CSS

Create a Flag With CSS

Corner flags are a nice way of labeling an image to emphasize something is 'new', 'featured' or 'on offer'. Often these effects are done with images. This tutorial gives an example of how to achieve this using CSS and semantic HTML.

By 
$$anonymous$$ user avatar
$$anonymous$$
·
Jul. 29, 16 · Code Snippet
Likes (3)
Comment
Save
Tweet
Share
10.3K Views

Join the DZone community and get the full member experience.

Join For Free

Corner flags are a nice way of labelling an image to emphasise something is 'new', 'featured' or 'on offer'. Often these effects are done with images. This tutorial gives an example of how to achieve this using CSS and semantic HTML.

Demo: Image flag

Example HTML

Our markup is straightforward and semantic. Requiring two elements: one for the corner flag and the other for the text.

<p><span>Popular</span></p>

The flag is positioned absolutely so just needs to be contained to achieve the correct results.

<article>
    <img src="bacon.jpg"/>
    <h2>Some title</h2>
    <p><span>New!</span></p>
</article>

Example Code

/**
 *   Flag component
 */

.flag {
    position: absolute;
    top: 0;
    left: 0;
}

/**
 * The traingle shape of the flag.
 * 1. The size of the triangle.
 */  
.flag:before { 
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    border-style: solid;
    border-width: 34px;     /* [1] */
}

/*
 * Rotate the text and position it.
 * 1. Put on the GPU to ensure the text is rendered correctly
 */
.flag-text {
    -moz-transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    -o-transform: rotate(-45deg);
    -webkit-transform: rotate(-45deg) translateZ(0);    /* [1] */
    transform: rotate(-45deg) translateZ(0);
    color: #FFF;
    display: inline-block;
    position: absolute;
    top: 18px;
    left: 0;
    z-index: 1;
    font-size: 12px;
    text-transform: uppercase;
    width: 50px;
    text-align: center;
}

/*
 * Modifier classes for different colour flags
 */
.flag.is-new:before {
    border-color: rgba(4,120,0,.9) transparent transparent rgba(4,120,0,.9);
}

.flag.is-popular:before {
    border-color: rgba(206,3,5,.7) transparent transparent rgba(206,3,5,.7);
}
CSS

Published at DZone with permission of $$anonymous$$, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Subtitles: The Good, the Bad, and the Resource-Heavy
  • Loader Animations Using Anime.js
  • Next.js Theming: CSS Variables for Adaptive Data Visualization
  • Creating Scrolling Text With HTML, CSS, and JavaScript

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!