Inclided text inside half square box - css

I have a css to draw a half square box
.box-tri {
width: 0;
height: 0;
border-right: 30px solid rgb(217, 224, 231);
border-top: 30px solid transparent;
border-left: 30px solid transparent;
border-bottom: 30px solid rgb(217, 224, 231);
}
Now what i should do if i want to write a text parallel to the diagonal of the box but inside the box.

I added a child element to contain the text and rotated it with CSS transform:
<div class="box-tri">
<span>Label</span>
</div>
.box-tri {
width: 0;
height: 0;
border-right: 30px solid rgb(217, 224, 231);
border-top: 30px solid transparent;
border-left: 30px solid transparent;
border-bottom: 30px solid rgb(217, 224, 231);
}
.box-tri span {
position:relative;
display:block;
transform: rotate(-45deg) translate(-15px, -18px);
-moz-transform: rotate(-45deg) translate(-15px, -18px);
-webkit-transform: rotate(-45deg) translate(-15px, -18px);
-webkit-backface-visibility: hidden;
outline: 1px solid transparent;
text-align:center;
line-height:1em;
width:60px;
height:1em;
overflow:hidden;
}
One caveat is that longer text does not work very well. My version truncates it.
WORKING EXAMPLE
In response to the other jsfiddle you found, I made the following changes to make the ribbon go from the top-right to the bottom-right:
.ribbon-wrapper-green {
...
top: -3px // removed
bottom: -3px; // added
}
.ribbon-green {
...
-webkit-transform: rotate(45deg); // removed
-moz-transform: rotate(45deg); // removed
-ms-transform: rotate(45deg); // removed
-o-transform: rotate(45deg); // removed
-webkit-transform: rotate(-45deg); // added
-moz-transform: rotate(-45deg); // added
-ms-transform: rotate(-45deg); // added
-o-transform: rotate(-45deg); // added
...
top: 15px // removed
top: 45px; // added
}
It's not perfect, but try tweaking those values to polish it.
WORKING EXAMPLE

Related

CSS: Fill Circle with 2, 3 or 4 colors

