CSS div oval shape - html

Can someone help me out making such a cut out from div?
Found possible solution,but dont have knowledge in SVG.Maybe someone can help me out.
HTML:
<svg viewBox="0 0 400 150">
<path opacity="0.6" fill="red" d="M0,10 Q0,0 10,0 Q195,40 390,0 Q400,0 400,10 Q390,75 400,140 Q400,150 390,150 Q195,100 10,150 Q0,150 0,140 Q10,75 0,10" />
</svg>
CSS:
svg {
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

body {
overflow-x: hidden
}
svg {
left: 47%;
position: relative;
top: -24%;
transform: translate(-50%, -50%);
width: 2000px;
}

Try it:-
#oval_parent{
background:black;
width:200px;
height:120px;
overflow:hidden;
}
#oval{
width: 220px;
height: 100px;
margin:10px 0 0 -10px;
background: white;
-moz-border-radius: 100px / 50px;
-webkit-border-radius: 100px / 50px;
border-radius: 100px / 50px;
}
<div id="oval_parent">
<div id="oval"></div>
</div>

The easiest way of doing this is create a div right after the navigation and make curved png with Photoshop and apply it as background to that div. So in that way you have rectangle navigation and div with curved background after navigation.
.nav-bot{
background: url(https://s23.postimg.org/jakqjag8r/nav_bot.png);
background-size: 100% 100%;
background-repeat: no-repeat;
width: 100%;
height: 20px;
}
Here is example fiddle.
EDIT
If you don't want to use image there is another way to do this Using css gradient and box-shadow.
.nav-bot{
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0) 50%);
width: 104%;
margin-left: -2%;
height: 50px;
border-radius: 50%;
margin-top: -19px;
-webkit-box-shadow: 0px 6px 15px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 6px 15px 0px rgba(0,0,0,0.75);
box-shadow: inset 1px 3px 5px 0px rgba(0,0,0,0.75);
}
Here is example for that.
Hope this helps you.

Html:
<div class="oval"></div>
css:
.oval { width: 100px; height: 50px; border-radius: 50%; background: red; overflow: hidden;}
The trick is to have one side bigger than the other. Overflow hidden to cut out the background stuff if you use an image.
Change the width and height depending on the direction of the oval.
Here's a JSfiddle:
https://jsfiddle.net/10cq0vmv/

Related

Can i customize a box shadow to be a triangle behind an image?

I'm Trying to customize a box shadow to shape like a triangle behind an image. Like this:
But i don't know if theres a way to doing it using box shadow.
This is my code so far.
#image{
width: 200px;
box-shadow: -10px 10px #ff9900;
}
<img src="https://placeimg.com/200/180/any" id="image" />
A simple border with gradient will do it and it will be responsive:
#image {
border: 10px solid transparent;
border-image: linear-gradient(to bottom left, transparent 60%, #ff9900 60.5%) 10;
}
<img src="https://placeimg.com/180/150/any" id="image" />
<img src="https://placeimg.com/250/150/any" id="image" />
Almost the same but with background:
.box{
width:200px;
height:150px;
padding:10px; /*control the space*/
background:
url(https://placeimg.com/180/150/any) center/cover content-box,
linear-gradient(to bottom left, transparent 60%, #ff9900 60.5%);
}
<div class="box"></div>
I think the box-shadow property cannot be modeled to be a format different than your father element.
For example, you cannot make a triangle shadow for a square image, like your question.
Try to make a triangle in css and make that with a realative position. Then, use your image with a absolute position.
#triangle-bottomleft {
width: 0;
height: 0;
border-bottom: 100px solid red;
border-right: 100px solid transparent;
position: relative;
margin-top: 30px;
}
#image {
position: absolute;
top: 20px;
left: 17px;
}
<div id="triangle-bottomleft"></div>
<img src="https://placeimg.com/100/100/any" title="title of image" alt="alt of image" id="image">
I hope this will helpu.
I would suggest nesting the triangle and refrain from using position: absolute; in this case:
#img {
position: relative;
width: 200px;
background: url(https://placeimg.com/200/150) no-repeat right top;
padding: 10px 10px 0 0;
}
#triangle {
position: relative;
border-bottom: 150px solid orange;
border-right: 200px solid transparent;
z-index: -1;
}
<div id="img">
<div id="triangle"></div>
</div>
If compatibility with IE is a non-issue you could also use clip-path:
#img {
position: relative;
width: 200px;
height: 150px;
background: url(https://placeimg.com/200/150) no-repeat right top;
padding: 10px 10px 0 0;
}
#triangle {
position: relative;
width: 100%;
height: 100%;
clip-path: polygon(0 0, 0% 100%, 100% 100%);
background-color: orange;
z-index: -1;
}
<div id="img">
<div id="triangle"></div>
</div>

