How to create triangle shape in the top-right angle of another div to look divided by border (2024)

To create a triangle shape in the top-right angle of another div in HTML/CSS, you can use CSS pseudo-elements and borders to achieve the effect. Here's how you can do it:

HTML:

<div class="container"> <div class="triangle"></div></div>

CSS:

.container { position: relative; width: 200px; height: 200px; background-color: #f0f0f0;}.triangle { position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 30px solid transparent; border-bottom: 30px solid #f0f0f0; /* Same as background color of the container */}

This CSS creates a right triangle in the top-right corner of the container div. Adjust the values (such as the size of the triangle) to fit your design requirements.

If you want the triangle to appear divided by a border, you can add a border to the right and top sides of the triangle element:

.triangle { position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 30px solid transparent; border-bottom: 30px solid #f0f0f0; /* Same as background color of the container */ border-right: 30px solid #000; /* Color of the border */ border-top: 30px solid #000; /* Color of the border */}

This will create a triangle shape in the top-right angle of the container, divided by a border on the top and right sides. Adjust the border colors and sizes as needed.

Examples

  1. HTML CSS Create Triangle in Top-Right Corner of Div

    Description: This example creates a triangle shape in the top-right corner of a div using CSS pseudo-elements.

    <style>.container { position: relative; width: 200px; height: 200px; border: 2px solid black;}.triangle { position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 20px solid transparent; border-bottom: 20px solid black;}</style><div class="container"> <div class="triangle"></div></div>
  2. CSS Triangle Shape Top-Right Corner of Div

    Description: This code uses a pseudo-element to create a triangle shape in the top-right corner of a div.

    <style>.container { position: relative; width: 250px; height: 250px; background-color: lightblue; border: 2px solid #000;}.container::after { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 30px solid transparent; border-bottom: 30px solid #000;}</style><div class="container"></div>
  3. Create Top-Right Corner Triangle with Border in HTML CSS

    Description: Adding a triangle in the top-right corner of a div using CSS, styled to look like part of the border.

    <style>.container { position: relative; width: 300px; height: 300px; border: 2px solid blue;}.container::before { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 25px solid transparent; border-bottom: 25px solid blue;}</style><div class="container"></div>
  4. HTML Add Triangle to Corner of Div with Border

    Description: This example demonstrates how to add a triangle to the top-right corner of a div using CSS pseudo-elements.

    <style>.box { position: relative; width: 200px; height: 200px; border: 3px solid green;}.box::before { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 20px solid transparent; border-bottom: 20px solid green;}</style><div class="box"></div>
  5. CSS Trick for Top-Right Corner Triangle in Div

    Description: Utilizing a CSS trick to create a top-right corner triangle within a div.

    <style>.wrapper { position: relative; width: 250px; height: 250px; border: 2px solid red;}.wrapper::after { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 20px solid transparent; border-bottom: 20px solid red;}</style><div class="wrapper"></div>
  6. HTML CSS Corner Triangle Shape in Div

    Description: Creating a triangle shape in the corner of a div using CSS pseudo-elements and positioning.

    <style>.outer { position: relative; width: 180px; height: 180px; border: 2px solid purple;}.outer::before { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 15px solid transparent; border-bottom: 15px solid purple;}</style><div class="outer"></div>
  7. CSS Create Border-Divided Triangle in Corner of Div

    Description: This CSS creates a border-divided triangle in the top-right corner of a div to make it appear as part of the border.

    <style>.block { position: relative; width: 220px; height: 220px; border: 2px solid orange;}.block::after { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 25px solid transparent; border-bottom: 25px solid orange;}</style><div class="block"></div>
  8. How to Add Corner Triangle to Div in HTML CSS

    Description: Demonstrating how to add a triangle to the corner of a div using CSS for visual effects.

    <style>.panel { position: relative; width: 260px; height: 260px; border: 2px solid pink;}.panel::before { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 30px solid transparent; border-bottom: 30px solid pink;}</style><div class="panel"></div>
  9. CSS Triangle Shape Top-Right Corner Effect

    Description: Applying a top-right corner triangle effect to a div using CSS.

    <style>.frame { position: relative; width: 240px; height: 240px; border: 2px solid teal;}.frame::after { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 20px solid transparent; border-bottom: 20px solid teal;}</style><div class="frame"></div>
  10. HTML CSS Triangle in Div Corner Border Divided

    Description: Creating a triangle in the top-right corner of a div with the appearance of a divided border using CSS.

    <style>.box { position: relative; width: 280px; height: 280px; border: 2px solid navy;}.box::before { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-left: 20px solid transparent; border-bottom: 20px solid navy;}</style><div class="box"></div>

More Tags

odbcacrobatlong-longoperating-systemaiohttphorizontalscrollviewserializationentitydecodeportrait

More Programming Questions

  • Django Admin Interface
  • Difference Between @Component, @Repository, @Service, and @Controller Annotations in Spring
  • Django Cache System
  • C# Directoryinfo Class: Folder Operations
  • Setting the OutputPath property of a project via Visual Studio Automation
  • Disable link to edit object in django's admin (display list only)?
  • Add lines to existing file using Python
  • Find out how much memory is being used by an object in Python
  • Set max value for color bar on seaborn heatmap
How to create triangle shape in the top-right angle of another div to look divided by border (2024)
Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 6547

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.