Create a rounded arrow - html

I am trying to make an arrow that looks like this:
However, this is the closest I can get to it:
.button {
margin: 4em 0;
padding: 2em;
width: 15%;
margin: 0 auto;
text-align: center;
background-color: #000000;
color: #ffffff;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-moz-flex-flow: row wrap;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
webkit-justify-content: center;
justify-content: center;
}
.curved-arrow {
display: inline-block;
border-top: 10px solid #fff;
border-bottom: 10px solid #fff;
border-left: 30px solid #fff;
border-top-right-radius: 100%;
border-bottom-right-radius: 100%;
}
<div class="button">
<div class="curved-arrow"></div>
</div>
Is this even possible? I know I can use images, but my designer made several of these in multiple colors to use throughout the site that I'd rather just use CSS for the shape.
If it's hard to see it's a flat straight line from top to bottom on the left, and curves in to the middle on the right.

SVG
CSS border radius won't let you get the exact output you are looking for easily. I would suggest an inline SVG with the path element with one quadratic bezier command :
svg{width:100px;}
<svg viewbox="0 0 20 8">
<path d="M0 0 Q 30 4 0 8" />
</svg>
Then you can color the arrow with the CSS fill property, see this fiddle (credits to #Nick R for the example posted in the comments)
CSS
You can also use the 2 values for the border-radius property (see MDN for an explanation of how it works) it is simple but it won't let you make the arrow 'point' as sharp as it is in your image :
.curved-arrow {
width:40px; height:25px;
background:#000;
border-top-right-radius:100% 50%;
border-bottom-right-radius:100% 50%;
}
<div class="curved-arrow"></div>

CSS
This requires just a bit of fancy border-radius styling to achieve the shape you want.
.container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
.arrow {
width: 50px;
height: 30px;
position: absolute;
top: 32px;
left: 25%;
border-radius: 0px 100% 100% 0px / 0 50% 50% 0;
background: white;
}
<div class="container">
<div class="arrow"></div>
</div>
If you want it in a single element, you can just use a psuedo element like so.
.arrow {
width: 100px;
height: 100px;
background: red;
position: relative;
}
.arrow:before {
content: '';
width: 50px;
height: 30px;
position: absolute;
top: 32px;
left: 25%;
border-radius: 0px 100% 100% 0px / 0 50% 50% 0;
background: white;
}
<div class="arrow"></div>
SVG
A good alternative would also be SVG to create this shape which also makes it fully responsive.
<svg width="100px" height="100px" viewbox="0 0 20 20" style="background: red;">
<path d="M5,7
Q15,7 15,10
Q15,13 5,13z" fill="white"></path>
</svg>

I think I've made something quite similar, maybe you could change some margins/widths or heights:
#arrow{
display: block;
box-sizing: content-box;
float: none;
width: 130px;
height: 50px;
top: auto;
right: auto;
bottom: auto;
left: auto;
margin: 0;
padding: 0;
overflow: visible;
outline: none;
border: 0 solid rgba(0,0,0,1);
-webkit-border-radius: 50%;
border-radius: 50%;
background: #1abc9c;
box-shadow: none;
text-shadow: none;
margin-left:-65px;
}
#arrow:after {
position:absolute;
left:-65px;
width:65px;
background:transparent;
content:'';
}
It should be an oval, which i hide by an half by using :after ( quite dirty trick )
js fiddle
However, I would recomend you to use CSS sprites, I guess they should fit best your situation, because CSS shapes are not that easy to read for browsers.
Hope it helps! :)

Here's my take on it. Not quite as sharp a point as I'd like, but it's a little bit closer. Edit: second take uses two pseudo-elements to help sharpen the angle.
.button { margin: 4em 0; padding: 2em; width: 15%; margin: 0 auto; text-align: center; background-color: #000000; color: #ffffff; isplay: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -moz-flex-flow:row wrap; -webkit-flex-flow:row wrap; -ms-flex-flow:row wrap; flex-flow:row wrap; webkit-justify-content: center; justify-content: center; }
.curved-arrow {
position: relative;
display: inline-block;
height: 36px;
width: 56px;
overflow: hidden;
}
.curved-arrow:after {
content: '';
position: absolute;
right: 0;
top: 0;
border-radius: 0 100% 0 0;
height: 50%;
width: 200%;
background: #FFF;
}
.curved-arrow:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
border-radius: 0 0 100% 0;
height: 50%;
width: 200%;
background: #FFF;
}
<div class="button">
<div class="curved-arrow"></div>
</div>

