Triangle with One Rounded Corner

Triangle with one rounded corner

I know this is a little hacky, but I don't think there is an easy way to do this with a single class.

All I've done is rotated a box 45 degrees with border-radius:10px and then contained it in another div with width set to the desired width of your arrow and overflow:hidden so that everything that spills over is invisible.

.arrow-left {  position: absolute;  width: 100px;  height: 100px;  left: 20px;  background: black;  -webkit-transform: rotate(45deg);  transform: rotate(45deg);  border-radius: 10px;}
.cover { position: absolute; height: 100px; width: 40px; overflow: hidden;}
<div class="cover">  <div class="arrow-left"></div></div>

How to draw a triangle with one rounded corner programatically with SVG?

There are several ways to do it, depending on what sort of curve you want. The simplest way is probably to use Q/q as you were attempting.

Calculate the endpoints, leading into and out of the curve, by calculating a position along that line segment. For instance in the second SVG I have chosen a point 80% along the first line (20,120 -> 70,20).

x = x0 + 80% * (x1 - x0)
= 20 + 80% * (70 - 20)
= 60

y = y0 + 80% * (y1 - y0)
= 120 + 80% * (20 - 120)
= 120 + -80
= 40

and the same for the line exiting the curved corner. Except, of course this time it will only be 20% aaway from the corner.

Once you have those two points, just use the original corner point as the control point (first coordinate pair) in the Q command.

So the original corner

M 20,120
L 70,20
L 120,120

becomes

M 20 120
L 60 40
Q 70 20 80 40
L 120 120

As shown in the third SVG below.

<p>Triangle</p><svg height="200" width="200" style="margin: 20px">  <path d="M 20 120           L 70 20           L 120 120               Z"         fill="LightBlue"         stroke="Blue"         stroke-width="10" /> </svg>
<svg height="200" width="200" style="margin: 20px"> <path d="M 20 120 L 60 40 L 80 40 L 120 120 Z" fill="LightBlue" stroke="Blue" stroke-width="10" /> </svg>
<svg height="200" width="200" style="margin: 20px"> <path d="M 20 120 L 60 40 Q 70 20 80 40 L 120 120 Z" fill="LightBlue" stroke="Blue" stroke-width="10" /> </svg>

css rounded corner of right angled triangle

Here is an idea where you can rely on 2 pseudo element and some background coloration to approximate it. You simply need to find the correct value to have the perfect overlap between both pseudo elements.

