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
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>
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>
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>
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>
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>
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>
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>
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>
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>
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