Something like this?
#arrow-base {
width: 120px;
height: 80px;
background: red;
}
#arrow {
width: 0;
height: 0;
border-top: 16px solid transparent;
border-bottom: 16px solid transparent;
border-left: 32px solid white;
display: inline-block;
margin: 24px 44px;
border-radius: 2px;
}
<div id="arrow-base">
<div id="arrow">
<!-- should be empty -->
</div>
</div>

Related

How to put background image directly to a div

I have a div like this:
Now I need to remove a part of the circle from this shape which is shown as below:
Therefore the final shape would be looked like this:
So I decided to put the image as the background of my div.
<div class="col-4 customBack">
<div class="mainInfo">
<div class="circle2">
<img src="https://sitename.com/images/image.png">
</div>
<div class="paraDivRight2">
<h6 style="margin-top:5px;"><strong>Lorem Ipsum Dolor Simit</strong></h6>
<hr style="margin-top:-5px;">
<p style="margin-top:-10px;">012-3456789</p>
<p style="padding-top:5px;">ifno#sitename.com</p>
</div>
</div>
</div>
And here are the styles:
.mainInfo{
background-color: #fff;
border: .01rem round #e0e1ed;
border-radius: 20px;
color: #585CA1;
width:100%;
height:5em;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
margin-top: 3em;
display: flex;
align-items: center;
justify-content: center;
}
.customBack{
background-image: url("/img/shadow3.png") !important;
}
.circle2 {
position: relative;
left:-60%;
width: 9em;
height: 9em;
background: #fff;
border-radius: 50%;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.65);
}
.circle2 img {
position: absolute;
max-width: 85%;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 100;
}
.paraDivRight2 {
position: absolute;
display: inline-block;
padding: 10px;
color:black;
top:0px !important;
padding-top:50px !important;
right: 20px;
text-align: right;
padding-right:50px !important;
}
.paraDivRight2 p {
line-height: 1em;
font-size: 10pt;
margin: 0;
letter-spacing: 1px;
}
As you can see I have put the background in .customBack class But the result is now looks like this:
So the question is, how can I properly place this background image which is (shadow3.png) as background image of this mainInfo div so the side of circle shape that needs to be removed, does not appear...
I'm really stuck with this, so please help me out...
Use CSS filter: drop-shadow() MDN Docs on a wrapper element.
Fix your class naming to use a friendlier convention
Use CSS flex for a simpler alignment of your elements
Stop using inline HTML style attributes
/* Quick Reset */
* {
margin: 0;
box-sizing: border-box;
}
.custom {
filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.4));
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.custom-image {
width: 9em;
height: 9em;
background: #fff;
border-radius: 50%;
padding: 1em;
}
.custom-image img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 50%;
}
.custom-content {
position: relative;
background: #fff;
padding: 1em;
text-align: right;
border-radius: 0 1em 1em 0;
padding-left: 2em;
left: -1em;
}
.custom-content h4 {
border-bottom: 1px solid #ddd;
}
<div class="custom">
<div class="custom-image">
<img src="https://i.stack.imgur.com/qCWYU.jpg?s=256&g=1">
</div>
<div class="custom-content">
<h4>Lorem Ipsum Dolor Simit</h4>
<p>012-3456789</p>
<p>ifno#sitename.com</p>
</div>
</div>
I'm not 100% sure about this but it has worked for me in the past,try making the position attribute of the div relative and make it absolute for the image,then size it properly.

Make element with position: absolute stretch the shadow of parent?