Is it possible to fill a circle with 2 or 3 colors so that each section has equal area?
I know you can do 4: http://jsfiddle.net/k8Jj9/
div {
border-radius: 50px;
border-right-color: blue;
border-top-color: yellow;
border-bottom-color: red;
border-left-color: green;
border-width: 50px;
border-style: solid;
height: 0px;
width: 0px;
/* To ratate */
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
But I'm curious how if there's an approach that can do 2, 3 and 4 (hopefully within a single approach / or set of coding).
Edit: These circles will be drawn by D3, so I'm not sure if that changes the answers/suggestions, especially regarding SVG.
To make a circle with three colors, start with the fiddle you have and superimpose two more circles onto it, with different rotations. The two more circles can be made using the div's ::before and ::after pseudo elements.
div {
border-radius: 50px;
border-right-color: red;
border-top-color: yellow;
border-bottom-color: red;
border-left-color: green;
border-width: 50px;
border-style: solid;
height: 0px;
width: 0px;
position: relative;
/* To ratate */
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
div::before {
display: block;
content: '';
position: absolute;
left: -50px;
top: -50px;
border-radius: 50px;
border-right-color: transparent;
border-top-color: yellow;
border-bottom-color: transparent;
border-left-color: transparent;
border-width: 50px;
border-style: solid;
height: 0px;
width: 0px;
/* To ratate */
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-o-transform: rotate(30deg);
-ms-transform: rotate(30deg);
transform: rotate(30deg);
}
div::after {
display: block;
content: '';
position: absolute;
left: -50px;
top: -50px;
border-radius: 50px;
border-right-color: transparent;
border-top-color: transparent;
border-bottom-color: transparent;
border-left-color: green;
border-width: 50px;
border-style: solid;
height: 0px;
width: 0px;
/* To ratate */
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
transform: rotate(-30deg);
}
<div></div>

Have Darker shadow around corners

I have looked and can't seem to find if it is possible to have darker box shadow around the corners. I know you can do with a .png, but is it possible to do this only with css?
I attached a picture to give an example of what I am trying to accomplish.
.box {
background-color: #dedede;
height: 200px;
width: 200px;
box-shadow: 0 4px 2px -2px rgba(177, 176, 176, 0.74);
}
<div class="box"> </div>
.effect2 {
position: relative;
}
.effect2:before,
.effect2:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: #777;
-webkit-box-shadow: 0 15px 10px #777;
-moz-box-shadow: 0 15px 10px #777;
box-shadow: 0 15px 10px #777;
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.effect2:after {
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-o-transform: rotate(3deg);
-ms-transform: rotate(3deg);
transform: rotate(3deg);
right: 10px;
left: auto;
}
<div class="box effect2">
<h3>Effect 2</h3>
</div>

how to route arrow from right to down css

I just want to route a arrow down.
My CSS:
.arrow-admin{
bottom: -130px;
right: -240px;
width: 0;
height: 0px;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left: 18px solid #666;
position:relative;
}
with css property transform. This property allows you to rotate, scale, move, skew, etc., elements.
.arrow-admin{
-ms-transform: rotate(90deg); /* IE 9 */
-webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */
-moz-transform: rotate(90deg); /* mozilla */
transform: rotate(90deg);
}

Polaroid Image Gallery with only css

UPDATE
here is a js-fiddle with images available: http://jsfiddle.net/TBwWw/
I am using a tutorial that I found here.
I have an unordered list that simply links the image to a larger one and also displays the image on the page.
<ul class="polaroids">
<li>
<a href="http://www.flickr.com/photos/zurbinc/3971679981/" title="Roeland!">
<img src="example/cyan_hawk.jpg" alt="Roeland!">
</a>
</li>
</ul>
And then css that is supposed to be adjusting the image size, add the polaroid effect and a whole lot more.
ul.polaroids a:after {
content: attr(title);
}
/* By default, we tilt all our images -2 degrees */
ul.polaroids a {
-webkit-transform: rotate(-2deg);
-o-transform: rotate(-2deg);
-ms-transform: rotate(-2deg);
-moz-transform: rotate(-2deg);
transform: rotate(-2deg);
}
/* Rotate all even images 2 degrees */
ul.polaroids li:nth-child(even) a {
-webkit-transform: rotate(2deg);
-o-transform: rotate(2deg);
-ms-transform: rotate(2deg);
-moz-transform: rotate(2deg);
transform: rotate(2deg);
}
/* Don't rotate every third image, but offset its position */
ul.polaroids li:nth-child(3n) a {
-webkit-transform: none;
-o-transform: none;
-ms-transform: none;
-moz-transform: none;
transform: none;
position: relative;
top: -5px;
}
/* Rotate every fifth image by 5 degrees and offset it */
ul.polaroids li:nth-child(5n) a {
-webkit-transform: rotate(5deg);
-o-transform: rotate(5deg);
-ms-transform: rotate(5deg);
-moz-transform: rotate(5deg);
transform: rotate(5deg);
position: relative;
right: 5px;
}
/* Keep default rotate for every eighth, but offset it */
ul.polaroids li:nth-child(8n) a {
position: relative;
top: 8px;
right: 5px;
}
/* Keep default rotate for every eleventh, but offset it */
ul.polaroids li:nth-child(11n) a {
position: relative;
top: 3px;
left: -5px;
}
/* Scale the images on hover, add transitions for smoothing things out, and ensure the hover appears on top */
ul.polaroids a:hover {
-webkit-transform: scale(1.25);
-ms-transform: scale(1.25);
-o-transform: scale(1.25);
-moz-transform: scale(1.25);
transform: scale(1.25);
position: relative;
z-index: 5;
}
/* Add drop shadows and smooth out the transition (Safari only) */
ul.polaroids a {
-webkit-transition: 0 .15s linear;
-moz-transition: 0 .15s linear;
-o-transition: 0 .15s linear;
-webkit-box-shadow: 0 3px 6px rgba(0,0,0,.25);
-moz-box-shadow: 0 3px 6px rgba(0,0,0,.25);
box-shadow: 0 3px 6px rgba(0,0,0,.25);
}
/* On hover, darken the shadows a bit */
ul.polaroids a {
-webkit-box-shadow: 0 3px 6px rgba(0,0,0,.5);
-moz-box-shadow: 0 3px 6px rgba(0,0,0,.5);
box-shadow: 0 3px 6px rgba(0,0,0,.5);
}
The end result is supposed to be:
But they are just appearing with just the unordered list text decoration and the after title effects like so:
Everyone else in the comments on the tutorial said it worked just fine. I don't understand why it isn't working for me. I do have the css in an external style sheet that is linked and being found correctly. Finally, the Google Chrome console is showing no errors. I have tried it in Google Chrome and Internet Explorer.
Try this:
http://jsfiddle.net/jC84f/1/
ul.polaroids { width: 970px; margin: 0 0 18px -30px; }
ul.polaroids li { display: inline; }
ul.polaroids a { background: #fff; display: inline; float: left; margin: 0 0 27px 30px; width: auto; padding: 10px 10px 15px; text-align: center; font-family: "Marker Felt", sans-serif; text-decoration: none; color: #333; font-size: 18px; -webkit-box-shadow: 0 3px 6px rgba(0,0,0,.25); -moz-box-shadow: 0 3px 6px rgba(0,0,0,.25); -webkit-transform: rotate(-2deg); -webkit-transition: -webkit-transform .15s linear; -moz-transform: rotate(-2deg); }
ul.polaroids img { display: block; width: 190px; margin-bottom: 12px; }
ul.polaroids a:after { content: attr(title); }
ul.polaroids li:nth-child(even) a { -webkit-transform: rotate(2deg); -moz-transform: rotate(2deg); }
ul.polaroids li:nth-child(3n) a { -webkit-transform: none; position: relative; top: -5px; -moz-transform: none; }
ul.polaroids li:nth-child(5n) a { -webkit-transform: rotate(5deg); position: relative; right: 5px; -moz-transform: rotate(5deg); }
ul.polaroids li:nth-child(8n) a { position: relative; right: 5px; top: 8px; }
ul.polaroids li:nth-child(11n) a { position: relative; left: -5px; top: 3px; }
ul.polaroids li.messy a { margin-top: -375px; margin-left: 160px; -webkit-transform: rotate(-5deg); -moz-transform: rotate(-5deg); }
ul.polaroids li a:hover { -webkit-transform: scale(1.25); -moz-transform: scale(1.25); -webkit-box-shadow: 0 3px 6px rgba(0,0,0,.5); -moz-box-shadow: 0 3px 6px rgba(0,0,0,.5); position: relative; z-index: 5; }
code { background: rgba(0,0,0,.5); padding: 2px 3px; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.75); -webkit-border-radius: 3px; -moz-border-radius: 3px; }
ol.code { background: rgba(0,0,0,.75); margin-bottom: 18px; border: solid rgba(0,0,0,.75); border-width: 1px 1px 0; -webkit-border-radius: 3px; -moz-border-radius: 3px; -webkit-box-shadow: 0 1px 1px rgba(255,255,255,.5); }
ol.code li, ol.code li code { font-size: 14px !important; }
ol.code code { background: none; }
First off, all the images are supposed to be in a single ul, not separate ones as you have in your fiddle. Second, you're missing the list styles, and display/float properties to make things wrap.
I was able to get your example to wrap by adding the following CSS:
ul { list-style: none; }
ul li { display: inline; }
ul a {
display: inline;
float: left;
}
ul img { display: block; }
I think this is essentially what you're missing, so you'll probably want to adjust things to how you like (including spacing, classes, etc.). Here is my fiddle: http://jsfiddle.net/jC84f/3/

Angled headings in CSS

Does anyone have any ideas to achieve this angled heading effect with CSS only?
The box shadow shouldn't be a problem using a generator like this, but I'm unsure on the angled edges - perhaps CSS3's transform?
Write this:
h1{
font-size:24px;
display:inline-block;
position:relative;
margin:20px;
}
h1:after{
content:'';
position:absolute;
top:0;
bottom:0;
left:-10px;
right:-10px;
background:red;
z-index:-1;
-moz-transform: skew(-25deg);
-webkit-transform: skew(-25deg);
box-shadow:3px 3px 0 0 #000;
-moz-box-shadow:3px 3px 0 0 #000;
-webkit-box-shadow:3px 3px 0 0 #000;
}
Check this http://jsfiddle.net/RP356/
You can achieve that with just transform:skew():
transform:skew(-30deg,0);
-ms-transform:skew(-30deg,0); /* IE 9 */
-moz-transform:skew(3-0deg,0); /* Firefox */
-webkit-transform:skew(-30deg,0); /* Safari and Chrome */
-o-transform:skew(-30deg,0); /* Opera */
As you can see here.
P.S. However keep in mind the “Heading” text and the skewed part have to be separate elements to avoid affecting the text too.
(In case the text is a child, you could set it straight using the opposite transformation: transform:skew(30deg,0).)
Yes it is transform. Following css does it for -20 degrees. and a white shadow
.box {
-moz-transform: scale() rotate(0deg) translate(0px, px) skew(-20deg, deg);
-webkit-transform: scale() rotate(0deg) translate(0px, px) skew(-20deg, deg);
-o-transform: scale() rotate(0deg) translate(0px, px) skew(-20deg, deg);
-ms-transform: scale() rotate(0deg) translate(0px, px) skew(-20deg, deg);
transform: scale() rotate(0deg) translate(0px, px) skew(-20deg, deg);
-webkit-box-shadow: 10px 10px 5px 5px #ffffff;
-moz-box-shadow: 10px 10px 5px 5px #ffffff;
box-shadow: 10px 10px 5px 5px #ffffff;
}
In order to #SvenBieder answer, it is better to use something like this:
body {
background: #ddd;
}
h1 {
position: relative;
font-family: sans-serif;
color: #fff;
width: 400px;
margin: 20px;
padding: 5px;
}
/* In CSS3 it is ::before, but IE doesn't support this */
h1:before {
content: '';
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: -5px;
z-index: -1;
background: #555;
-webkit-transform: skew(-20deg);
-moz-transform: skew(-20deg);
-o-transform: skew(-20deg);
-ms-transform: skew(-20deg);
transform: skew(-20deg);
-webkit-box-shadow: 10px 10px 0px 3px #ffffff;
-moz-box-shadow: 10px 10px 0px 3px #ffffff;
box-shadow: 10px 10px 0px 3px #ffffff;
}
Live example: http://jsfiddle.net/fjPbr/1/
It's better because it don't skew the content and it has less code.

Resources