How to rounded an image whatever the source shape and size?

In my ionic/angularJS app i'm using either the camera or the gallery to pick a photo and upload it as avatar. My problem is, depending the source file, if the image is small or rectangle, i'm not able to resize it the way i want to have a proper rounded image. What do you think ?
Here is what i have :
Or here, same image but it's too much zoomed in...
/* ZOOMED IN IMAGE CSS */
.menu-image-2 {
position: relative;
max-width: 150px;
max-height: 150px;
border-radius: 50%;
overflow: hidden;
border: 2.5px solid rgba(255, 255, 255, 0.4);
left: 50%;
transform: translateX(-50%);
}
.menu-image-2 > img {
width: 150px;
border-radius: 0%;
}
figure{
width:150px;
height:150px;
left: 50%;
transform: translateX(-50%);
}
/* CROPPED IMAGE CSS */
.moncompte-image {
position: relative;
max-width: 200px;
max-height: 200px;
border-radius: 50%;
overflow: hidden;
border: 2.5px solid rgba(255, 255, 255, 0.4);
left: 50%;
transform: translateX(-50%);
}
.moncompte-image > img {
max-width: 200px;
border-radius: 0%;
}
figure_monCompte{
}
figure_monCompte > img{
max-width:200px;
max-height:200px;
}
<!--ZOOMED IN IMAGE -->
<div class="menu-image-2">
<figure><img data-ng-src="xxxxx"></figure>
</div>
<!-- CROPPED IMAGE -->
<div class="moncompte-image">
<figure_monCompte>
<img src="xxxxxx"> </figure_monCompte>
</div>
EDIT :
I have a question about the second snippet, I would like to use it, but i need to set the background image out of the css file, but when trying this the image is not set as background so the result is an image squeezed instead of have a nice hidden overflow... Do you have ideas to overtake this ?
#rounded-image {
border-radius: 50%;
width: 150px;
height: 150px;
border: 5px solid rgba(0, 0, 0, 0.4);
overflow: hidden;
}
#rounded-image:before {
content: "";
/* background-image: url(https://i.ytimg.com/vi/7xWxpunlZ2w/maxresdefault.jpg) center; */
background-size: cover;
width: 100%;
height: 100%;
display: block;
overflow: hidden;
}
<img data-ng-src="{{avatar}}" id="rounded-image">
You need to set the image as background-image, background position center, background size contain, top left 0, background repeat no repeat
If you dont specify the image as background image, the image might get stretched
*Sorry for the formatting, im stuck in a traffic only with my phone
As mentioned in my comment, you can just use border-radius: 50%; but you may want to include browser prefixes:
img {
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-o-border-radius: 50%;
-ms-border-radius: 50%;
}
Browser prefixes: https://lifewire.com/css-vendor-prefixes-3466867
<img src="https://image.ibb.co/h9mYY0/moz.png" style="border-radius:50%;border: 5px solid rgba(0, 0, 0, 0.4);">
Alternatively, you can use Psuedo elements, to set the images as the background images of the ::before element... this way, you're DIV border radius will work correctly: Can I put a border radius on a before or after pseudo selector image?
Or as the background image of the DIV itself, though this leaves you with less flexibility.
New snippet using Psuedo elements, works with rectangles and small images:
#rounded-image {
border-radius: 50%;
width: 150px;
height: 150px;
border: 5px solid rgba(0, 0, 0, 0.4);
overflow: hidden;
}
#rounded-image:before {
content: "";
background-image: url(https://ichef.bbci.co.uk/news/976/cpsprodpb/9947/production/_103893293_ec317eb7-0fa2-4ec8-ab8e-53c9ce976a63.jpg);
background-size: cover;
width: 100%;
height: 100%;
display: block;
overflow: hidden;
}
<div id="rounded-image"></div>
UPDATE:
<style>
#rounded-image:before {
background-image: url('{{bgImg}}');
}
</style>
<div id="rounded-image"></div>
Obviously, you still need your CSS file for the rest of the styles, but do that in the <head> of your page, or just before the tag, but <head> is nicer ... childish giggle