I have a usual search as most websites do. The results are shown below on the div that is visually connected to the search input.
It looks like this:
I need to have one solid shadow for the div parent but can't figure out or find online the way to do this.
I thought that I could either make 2 separate shadows, but that will look inconsistent and just terrible. Or I could make a div below with the same height and width that will act as a shadow but that's a non-necessary complication + the .search-results div's height will change dynamically.
This is an example:
body {
background-color: gray;
}
.search-wrapper {
position: relative;
margin: 100px 100px 0px 100px;
width: 200px;
overflow: initial;
box-shadow: 0px 0px 10px 10px rgba(0,0,0,0.3);
}
.search {
width: 200px;
height: 30px;
color: white;
border-radius: 4px;
} .search input {
padding: 0;
background-color: #022222;
border: none;
height: 100%;
width: 100%;
color: white;
}
.search-results {
position: absolute;
height: 150px;
width: 200px;
background-color: black;
}
<div class="search-wrapper">
<div class="search">
<input placeholder="air max . . .">
</div>
<div class="search-results">
</div>
</div>
I am sure there must be a clever and simple way to do this.
Please help,
Thank you
You don't need to use positions here and you can use FlexBox instead. It's the best way and a lot easier. Also, you can ignore all of them, they will place on top of each other because they are block-level tags/elements. (divs)
You don't need to put the input in another div parent, use it as I did.
Sorry, I couldn't understand your code, so I must write the whole code from the beginning.
EDIT
I removed display flex, cause it's not necessary.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: Arial;
border-radius: 10px;
background-color: #fff
}
body {
height: 100vh;
background-color: gray;
padding: 30px
}
.search-wrapper {
/* EDITED HERE ADDED HEIGHT */
position: relative;
z-index: 999;
width: 200px;
height: 160px;
box-shadow: 0 0 2px 5px rgba(232, 232, 232, .2)
}
.search-input {
width: 100%;
position: absolute;
padding-block: 5px;
border: none;
outline: none;
padding: 15px
}
.search-result {
/* EDITED HERE */
position: absolute;
z-index: 999;
bottom: 0;
width: 100%;
padding: .5px
}
p {
padding: 10px 0 10px 10px;
}
p:hover {
background-color: #e8e8e8;
cursor: pointer
}
<div class='search-wrapper'>
<input class='search-input' placeholder='Search...'>
<div class='search-result'>
<p>Nike Airforce</p>
<p>Nike Airforce</p>
<p>Nike Airforce</p>
</div>
</div>

Phantom Border on Element

I have a filled circle and a child element. I want the child ele to be 'attached' to the circle on the left. But I don't want this ele to have a visible border on its right edge.
I'm not sure why, but when these two eles are overlapped, the child ele has this faint kind of dashed border on the right.
body {
height: 900px;
width: 1600px;
zoom: 500%;
}
.container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
}
.circle {
position: absolute;
/* border: solid 3px black; */
background: yellow;
width: 300px;
height: 300px;
border-radius: 100%;
display: flex;
align-items: center;
}
.arc {
position: absolute;
width: 29%;
height: 25%;
background-color: yellow;
transform: translate(-68%, 15%) rotate(-24deg);
border-radius: 100% 0% 0% 100%;
/* Changing the last num to 0 gets rid
of the phantom border..? */
border-width: 3px 0px 3px 3px;
border-color: black;
border-style: solid;
/* Padding 1px works to get rid of it when the element isnt rotated */
padding: 1px;
}
<div class="container">
<div class="circle">
<div class="arc"></div>
</div>
</div>
https://codepen.io/CoreyBuckley/pen/ZEWKMaZ
Help on why this is occurring and how to get rid of it is much appreciated!
If nothing else works hide it indirectly with a pseudo element, matching the colour at the edge seems to sort out what appears to be an aliasing problem Edit: I checked setting DPI scaling to 100% it doesnt appear to be linked with that.
.arc:before {
content: ' ';
display: block;
position: absolute;
right: 0;
top: 0;
width: 1px;
height: 100%;
background-color: yellow;
}

How add border inside div? [duplicate]

