Double curved shape
Considering :
- the amount of code needed
- the hassle of aligning double curves
CSS doesn't seem to be the way to go here and SVG way more appropriate. To illustrate, see these two snippets :
SVG
DEMO
/*** FOR THE DEMO **/svg{ display:block; width:70%; margin:0 auto; opacity:0.8;}body{ background: url('http://lorempixel.com/output/people-q-g-640-480-7.jpg'); background-size:cover;}
<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 80"> <path stroke-width="1" stroke="#000" fill="grey" d="M95 5 Q70 20 70 38 T50 65 Q55 50 30 40 T5 5z"/></svg>
Draw double curved item with beveled edges
I created 2 SVG
examples so you can choose where to apply the background
Codepen demo
The outer container of each SVG
element keeps a specific aspect ratio so the whole element can be responsive (but, of course, you can also specify a fixed width or height).
The basic idea is to create a path
that overflows the size of the SVG
element, so you can define a closed shape on the top area or on the bottom area, in order to fill it with a colour (if you enlarged the viewbox
e.g. to -10 -10 610 130
you could see how the path is actually defined).
The applied background is a gradient but you can also specify a single color-stop (white, in your specific scenario). The background on the body element shows the transparent parts of the SVG
.
Fine tuning and adjustment of curves, viewbox, colours is left to the reader.
For any change to the shape you can read the path documentation on MDN
Markup
<div class="doublecurve">
<svg viewBox="0 0 600 120" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#d8e5f1" />
<stop offset="100%" stop-color="#91b4d3" />
</linearGradient>
</defs>
<path class="concave" fill="url(#gradient)" d="M-2 2
L75 2 A75 75 0 0 1 110 20 C200 100 400 100 480 20
A75 75 0 0 1 525 2 L602 2 L602 122 L-2 122 z"/>
</svg>
</div>
<div class="doublecurve">
<svg viewBox="0 0 600 120" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#d8e5f1"/>
<stop offset="100%" stop-color="#91b4d3"/>
</linearGradient>
</defs>
<path class="concave" fill="url(#gradient)" d="M-2 2
L75 2 A75 75 0 0 1 110 20 C200 100 400 100 480 20
A75 75 0 0 1 525 2 L602 2 L602 -2 L-2-2"/>
</svg>
</div>
CSS
.doublecurve {
width: 100%;
height: 0;
margin: 20px 0;
border: 1px dashed #bc9;
padding-bottom: 20%;
position: relative; }
.doublecurve svg {
position: absolute;
width: 100%; height: 100%;}
.doublecurve path.concave {
stroke: #d0d0d0;
stroke-width: 4px;}
Final Result
Creating s-shaped curve using css
SVG
As Harry suggested in the comments, SVG would be your best option as a double curve in CSS isn't feasible without using multiple elements, pseudo elements or using possibly unsupported CSS3 properties.
SVG stands for Scalable Vector Graphic. The web browser views it as an image but you can add text and normal HTML elements within an SVG.
It is well supported across all browsers as viewable here: CanIUse
<svg width="466" height="603" viewbox="0 0 100 100" preserveAspectRatio="none"> <path d="M0,0 L100,0 C25,50 50,75 0,100z" fill="#8aa7ca" /></svg>
How to draw a curved line between 2 points on canvas?
I found a solution to my problem myself. Even though there were some great answers, they weren't an exact solution to my particular problem.
Here is what I did:
- Found the point in between the 2 given points
- Calculated the angle 90 degrees between the 2 points
- Calculated the point X pixels from the middle point using the calculated degree from before.
- Used "path.cubicTo" with these 3 points (Takes both negative and positive values to determine which way the line should curve).
Here is my code if anyone else should run into the same problem:
public OverlayBuilder drawCurvedArrow(int x1, int y1, int x2, int y2, int curveRadius, int color, int lineWidth) {
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(lineWidth);
paint.setColor(ContextCompat.getColor(context, color));
final Path path = new Path();
int midX = x1 + ((x2 - x1) / 2);
int midY = y1 + ((y2 - y1) / 2);
float xDiff = midX - x1;
float yDiff = midY - y1;
double angle = (Math.atan2(yDiff, xDiff) * (180 / Math.PI)) - 90;
double angleRadians = Math.toRadians(angle);
float pointX = (float) (midX + curveRadius * Math.cos(angleRadians));
float pointY = (float) (midY + curveRadius * Math.sin(angleRadians));
path.moveTo(x1, y1);
path.cubicTo(x1,y1,pointX, pointY, x2, y2);
canvas.drawPath(path, paint);
return this;
}
And here is an example of how the implementation looks like:
Related Topics
:Active CSS Selector Not Working for IE8 and IE9
Less: Unrecognized Input Error When Using Bootstrap
Background with 2 Colors in Javafx
How to Change Color of Icons in Font Awesome 5
Bootstrap Change Order of Columns
Stacking Order of Elements Affected by Opacity
What Is This CSS Selector? [Class*="Span"]
Why Can't I Save CSS Changes in Firebug
Suggestions for Debugging Print Stylesheets
Using Font Awesome Icon for Bullet Points, with a Single List Item Element
How to Make Select Element Be Transparent in Chrome
How to Change Bootstrap Version 4 Button Color
How Is Padding-Top as a Percentage Related to the Parent's Width
Pseudo Elements and Select Tag
Hide Scrollable Content Behind Transparent Fixed Position Divs When Scrolling the Page