How to partially darken a background image using CSS?

.darken {
position: relative;
width: auto;
height: auto;
margin: 10px;
border-radius: 20px;
border: hidden;
padding: 20%;
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), no-repeat center top / cover;
}
<div class="darken" style="background-image: url("https://smorder.blob.core.windows.net/images/6/d9ffff37-79a2-44b2-aef4-6c8aadff1c6e");"></div>
But, it does not achieve what I want exactly. As I want to darken the left side of the image partially. I want to achieve something like this: http://prntscr.com/gj0hs8
Any ideas how to achieve this darkening effect?
linear gradient is treated as a background image too.
You can use it as an overlay if set first while using multiple background-image.
Mind the start/stop value, direction and to set 2 different colors in order to draw a gradient (tune provided example below to your needs).
A simple gradient always covers its container, no need to reset background-size to it
example below.
.darken {
position: relative;
width: auto;
height: auto;
margin: 10px;
border-radius: 20px;
border: hidden;
padding: 20%;
}
<div class="darken" style="
background:
linear-gradient(135deg, rgba(0, 0, 0, 0.8) 40%, rgba(0, 0, 0, 0) 70%) no-repeat center top ,
url(http://lorempixel.com/800/500/nightlife/7) 0 0 /cover ;">
test</div>
You need a div as overlay and give this one the gradient and it should work
Hope this might work
.darken {
position: relative;
width: auto;
height: auto;
margin: 10px;
border-radius: 20px;
border: hidden;
padding: 20%;
background-image: url("https://preview.ibb.co/fQxszF/security.jpg");
background-repeat: no-repeat;
background-size: cover;
}
.overlay::before {
position: absolute;
top: 0;
left: 0;
transform: translate(-230px, -60px) rotate(145deg);
content: '';
display: block;
width: 77%;
height: 65%;
background: rgba(0, 0, 0, 0.9);
}
<div class="darken overlay"></div>
Include the class overlay in the div.
Appreciate if useful.

CSS shadow for :before and :after on a scrollable container

I have a container which is scrollable. I would like to add an inset shadow at the beginning of the container and another one in the opposite direction at the bottom of the container. Attached is an image of what I have vs what I'm trying to achieve.
This is the shadow I'm trying to attach at the top, and a reversed one at the bottom. Notice that the left and right side fade just a bit.
CSS for shadow:
.list {
height: 100px;
overflow: auto;
position: relative;
}
.list:before {
content: "";
position: absolute;
width: 100%;
margin: 0 auto;
height: 12px;
border: 0;
box-shadow: inset 0 12px 12px -12px rgba(0,0,0,0.5);
}
.list:after {
content: "";
position: absolute;
width: 100%;
margin: 0 auto;
height: 12px;
border: 0;
box-shadow: inset 0 -12px 12px -12px rgba(0,0,0,0.5);
bottom: 0;
}
I have these two issues:
When I scroll, the shadows move, how can I keep them in place?
I tried fixed position, but then they are not limited to the container.
How can I achieve a slight fade on the shadow at the left and right?
I tried transform: rotateX(1deg) rotateY(0deg) rotateZ(0deg) with perspective: 10px but no real results - but I think this is a starting point.
A plunker with this code in it:
http://plnkr.co/edit/YREOxLXUfN7xCUQDwc77?p=preview
You'll need to add a container <div> to achieve this. Something like this:
.list-container {
height: 100px;
position: relative;
}
.list-container:before {
display:block;
content: "";
position: absolute;
width: 100%;
margin: 0 auto;
height: 12px;
border: 0;
box-shadow: inset 0 12px 12px -12px rgba(0,0,0,0.5);
}
.list-container:after {
display:block;
content: "";
position: absolute;
width: 100%;
margin: 0 auto;
height: 12px;
border: 0;
box-shadow: inset 0 -12px 12px -12px rgba(0,0,0,0.5);
bottom: 0;
}
.list {
height: 100px;
overflow: auto;
}
<div class="list-container">
<div class="list">
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
<div> {{item}} </div>
</div>
</div>
As for the slight fade you desire, have a look here: Taper/fade CSS box shadow?
Well, about the scrolling issue, the solution is in the video from Lea Verou conference.
I could post the code here, but people should see the video, it deserves it
About the request shadow, generated with backgrounds, I porvide you 2 different options, generated with multiple backgrounds. The first uses rounded corners, the second linear ones.
I have done it bigger and darker than requested, so that the difference is easier to see.
.one {
width: 200px;
height: 150px;
border: solid 1px red;
background-image: radial-gradient(circle at bottom right, black 0%, white 70%),
radial-gradient(circle at bottom left, black 0%, white 70%),
linear-gradient(to top, black 0%, white 100%);
background-size: 40px 40px, 40px 40px, 100% 40px;
background-repeat: no-repeat;
background-position: bottom left, bottom right, bottom left;
}
.two {
width: 200px;
height: 150px;
left: 220px; top: 10px;
position: absolute;
border: solid 1px red;
background-image: linear-gradient(-45deg, black 0%, white 50%),
linear-gradient(45deg, black 0%, white 50%),
linear-gradient(to top, black 0%, white 100%);
background-size: 40px 40px, 40px 40px, 100% 40px;
background-repeat: no-repeat;
background-position: bottom left, bottom right, bottom left;
}
<div class="one"></div>
<div class="two"></div>
something like this?
.wrapList:before {
content: "";
position: fixed;
width: 100%;
margin: 0 auto;
height: 12px;
background: linear-gradient(90deg, rgba(0,0,0,0.2), rgba(0,0,0,.5));
overflow: hidden;
box-shadow: inset 0 12px 12px -12px rgba(0,0,0,0.5);
}
.wrapList:after {
content: "";
position: absolute;
width: 100%;
margin: 0 auto;
height: 12px;
border: 0;
box-shadow: inset 0 -12px 12px -12px rgba(0,0,0,0.3);
background: linear-gradient(90deg, rgba(0,0,0,.3), rgba(0,0,0,0.2));
}
with
<div class="wrapList">
<div class="list">
<div ng-repeat="item in items"> {{item}} </div>
</div>
</div>

Draw Circle using css alone [duplicate]

This question already has answers here:
How to draw circle in html page?
(19 answers)
Closed 7 years ago.
Is it possible to draw circle using css only which can work on most of the browsers (IE,Mozilla,Safari) ?
Yep, draw a box and give it a border radius that is half the width of the box:
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
Working demo:
http://jsfiddle.net/DsW9h/1/
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
<div id="circle"></div>
You could use a .before with a content with a unicode symbol for a circle (25CF).
.circle:before {
content: ' \25CF';
font-size: 200px;
}
<span class="circle"></span>
I suggest this as border-radius won't work in IE8 and below (I recognize the fact that the suggestion is a bit mental).
Create a div with a set height and width (so, for a circle, use the same height and width), forming a square
add a border-radius of 50% which will make it circular in shape. (note: no prefix has been required for a long time)
You can then play around with background-color / gradients / (even pseudo elements) to create something like this:
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
.yellow {
background-color: yellow;
}
.sphere {
height: 200px;
width: 200px;
border-radius: 50%;
text-align: center;
vertical-align: middle;
font-size: 500%;
position: relative;
box-shadow: inset -10px -10px 100px #000, 10px 10px 20px black, inset 0px 0px 10px black;
display: inline-block;
margin: 5%;
}
.sphere::after {
background-color: rgba(255, 255, 255, 0.3);
content: '';
height: 45%;
width: 12%;
position: absolute;
top: 4%;
left: 15%;
border-radius: 50%;
transform: rotate(40deg);
}
<div class="sphere red"></div>
<div class="sphere green"></div>
<div class="sphere blue"></div>
<div class="sphere yellow"></div>
<div class="sphere"></div>
border radius is good option, if struggling with old IE versions then try HTML codes
•
and use css to change color. Output:
•
This will work in all browsers
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
}
yup.. here's my code:
<style>
.circle{
width: 100px;
height: 100px;
border-radius: 50%;
background-color: blue
}
</style>
<div class="circle">
</div>