I would like to add a white border over all my images in my content div using css. Images in the header and footer div areas should not be affected. how do I achieve this? See example image below. There are images of different sizes on the web pages.
See image:
You can do this without having an extra element or pseudo element:
http://cssdeck.com/labs/t6nd0h9p
img {
outline: 1px solid white;
outline-offset: -4px;
}
IE9&10 do not support the outline-offset property, but otherwise support is good: http://caniuse.com/#search=outline
Alternate solution that doesn't require knowing the dimensions of the image:
http://cssdeck.com/labs/aajakwnl
<div class="ie-container"><img src="http://placekitten.com/200/200" /></div>
div.ie-container {
display: inline-block;
position: relative;
}
div.ie-container:before {
display: block;
content: '';
position: absolute;
top: 4px;
right: 4px;
bottom: 4px;
left: 4px;
border: 1px solid white;
}
img {
vertical-align: middle; /* optional */
}
You could try this:
Html:
<div class="image">
<div class="innerdiv">
</div>
</div>
Css:
.image
{
width: 325px;
height: 239px;
background: url("https://i.picsum.photos/id/214/325/239.jpg?hmac=7XH4Bp-G9XhpuKz5vkgES71GyXKS3ytp-pXCt_zpzE4") 0 0 no-repeat;
background-size: cover;
padding: 10px;
}
.innerdiv
{
border: 1px solid white;
height:100%;
width: 100%;
}
jsFiddle
Hope this is what you meant :)
I solved this with box-shadow: inset and it works with IE11 and up. I wanted a border in the corners around the image but this examples have the border 10px inset. It requires a parent div with :before or :after element but handles it very well.
.image {
width: 100%;
height: auto;
}
.image__wrapper {
position: relative;
}
.image__wrapper:before {
content: '';
position: absolute;
top: 10px;
bottom: 10px;
left: 10px;
right: 10px;
box-shadow: inset 0 0 0 3px red;
}
CodePen Demo
Whatever the div ID or class is you can simply add
#yourDivIDExample {
...
}
#yourDivIDExample img{
border:1px solid #ffffff;
}
This will create a border around the images in the div itself.. same works for classes or global rule also ..
img {
border:1px solid #ffffff;
}
You can do something like this DEMO
HTMl
<div class="imgborder">
<div class="in-imgborder">
</div>
</div>
CSS
.imgborder {
width: 300px;
height: 300px;
position: relative;
background: url(http://placekitten.com/300/300) no-repeat;
}
.in-imgborder {
width: 290px;
height: 290px;
position: absolute;
top: 4px;
left: 4px;
border: 1px solid red;
}

Two borders overlapping with different sizes

Is there any better way of setting two borders like in the example below? I could only do it with positioning. I'm new here so I apologize for any mistakes whatsoever.
.border1 {
margin: 0 auto;
height: 300px;
width: 250px;
border: 9px solid red;
position: relative;
}
.border2 {
border: 9px solid blue;
height: 250px;
width: 300px;
position: absolute;
top: 12px;
left: -33px;
}
<div class="border1">
<div class="border2"></div>
</div>
Absolute is indeed a good and easy way here.
You can also use a pseudo and only coordonates to size the second border box.
.border1 {
margin: 0 auto;
min-height: 150px;/* allow it to grow */
width: 250px;
padding:20px 0.5em;
border: 9px solid red;
position: relative;
}
.border2:before {
content:'';
border: 9px solid blue;
pointer-events:none;/* to allow clicking through else you may use a negative z-index */
position: absolute;
top: 12px;
bottom:12px;
left: -33px;
right:-33px;
}
<div class="border1 border2">
add anything here instead setting height
</div>
This is a different approach. I used box-shadow as the second border and you will no longer need a second div for second border.
.border{
margin:0 auto;
height:300px;
width:250px;
border:9px solid red;
position:relative;
box-shadow: 0 0 0px 9px blue;
}
<div class="border"></div>
You can do it with the Flexbox and without unnecessary calculations:
.border1 {
margin: 0 auto;
height: 300px;
width: 250px;
border: 9px solid red;
display: flex; /* displays flex-items (children) inline */
justify-content: center; /* centers them horizontally */
align-items: center; /* and vertically */
}
.border2 {
flex: 0 0 300px; /* doesn't shrink, flex-basis set to "300px" (initial width) */
border: 9px solid blue;
height: 250px;
}
<div class="border1">
<div class="border2"></div>
</div>