I think images speak louder than words in this case.
I want to get this effect:
But the best I can do with CSS3 is this:
And the code for this is absolutely terrible:
box-shadow: 1px 1px hsl(0, 0%, 27%),
2px 2px hsl(0, 0%, 27%),
3px 3px hsl(0, 0%, 27%),
4px 4px hsl(0, 0%, 27%),
5px 5px hsl(0, 0%, 27%),
6px 6px hsl(0, 0%, 27%),
7px 7px hsl(0, 0%, 27%),
8px 8px hsl(0, 0%, 27%),
...
Is there any way that I can create an effect like this with pure CSS3? I don't mind having it be 3D, but isometric would be preferred.
I don't need to place content onto the sides of the box, just onto the front face, so I'm working with just a single <div> element.
Here's what I have so far: http://jsfiddle.net/X7xSf/3/
Any help would be appreciated!
I'd use some skew transforms on some CSS generated elements... Take a look at this:
http://jsfiddle.net/X7xSf/12/
If I wanted to use this in production, I'd probably identify which browsers support before and after, but not transforms (only IE8), then use Paul Irish's method from 2008 (http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/) to turn this off for IE8.
Well... My idea was to use border hacks and some masking to get it to work in... IE 8 at least? But I can't figure out how to get the border to animate backwards Fixed it.
You can see my idea here: http://jsfiddle.net/k2AdU/1
and the code concept is to use :before and :after to create a mask for the corners
.cube
{
width:100px;
height:100px;
background:#454545;
position:relative;
border-right:20px solid #333;
border-bottom:20px solid #111;
border-right-width:0px;
border-bottom-width:0px;
left:20px;
top:20px;
}
.cube:after
{
content:"";
display:block;
position:absolute;
left:0px;
top:100%;
border:10px solid transparent;
border-left:10px solid white;
border-bottom:10px solid white;
}
.cube:before
{
content:"";
display:block;
position:absolute;
top:0px;
left:100%;
border:10px solid transparent;
border-top:10px solid white;
border-right:10px solid white;
}
Related
I'm looking to create a styled button for my app. The hope is to use css to generate a button which looks similar to:
The blue comes from the background so it's not relevant, its the shades of green I'm interested in. I'm not sure first if its possible to do it with CSS or how to do it if it is possible.
Can you start a gradient in the top left corner, move into a different colour from there and finish with a final colour at the bottom of the gradient?
If so are there any examples that you know of which I can refer too?
You can do this easily enough with a CSS-gradient using color stops. Here's a snippet example:
.gradientButton {
height: 50px;
width: 100px;
line-height:50px;
vertical-align:middle;
text-align:center;
font-family:arial;
font-size:26px;
font-weight:bold;
color:white;
text-shadow:2px 2px #336633;
box-shadow:2px 2px #336633;
border: 1px solid black;
border-radius:12px;
background: linear-gradient(to bottom right, LawnGreen 15%, green 85%, DarkGreen 90%);
}
.gradientButton:hover {
text-shadow:1px 1px #336633;
box-shadow:1px 1px #336633;
background: linear-gradient(to bottom right, LawnGreen 5%, green 80%, DarkGreen 85%);
}
<html>
<body>
<div class="gradientButton">log in</div>
</body>
</html>
Using things like gradients and shadows you can even provide hover effects like I've done here making it look like the button's depressed when you hover over it.
I have a div with a vignette effect.
<div id="box" class="glow"></div>
#box
{
padding:10px;
border:solid 1px #ddd;
width:100px;
height:400px;
position:relative;
}
.glow:after
{
-webkit-box-shadow:inset 0px 0px 70px #CE1A1A;
-moz-box-shadow:inset 0px 0px 70px #CE1A1A;
box-shadow:inset 0px 0px 70px #CE1A1A;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
content: "";
}
Here's the jsfiddle: http://jsfiddle.net/bEFha/
But what I am really after is a glow from the inside out. So red in the center and white in the sides. The effect I'm trying to achieve is as if there is a red light source shining from underneath the div.
I've tried various things but just not able to the vignette effect to spread out from the center.
Any help is appreciated.
UPDATE: If possible I would like to not modify the background property of #box as I need that to be white.
You could use a radial-gradient background.
See: https://developer.mozilla.org/de/docs/Web/CSS/radial-gradient
Here's a very basic example, you could tweak: http://jsfiddle.net/bEFha/5/
background-image: radial-gradient(farthest-corner at center center, #CE1A1A 0%, #ffffff 100%);
I also find this visual editor very helpful http://www.visualcsstools.com/
I'm not quite sure what your after, but by playing around I got this:
box-shadow:inset 0px 3px 20px 10px #FFF;
background-color: #CE1A1A;
Fiddle Here
Try this vintage effect Demo
Just give background color to the box and you will get cool vintage effect.
#box{ background:#FFE4E4; }
UPDATED ANSWER:
Demo
CSS Changes
#box:after{
content:"";
background: #CE1A1A;
opacity:0.5;
}
.glow:after {
-webkit-box-shadow:inset 0px 0px 120px #fff;
-moz-box-shadow:inset 0px 0px 120px #fff;
box-shadow:inset 0px 0px 120px #fff;
}
Your #box is still white but I added #box:after to make it red.
Demo with Image
Below is an image of a button we use on our site, it's a .png.
We'd like to see if we can get really close to it with CSS on a standard button.
The gradient goes top: #E14C5B to middle: #D33742 to bottom: #B61C27 with a couple pixel radial of round corners.
Is that even possible in CSS?
I'll get ya started...
HTML
<button>Submit</button>
CSS with some background gradients
#import url(http://fonts.googleapis.com/css?family=Pathway+Gothic+One);
button {
font-family: 'Pathway Gothic One', sans-serif;
font-size: 1.5em;
text-shadow: 1px 1px rgba(0, 0, 0, 0.5);
border: 1px solid transparent;
border-radius: 3px;
height: 50px;
width: 100px;
color: white;
background-repeat: repeat-x;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#E14C5B), color-stop(0.5, #D33742), to(#B61C27));
box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer;
}
DEMO
Screenshot:
If you want some kind of clicky feedback type look on click, you could also add:
button:active {
-webkit-transform: translate(1px, 1px);
box-shadow: none;
}
DEMO w/ :active
This is only prefixed for -webkit browsers. You'll need to provide the proper vendor prefixes for whatever you are supporting.
Here is the cross-browser version using css gradient.
I specified 4 colors for the gradient.
The first gradient from 0 to 50% and the second gradient from 51% to 100%.
Ex.
background: linear-gradient(to bottom, #f64757 0%,#f83b49 50%,#eb2735 51%,#ce0011 100%);
jsfiddle demo here
Please note that the red i took are brighter than in tour example.
Just play with the css to adjust colors that fit your needs.
I'm trying to do something like this for a client who has a blog.
She wanted a semi transparent border. I know that's possible with making it just a background. But I can't seem to find the logic/code behind this kind of css technique for banners. Does anybody know how to do this? It would be a lot of help because that's the look my client's wanting to achieve for his blog....
Well if you want fully transparent than you can use
border: 5px solid transparent;
If you mean opaque/transparent, than you can use
border: 5px solid rgba(255, 255, 255, .5);
Here, a means alpha, which you can scale, 0-1.
Also some might suggest you to use opacity which does the same job as well, the only difference is it will result in child elements getting opaque too, yes, there are some work arounds but rgba seems better than using opacity.
For older browsers, always declare the background color using #(hex) just as a fall back, so that if old browsers doesn't recognize the rgba, they will apply the hex color to your element.
Demo
Demo 2 (With a background image for nested div)
Demo 3 (With an img tag instead of a background-image)
body {
background: url(http://www.desktopas.com/files/2013/06/Images-1920x1200.jpg);
}
div.wrap {
border: 5px solid #fff; /* Fall back, not used in fiddle */
border: 5px solid rgba(255, 255, 255, .5);
height: 400px;
width: 400px;
margin: 50px;
border-radius: 50%;
}
div.inner {
background: #fff; /* Fall back, not used in fiddle */
background: rgba(255, 255, 255, .5);
height: 380px;
width: 380px;
border-radius: 50%;
margin: auto; /* Horizontal Center */
margin-top: 10px; /* Vertical Center ... Yea I know, that's
manually calculated*/
}
Note (For Demo 3): Image will be scaled according to the height and
width provided so make sure it doesn't break the scaling ratio.
You can also use border-style: double with background-clip: padding-box, without the use of any extra (pseudo-)elements. It's probably the most compact solution, but not as flexible as the others.
For example:
<div class="circle">Some text goes here...</div>
.circle{
width: 100px;
height: 100px;
padding: 50px;
border-radius: 200px;
border: double 15px rgba(255,255,255,0.7);
background: rgba(255,255,255,0.7);
background-clip: padding-box;
}
If you look closely you can see that the edge between the border and the background is not perfect. This seems to be an issue in current browsers. But it's not that noticeable when the border is small.
Using the :before pseudo-element,
CSS3's border-radius,
and some transparency is quite easy:
LIVE DEMO
<div class="circle"></div>
CSS:
.circle, .circle:before{
position:absolute;
border-radius:150px;
}
.circle{
width:200px;
height:200px;
z-index:0;
margin:11%;
padding:40px;
background: hsla(0, 100%, 100%, 0.6);
}
.circle:before{
content:'';
display:block;
z-index:-1;
width:200px;
height:200px;
padding:44px;
border: 6px solid hsla(0, 100%, 100%, 0.6);
/* 4px more padding + 6px border = 10 so... */
top:-10px;
left:-10px;
}
The :before attaches to our .circle another element which you only need to make (ok, block, absolute, etc...) transparent and play with the border opacity.
use rgba (rgb with alpha transparency):
border: 10px solid rgba(0,0,0,0.5); // 0.5 means 50% of opacity
The alpha transparency variate between 0 (0% opacity = 100% transparent) and 1 (100 opacity = 0% transparent)
In an attempt to make an arrow in pure CSS for my tooltip, I ran across a problem in Firefox:
I tried to find what was causing the dark border in Firefox without success.
Here is a jsfiddle and a running snippet demonstrating the problem:
.tooltip {
position:relative;z-index:1;
display:inline-block;padding-right:10px;
}
.tooltip .info {
position:absolute;left:100%;top:-7px;
display:block;padding:7px;border:1px solid #cccccc;
background:#fff;
-webkit-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: 1px 1px 8px 0px rgba(0, 0, 0, .2);
box-shadow: 1px 1px 8px 0px rgba(0, 0, 0, .2);
}
.tooltip .info img {float:left;}
.tooltip:after {
content: '';
position:absolute;top:0;left:100%;
display:block;
width:0;
height:0;
margin-left:-13px;
border:0 solid transparent;
border-right-color:#cccccc;
color:#ccc;
}
.tooltip .info:after {
content: '';
position:absolute;top:7px;left:-12px;z-index:10;
display:block;
width:0;
height:0;
border:transparent solid 6px;
border-right-color:#fff;
color:#ccc;
}
<a class="tooltip">Test for tooltip<span class="info">My tootip information</span></a>
This second demo demonstrates that background transparent is the root cause as replacing transparent by a color results in the same render in Chrome and Firefox.
2015's EDIT
Now it works by using both RGBa and transparent; appearently, the Bug has been resolved (maybe incidentally, because it is still in state NEW , instead that on FIXED).
If it still happens to you, you're probably running an old FireFox version (the current one is 38.0.5), and you can use the workaround in the answer to overcome the problem.
It is the
Bug 646053 - dark diagonals at corner joins adjacent to transparent borders
The workaround is to use RGBa instead of transparent:
/* old */
border: transparent solid 6px;
border-right-color: #fff;
/* new */
border: rgba(255,255,255,0) solid 6px;
border-right-color: #fff;