I am trying to create a div in css with an inward oval shape to it like this.
At the moment, I have a shape that is outward instead of inward (JS Fiddle Link).
.shape {
float: left;
width: 100px;
height: 50px;
border: none;
background: #CC0000;
border-radius: 0 90px 0 0;
-moz-border-radius: 0 90px 0 0;
-webkit-border-radius: 0 90px 0 0;
background-image: -webkit-gradient( linear, left top, right bottom, color-stop(0, #520C0C), color-stop(1, #CC0000) );
background-image: -o-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -moz-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -webkit-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -ms-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: linear-gradient(to right bottom, #520C0C 0%, #CC0000 100%);
}
Any ideas on how to go about this?
Have a look at my example fiddle.
I used a pseudo-element and some elliptical border-radius coupled with an inset box-shadow.
div {
position:relative;
width: 200px;height: 100px;
background: #CC0000;
background-image: linear-gradient(to right bottom, #520C0C 0%, #CC0000 100%);
}
div:after {
position:absolute;content:"";
width: 100%;height: 95%;
background: #222;
box-shadow:inset 10px -10px 5px -10px #000;
border-radius: 0 0 0 200px / 100px;
}
With a little more effort, one could probably get closer to your result, but this might be a good starting point.
I have created this fiddle for you. Here is the code:
HTML
<div class="container">
<div class="shape"></div>
</div>
CSS
.container {
float: left;
width: 100px;
height: 50px;
border: none;
background: #CC0000;
background-image: -webkit-gradient( linear, left top, right bottom, color-stop(0, #520C0C), color-stop(1, #CC0000) );
background-image: -o-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -moz-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -webkit-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -ms-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: linear-gradient(to right bottom, #520C0C 0%, #CC0000 100%);
}
.shape {
width: 100px;
height: 50px;
border: none;
background: #000000;
border-radius: 0 0 0 90px;
-moz-border-radius: 0 0 0 90px;
-webkit-border-radius: 0 0 0 90px;
}
If the part of the graphic that "isn't there" doesn't have to be actually transparent, then you can just make a regular rectangle, and build a curved shape that will sit on top of the rectangle and has the same color as the background.
http://jsfiddle.net/ub8fM/1/
.shape {
float: left;
width: 100px;
height: 50px;
border: none;
background: #CC0000;
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0, #520C0C), color-stop(1, #CC0000));
background-image: -o-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -moz-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -webkit-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -ms-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: linear-gradient(to right bottom, #520C0C 0%, #CC0000 100%);
position:relative;
}
.shape:before {
border-radius: 0 90px 0 0;
-moz-border-radius: 0 90px 0 0;
-webkit-border-radius: 0 90px 0 0;
content:'';
position:absolute;
top:0;
left:0;
background:white;
width:100%;
height:100%;
}
Having the shadow would a bit harder and I have no solution for that yet.
Also jsfiddle has a tidy up button that's super useful.
Related
I use a <div class="menu"></div> and I set a background color with a gradient.
It floats from red in the top to white in the Bottom. Here is my .css code:
.menu {
background-color: #FFF;
background-image: -webkit-gradient(linear, left top, left bottom, from(#791014), to(#FFF));
background-image: -webkit-linear-gradient(top, #791014, #FFF);
background-image: -moz-linear-gradient(top, #791014, #FFF);
background-image: -ms-linear-gradient(top, #791014, #FFF);
background-image: -o-linear-gradient(top, #791014, #FFF);
background-image: linear-gradient(top, #791014, #FFF);
clear: both;
}
I like the starting and end color. My question is, if there is a way that I can change how it flows from red (top) to white (bottom)
For example that it switches very much earlier to white, so that I have the dark red at the beginning of the top but in the middle it is already much more white.
In other words, I want to change how fast it transitions from red to white.
If you want the transition between the colors to happen quicker than normal , just change the point by where the transition should be fully completed. When just two colors are given without any color-stop percentage then the first color starts at 0% and the in between colors are calculated such that second color is reached at 100% mark (100% = container's height by default or background-size in Y-axis if specified). Instead of that give a lower value for the white color. In the below snippet, I have given it as 60% and so the background reaches white color by the time it reaches 60% of the container's height.
Note:
100% = Container's height (default) or background-size in Y-axis (if it is specified) for a vertical gradient.
100% = Container's width (default) or background-size in X-axis (if it is specified) for horizontal gradient.
div {
float: left;
height: 100px;
width: 200px;
line-height: 100px;
text-align: center;
margin-right: 5px;
}
.menu-60 {
background-color: #FFF;
background-image: -webkit-linear-gradient(top, #791014 0%, #FFF 60%);
background-image: -moz-linear-gradient(top, #791014 0%, #FFF 60%);
background-image: -ms-linear-gradient(top, #791014 0%, #FFF 60%);
background-image: -o-linear-gradient(top, #791014 0%, #FFF 60%);
background-image: linear-gradient(top, #791014 0%, #FFF 60%);
}
.menu-40 {
background-color: #FFF;
background-image: -webkit-linear-gradient(top, #791014 0%, #FFF 40%);
background-image: -moz-linear-gradient(top, #791014 0%, #FFF 40%);
background-image: -ms-linear-gradient(top, #791014 0%, #FFF 40%);
background-image: -o-linear-gradient(top, #791014 0%, #FFF 40%);
background-image: linear-gradient(top, #791014 0%, #FFF 40%);
}
.menu-80 {
background-color: #FFF;
background-image: -webkit-linear-gradient(top, #791014 0%, #FFF 80%);
background-image: -moz-linear-gradient(top, #791014 0%, #FFF 80%);
background-image: -ms-linear-gradient(top, #791014 0%, #FFF 80%);
background-image: -o-linear-gradient(top, #791014 0%, #FFF 80%);
background-image: linear-gradient(top, #791014 0%, #FFF 80%);
}
br {
clear: both;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<h3>Red to White at 60%</h3>
<div class='menu-60'>Text</div>
<div class='menu-60'>Text</div>
<div class='menu-60'>Text</div>
<br/>
<h3>Red to White at 40%</h3>
<div class='menu-40'>Text</div>
<div class='menu-40'>Text</div>
<div class='menu-40'>Text</div>
<br/>
<h3>Red to White at 80%</h3>
<div class='menu-80'>Text</div>
<div class='menu-80'>Text</div>
<div class='menu-80'>Text</div>
You can use colour stops to achieve this like
background: -moz-linear-gradient(top, #791014 0%, #ffffff 28%);
background: -webkit-linear-gradient(top, #791014 0%,#ffffff 28%);
background: linear-gradient(to bottom, #791014 0%,#ffffff 28%);
You could use a tool like http://www.colorzilla.com/gradient-editor/ to easily tweak this visually and have the code generated for you.
http://colorzilla.com/gradient-editor/#791014+0,ffffff+28
I have this div, and i need it to be fixed, but i can't use position fixed (the site goes to the left when i push a button, and if the div it's fixed, t will stay in the same spot)... How can i do it?
#baar{
height: 56px;
width: 100%;
background: linear-gradient(top, #e3e3e3 0%, #f9f9f9 100%);
background: -moz-linear-gradient(top, #e3e3e3 0%, #f9f9f9 100%);
background: -webkit-linear-gradient(top, #e3e3e3 0%, #f9f9f9 100%);
background-image: -ms-linear-gradient(top left, #e3e3e3 0%, #f9f9f9 100%);
background-image: -o-linear-gradient(top left, #e3e3e3 0%, #f9f9f9 100%);
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0, #f9f9f9), color-stop(1, #e3e3e3));
background-image: linear-gradient(to bottom right, #e3e3e3 0%, #f9f9f9 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
position: relative;
margin-top: 16px;
left: 0;
text-align: center;
}
I've already tried overflow: hidden...
Thanks
Try this,
position: absolute;
and check if that works, also maybe add a float parameter.
Have a look at this documentation/syntax of style sheets on w3schools, it can be helpful if you forget a couple things now and again.
-http://www.w3schools.com/css/css_syntax.asp
I'm currently having trouble with my css:
.text {
width: 70%;
height: auto;
padding: 7px;
margin-bottom: 10px;
background: #ffffff;
background: -moz-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: -webkit-gradient(left top, right bottom, color-stop(0%, #ffffff), color-stop(100%, #ebebeb));
background: -webkit-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: -o-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: -ms-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: linear-gradient(135deg, #ffffff 0%, #ebebeb 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ebebeb', GradientType=1 );
border: 1px solid rgba(0,29,50,0.5);
border-radius: 6px;
}
.side {
width: 20%;
height: auto;
padding: 7px;
float: right;
margin-bottom: 10px;
background: #ffffff;
background: -moz-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: -webkit-gradient(left top, right bottom, color-stop(0%, #ffffff), color-stop(100%, #ebebeb));
background: -webkit-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: -o-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: -ms-linear-gradient(-45deg, #ffffff 0%, #ebebeb 100%);
background: linear-gradient(135deg, #ffffff 0%, #ebebeb 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ebebeb', GradientType=1 );
border: 1px solid rgba(0,29,50,0.5);
border-radius: 6px;
}
(See it working at http://jsfiddle.net/8L5Tf/)
As you can see at JSFiddle my second sidebar touches the other, but I want it to float beneath the other one, how can I fix this?
You need to clear: right; on the .side class: http://jsfiddle.net/8L5Tf/1/
Floats can be tricky though, so consider putting them both in one div, as Richard said in his comment. It might just end up being easier to manage.
You could add a container div;
<div class="content">
<div class="side">
<div>
Text...
</div>
<div>
Text ...
</div>
</div>
<div class="text">
Text text
</div>
</div>
(and then update your CSS so that the cosmetic styling that was applied to .side is applied to .side > div.)
See http://jsfiddle.net/8L5Tf/3/
I needed to print a textearea content (user input) and I just used css gradient to produce lines below the text. The following css did the trick for me.
.linedText {
color: #000000;
line-height: 24px;
background-color: #ffffff;
background: -webkit-gradient(linear, 2% 2%, 2% 100%, from(#000000), color-stop(1%, #ffffff)) 0 -2px;
background: -webkit-linear-gradient(top, #000000 0%, #ffffff 1%) 0 -1px;
background: -moz-linear-gradient(top, #000000 0%, #ffffff 1%) 0 -1px;
background: -ms-linear-gradient(top, #000000 0%, #ffffff 1%) 0 -1px;
background: -o-linear-gradient(top, #000000 0%, #ffffff 1%) 0 -1px;
background: linear-gradient(top, #000000 0%, #ffffff 1%) 0 -1px;
-webkit-background-size: 100% 24px;
-moz-background-size: 100% 24px;
-ms-background-size: 100% 24px;
-o-background-size: 100% 24px;
background-size: 100% 24px;
}
<p class="linedText">fdfdfdfdfdfdf<br>dfdfd<br>fdf<br>df</p>
And it generates like following:
Now I need to change the style to dotted. Can anyone do it for me please? I tried it for sometimes, but no luck, so thought of SO for a quick response.
Thanks.
This is an example of how you can achieve what you're trying.
It's just a matter of using two linear gradients with rgba colors = transparency and make them overlap to create a pattern to be repeated.
It's not cross browser (webkit only). Just a snippet to get you started.
background-image:
-webkit-linear-gradient(right, rgba(255,255,255,1) 0%, rgba(255,255,255,1) 50%, rgba(255,255,255,0) 51%,rgba(255,255,255,0) 100%),
-webkit-linear-gradient(bottom, rgba(128,128,128,1) 0%, rgba(128,128,128,0) 8%, rgba(128,128,128,0) 100%);
background-size: 12px 24px;
http://jsfiddle.net/ZMfBv/
hr {
border: 0;
border-color:blue;
background-color:blue;
color:blue;
height: 4px;
background:#fff;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,hsla(0,0%,0%,0)), color-stop(50%,hsla(0,0%,0%,.75)), color-stop(100%,hsla(0,0%,0%,0)));
background: -webkit-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: -moz-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: -ms-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: -o-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
}
I wish to change the hr's color to blue.Clearly, the color, background-color setting is not working, how can I do this?
update: Here is a black background with a white to gray gradient hr
body {background-color: black;}
hr {
height: 4px;
border: 0;
background: -webkit-linear-gradient(left, #f3ffff, #555555);
background: -moz-linear-gradient(left,#f3ffff, #555555);
background: -o-linear-gradient(left, #f3ffff, #555555);
background: linear-gradient(left, #f3ffff, #555555);
}
http://jsfiddle.net/ZMfBv/3
background: linear-gradient(to right, rgba(3,0,221,0.75) 10%, rgba(255,255,255,1) 100%);
Use blue as the color, rather than black. You can use this for creating css gradients.
I guess, you want a solid blue color, right ?
I so then here is the simplest solution.
hr {
border: 0;
border-color:red;
color:red;
height: 4px;
background: blue;
}
http://jsfiddle.net/ZMfBv/13/