h1 {  padding-left:1em;  position:relative;}
h1:before { content: ""; position:absolute; left: 0; top: calc(50% - 0.35em); width: 0.7em; height: 0.7em; background: linear-gradient(to bottom left, #34495e 50%, transparent 50%); border-radius: 0.1em;}h1:after { content: ""; position: absolute; left: 3.8px; top: -0.1px; width: 0.92em; height: 0.8em; margin-right: 10px; background: linear-gradient(to top,#34495e 3.5px,transparent 5px); border-radius: 0.1em; transform: rotate(45deg); z-index: -1;}
<h1>Heading</h1>

css3 triangle shape with one rounded corner

One solution that appears to work (tested in Chrome, Safari, Firefox) is removing the following lines from .triangle-topright

-webkit-border-top-right-radius: 6px 6px;
-moz-border-radius-topright: 6px / 6px;
-khtml-border-top-right-radius: 6px / 6px;
border-top-right-radius: 6px / 6px;

And instead simply adding overflow: hidden; to the .box css.

Demo: http://jsfiddle.net/BcrKH/

Is it possible to make a rounded triangle with just CSS?

To actually answer your question (and provide the first answer without border-radius): If you want a CSS only solution, you will have to use border-radius.

Nevertheless I would highly recommend to use SVG for creating shapes, as simple shapes like this are easy to create manually, it's responsive, it's widely supported now and (as @chharvey mentioned in the comments) semantically more appropriate.

<svg viewbox="0 0 50 50" height="56px">  <path d="M1 50 V10 Q1 1 10 1 H50z" fill="#ff4369" /></svg>

How to make 3-corner-rounded triangle in CSS

My best attempt: http://dabblet.com/gist/4592062
final

Pixel perfection at any size, uses simpler math than Ana's original solution, and is more intuitive in my opinion :)

.triangle { position: relative; background-color: orange; text-align: left;}.triangle:before,.triangle:after { content: ''; position: absolute; background-color: inherit;}.triangle,.triangle:before,.triangle:after { width:  10em; height: 10em; border-top-right-radius: 30%;}
.triangle { transform: rotate(-60deg) skewX(-30deg) scale(1,.866);}.triangle:before { transform: rotate(-135deg) skewX(-45deg) scale(1.414,.707) translate(0,-50%);}.triangle:after { transform: rotate(135deg) skewY(-45deg) scale(.707,1.414) translate(50%);}
<div class="triangle"></div>

triangle with rounded corners

rotate + overflow would do (with an extra element or a pseudo):

.tr {  height:40px;  width:40px;  overflow:hidden;  transform:scale(1,1.2);/* increase visual height */  }.tr div {/* could be a pseudo */  width:70%;  height:70%;  float:right;  background:#C20009;  transform:rotate(-45deg);  box-shadow: 0 0 1px, inset 0 1px 1px , inset 5px -5px 5px rgba(0,0,0,0.3);  transform-origin: top right;  border-radius : 8px 0 0 0 /* and the rounded corner to finish */  }
<div class="tr">  <div></div></div>

Create triangle with rounded corners at top of bottomsheet

You can achieve this using a MaterialShapeDrawable with a custom ShapeAppearanceModel.

1. Get the latest Material Design Library and add it into your app grandle dependencies (implementation 'com.google.android.material:material:1.4.0')

2. In your Bottom Sheet xml file define an empty View (eg: a Relative Layout) which will be the top of your Bottom Sheet. A sample will be like below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottomSheetParentRL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">

<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"/>

</RelativeLayout>

3. Finally create your custom ShapeAppearanceModel with Rounded Corners only to the Top Left Side and use a custom EdgeTreatment for the TopEdge to draw the above triangle shape using the ShapePath.quadToPoint method like in the below example:

JAVA:

//get the Relative Layout or any other View
RelativeLayout relativeLayout = findViewById(R.id.relativeLayout);

//set the top left corner radius and bottom Y margin in pixels
int topLeftCornerRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics());
int bottomYMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, getResources().getDisplayMetrics());

//create a new ShapeAppearanceModel
ShapeAppearanceModel shapeAppearanceModel = new ShapeAppearanceModel()
.toBuilder()
.setTopLeftCorner(CornerFamily.ROUNDED, topLeftCornerRadius)
.setTopRightCorner(CornerFamily.ROUNDED, 0)
.setBottomLeftCorner(CornerFamily.ROUNDED, 0)
.setBottomRightCorner(CornerFamily.ROUNDED, 0)
.setTopEdge(new EdgeTreatment(){
@Override public void getEdgePath(float length, float center, float interpolation, @NonNull ShapePath shapePath) {
shapePath.quadToPoint(0, 0, length, relativeLayout.getLayoutParams().height - bottomYMargin);
}
})
.build();

//create a new MaterialShapeDrawable based on above ShapeAppearanceModel and sets it color
MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
shapeDrawable.setFillColor(ContextCompat.getColorStateList(this, android.R.color.holo_blue_light));

//finally use the ViewCompat static method to draw the above shapeDrawable to relativeLayout
ViewCompat.setBackground(relativeLayout, shapeDrawable);

KOTLIN:

//get the Relative Layout or any other View
val relativeLayout = findViewById<RelativeLayout>(R.id.relativeLayout)

//set the top left corner radius and bottom Y margin in pixels
val topLeftCornerRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20f, resources.displayMetrics).toInt()
val bottomYMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25f, resources.displayMetrics).toInt()

//create a new ShapeAppearanceModel
val shapeAppearanceModel = ShapeAppearanceModel()
.toBuilder()
.setTopLeftCorner(CornerFamily.ROUNDED, topLeftCornerRadius.toFloat())
.setTopRightCorner(CornerFamily.ROUNDED, 0f)
.setBottomLeftCorner(CornerFamily.ROUNDED, 0f)
.setBottomRightCorner(CornerFamily.ROUNDED, 0f)
.setTopEdge(object : EdgeTreatment() {
override fun getEdgePath(length: Float, center: Float, interpolation: Float, shapePath: ShapePath) {
shapePath.quadToPoint(0f, 0f, length, (relativeLayout.layoutParams.height - bottomYMargin).toFloat())
}
})
.build()

//create a new MaterialShapeDrawable based on above ShapeAppearanceModel and sets it color
val shapeDrawable = MaterialShapeDrawable(shapeAppearanceModel)
shapeDrawable.fillColor = ContextCompat.getColorStateList(this, android.R.color.holo_blue_light)

//finally use the ViewCompat static method to draw the above shapeDrawable to relativeLayout
ViewCompat.setBackground(relativeLayout, shapeDrawable)

Result:

shape



Related Topics



Leave a reply



Submit