CSS for slant diagonal line - css

Can some CSS expert help guide me to achieve slant line in a box via css. I can't attached the image. I know this can be done but lack of expert knowledge over css I am missing the way to achieve this. I am referring to this example. If you go end of the page (slanthowto.html) there is a image which show only slanted black line... I want to implement the same.
Regards,

That's the CSS and HTML code for the slanted black line:
.borderdraw {
border-style:solid;
height:0;
line-height:0;
width:0;
}
<div style="position: relative; width: 100px; height: 100px;">
<div style="position: absolute; top: 0px; left: 0px; border-color: transparent transparent transparent rgb(64, 0, 0); border-width: 0px 0px 65px 87px;" class="borderdraw"><!-- --></div>
<div style="position: absolute; top: 0px; left: 0px; border-color: transparent transparent transparent rgb(255, 240, 240); border-width: 0px 0px 64px 85px;" class="borderdraw"><!-- --></div>
</div>
EDIT: You can also copy the properties from the class to the style attribute:
<div style="position: relative; width: 100px; height: 100px;">
<div style="position: absolute; top: 0px; left: 0px; border-color: transparent transparent transparent rgb(64, 0, 0); border-width: 0px 0px 65px 87px; border-style: solid; height: 0; line-height: 0; width: 0;"><!-- --></div>
<div style="position: absolute; top: 0px; left: 0px; border-color: transparent transparent transparent rgb(255, 240, 240); border-width: 0px 0px 64px 85px; border-style: solid; height: 0; line-height: 0; width: 0;"><!-- --></div>
</div>

Update for 5 years later (2015)...
2D transforms enjoy much better support now. They'll also do the work of eliminating that "crunch" or jagged edges you may have seen with the previous method. CSS below.
.slanted-line {
width: 300px;
background: black;
height: 2px;
/* bonus rounded edges */
border-radius: 1px;
transform: rotate(-45deg);
-os-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
/* helps with positioning */
transform-origin: 100% 100%;
-o-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
-moz-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
}
<div class="slanted-line"></div>
Browser support according to caniuse.com:
IE 9+
Firefox 31+
Chrome 31+
Safari 7+
Opera 27+
iOS Safari 7.1+
Android Browser 4.1+
Mobile Chrome 41+
DEMO EXAMPLE

Don't use this method. No seriously, don't. Look at the date at the bottom of the page. It says
Last modified: Thu Jan 30 21:56:16 Romance Standard Time 2003
That's seven years ago. Technology's moved on. We don't do this anymore. Just go use any graphics manipulation software, draw yourself a triangle, and use either of these two techniques to stick a image into your webpage.
First of all, the image. Here's one I created in Paint earlier:
Then, with either the img tag
<img src="triangle.png" alt="Triangle!" />
or the background, with CSS method
<div class="triangle"></div>
.triangle {
background: url('triangle.png') no-repeat;
width: 120px;
height: 120px;
}
That's better, isn't it.

Related

CSS: backdrop-filter for button borders (potential solution?)

I am trying to create colored borders around buttons. The buttons themselves have a transparent but blured background (backdrop-filter). The borders however should be lighter/oversaturated depending on the image behind the the buttons. Essentially what I am trying to do is to apply seperate backdrop-filters to the borders.
Example from MusicBee
What I've tried so far:
just making the border a transparent white: looks good on flat colored backgrounds, but not on images
playing around with hsla(): the saturation/lightness components are there, but I can only use one (hue-)color
putting a div with slight overlap behind the buttons and using the filters on that: works with flat colored buttons, but I want mine to be transparent
EDIT:
I've found a "solution", but it's a rather ugly and restrictive one. Notice when you increase the thickness, the edges on the corners become really apparent. Is it possible to fix this?
https://codepen.io/schlossgeist/pen/YzVEear
(You may want to resize your window when viewing this example, so the button sits over a more colorful area, where the effect is more noticeable.)
I don't take credit for this concept, it has been done many times, not just in this exact same way.
CODE:
html
<div id=wrapper>
<a href="http://stackoverflow.com" class="links">Link
<div class="linkT"></div>
<div class="linkR"></div>
<div class="linkB"></div>
<div class="linkL"></div>
</a>
</div>
As you can see, I am using a div for every edge, so I have full flexability.
css
:root {
--thickness: 1.5px;
--brightness: 2;
--blur: 5px;
}
.linkT{
border-radius: 50px 50px 0px 0px;
height: var(--thickness);
top: 0;
right: 0;
left: 0;
background: transparent;
position: absolute;
backdrop-filter: brightness(var(--brightness));
filter: blur(var(--blur));
}
.linkR{
border-radius: 0px 50px 50px 0px;
width: var(--thickness);
top: 0;
right: 0;
bottom: 0;
background: transparent;
position: absolute;
backdrop-filter: brightness(var(--brightness));
filter: blur(var(--blur));
}
.linkB{
border-radius: 0px 0px 50px 50px;
height: var(--thickness);
right: 0;
bottom: 0;
left: 0;
background: transparent;
position: absolute;
backdrop-filter: brightness(var(--brightness));
filter: blur(var(--blur));
}
.linkL{
border-radius: 50px 0px 0px 50px;
width: var(--thickness);
top: 0;
bottom: 0;
left: 0;
background: transparent;
position: absolute;
backdrop-filter: brightness(var(--brightness));
filter: blur(var(--blur));
}
Sadly, you can only use 2 filters on the border (one normal "filter" and one "backdrop-filter"). I found that blur and brightness are the best for my intended effect.
Can this method be improved/simplyfied in any way?

Multiple U shapes divs

I'm trying to obtain some nice U shapes divs.
This is the expected result (it must look nice and be responsive):
This is the solution I found for footer (the shape is not so good as I want):
footer:after {
content: "";
display: block;
position: absolute;
border-radius: 0px 0px 50% 50%;
width: 100%;
height: 140px;
background-color: white; /* but if I choose a bg image for about us this solution is wrong */
left: 0;
top: 0px;
}
I will have multiple sections similar to #about-us. Can you suggest a nice starting solution here? Please keep in mind in brand section background I have an animation, in footer a background image. This is why I can't use in about-us the solution I used for footer. It's kind of let's cut this div with an oval and make this section transparent.
UPDATE:
My current header / about us annoying merge. Adding a gray shape (inside header or in top of about us) is not a solution.
.u-shape {
height: 120px;
right: -100px;
left: -100px;
z-index: 1000;
position: absolute;
margin: 0 auto;
}
.u-shape.top {
top: -120px;
background: radial-gradient(ellipse at 50% 0, transparent 69%, white 70%);
}
.u-shape.bottom {
top: 0;
background: radial-gradient(ellipse at 50% 0, white 69%, transparent 70%);
}
Usage:
<header>...</header>
<div class="u-shape top"></div>
<div id="about-us"></div>
<div class="u-shape bottom"></div>
<footer>...</footer>
Useful:
https://codepen.io/thebabydino/pen/wFvmA

Using perspective and transform ruins my site at different resolutions

I'm trying to create a 3D responsive mockup for a sign with perspective and transform, but I'm having some difficulty.
This is what I'm trying to do:
It looks good but when I'm changing my screen size it looks terrible:
I really don't know how to make it responsive.
This is my code up to now:
#import url('https://fonts.googleapis.com/css?family=Pacifico');
* {
padding: 0;
margin: 0;
font-family: 'Pacifico', cursive;
}
.mockup {
position: relative;
width: 100%;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-perspective: 500px;
perspective: 500px;
}
.mockup--background {
width: 100%;
}
.mockup--crop {
position: absolute;
top: 30%;
left: 14%;
width: 52%;
padding: 1.8% 0;
font-size: 3em;
text-align: center;
background: rgb(141,126,127);
color: #fff;
text-shadow: -1px 0px #bab1b2,
-2px 1px #bab1b2,
-3px 2px #bab1b2,
-5px 3px #bab1b2,
-5px 4px #bab1b2,
-6px 5px #bab1b2;
background: -moz-linear-gradient(45deg, rgba(141,126,127,1) 0%, rgba(169,160,165,1) 100%);
background: -webkit-linear-gradient(45deg, rgba(141,126,127,1) 0%,rgba(169,160,165,1) 100%);
background: linear-gradient(45deg, rgba(141,126,127,1) 0%,rgba(169,160,165,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#8d7e7f', endColorstr='#a9a0a5',GradientType=1 );
}
.perspective {
transform: rotateY(22deg) rotateX(6deg) skewY(22deg) skewX(-2deg);
}
<div class="mockup">
<img class="mockup--background" src="https://designshack.net/wp-content/uploads/screenshot_1-o-1024x681.png" />
<div class="mockup--crop perspective">
Mock Up
</div>
</div>
Fiddle demo
After a lot of fine-tuning, I think I've got it fit perfectly
Fiddle
The HTML now only consists of two elements
<div class="mockup">
<div class="mockup--crop">Mock Up</div>
</div>
I've removed the img tag because the image is clearly a background-image, so I figured it'd be semantically correct to move it to the CSS
.mockup{
position: relative;
perspective: 150vw;
padding-bottom: 66.5%;
background-image: url('https://designshack.net/wp-content/uploads/screenshot_1-o-1024x681.png');
background-size: 100% 100%;
}
.mockup--crop {
position: absolute;
top: 16.125%;
left: 17.5%;
width: 63.2%;
height: 28.8%;
background-image: linear-gradient(to bottom right, #8D7E7F 0%, #A9A0A5 100%);
text-align: center;
font-size: 10vw;
color: #FFF;
text-shadow: -.1vw .1vw #BAB1B2,-.2vw .2vw #BAB1B2,-.3vw .3vw #BAB1B2,-.4vw .4vw #BAB1B2,-.5vw .5vw #BAB1B2,-.6vw .6vw #BAB1B2,-.7vw .7vw #BAB1B2,-.8vw .8vw #BAB1B2,-.9vw .9vw #BAB1B2,-1vw 1vw #BAB1B2;
transform: rotateZ(18.7deg) rotateY(47.5deg) rotateX(32.9deg);
transform-origin: 0 0;
}
.mockup has a padding-bottom of 66.5%, which is the ratio of the image (100 / (1024 / 681)). It also has a perspective of 150vw. This is a value I've come to as I was tweaking the transforms etc.
I've moved .mockup--crop's upper left corner to the upper left corner of the sign in the background, and gave it perspective-origin: 0 0;, so that I could easily transform it with a fixed, correct point. The rest is self explanatory.
#noJavaScript

Rectangle with two cut edges

I'm not sure what is specific name for this shape but can I just called it "half Parallelogram" ? I want make this shape purely using CSS/CSS3. Any help? or tutorial?
You can do it using pseudo-elements like below. The approach is to cut out a triangle shape from the left-bottom and top-right of the box. This method can be used with either a solid color an image inside the shape as long as the body background is a solid color. When the body background is a non-solid color this approach will not work because the border hack needs a solid color background.
The advantage of this method is that it can support cuts of different angles at each side (like in the question where the hypotenuse of the triangular cut on either side are not parallel to each other).
div {
background: red;
width: 200px;
height: 100px;
position: relative;
}
div:before {
position: absolute;
height: 0;
width: 0;
content: ' ';
border: 20px solid white;
border-color: transparent transparent white white;
border-width: 20px 0px 0px 15px;
left: 0;
top: 80px;
}
div:after {
position: absolute;
height: 0;
width: 0;
content: ' ';
border: 20px solid white;
border-color: white white transparent transparent;
left: 170px;
top: 0px;
}
.with-img {
background: url(http://lorempixel.com/100/100);
}
<div></div>
<br>
<div class="with-img"></div>
Sample 2: You can also achieve a similar effect using gradients. Just 1 gradient is enough to produce a cut of similar angle on both sides. If different angles are required then two gradients should be used. However the multiple gradient approach mentioned here will not work when the body background is a non-solid color.
div {
width: 200px;
height: 100px;
position: relative;
}
.with-single-gradient {
background: linear-gradient(45deg, transparent 5%, yellowgreen 5%, yellowgreen 90%, transparent 90.5%);
}
.with-single-gradient.image {
background: linear-gradient(45deg, white 5%, transparent 5%, transparent 90%, white 90.5%), url(http://lorempixel.com/100/100);
}
.with-multiple-gradient.image {
background: linear-gradient(45deg, transparent 0%, transparent 90%, white 90%), linear-gradient(60deg, white 10%, transparent 5%, transparent 100%), url(http://lorempixel.com/100/100);
}
<div class='with-single-gradient'></div>
<br>
<div class='with-single-gradient image'></div>
<br>
<div class='with-multiple-gradient image'></div>
Sample 3: This can also be created using SVG and is the best method yet. All that it requires is just a single path element which creates the required shape.
<svg viewBox='0 0 100 60' width='200px' height='120px'>
<path d='M0,0 80,0 100,16 100,60 10,60 0,54z' fill='yellowgreen' />
</svg>
Tested on Chrome v24, Firefox v19, Safari v5.1.7 (on Windows) and IE v10. They are older versions but should work in the latest versions also.
Note: IE versions less than 10 do not support gradients as mentioned in this SO thread.
there's no thing as straight radius, but here you have some tutorials. For weird shapes, you need to use a combination of shape and negative space, basically using figures with the same color of the background . The good news is you could use "transparent" as color, so you can "fake" this figures in an easy way. See tutorials Shapes of CSS or yuo can use a generator like CSS Shape Generator or CSS Shape Generator 2 but they will highly depend on your needs. Personally, I'd use a BG image and be a happy camper
to make this shape you have to use pseudo class.
and i hope it will help you
div { display: inline-block; margin: 20px; float: left; }
shape {
width: 208px;
height: 130px;
background: red;
position: relative; }
shape:before {
content: "";
position: absolute;
top: 0;
left: 0;
border-bottom: 29px solid red;
border-right: 29px solid #fff;
width: 179px;
height: 0; }
shape:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
border-top: 29px solid red;
border-left: 29px solid #fff;
width: 42px;
height: 0; }
demo
2 gradients and background-size can be used too :
div {
width: 1440px;
height: 590px;
background:
linear-gradient(45deg, transparent 80px, #FF0000 80px) left no-repeat,
linear-gradient(-135deg, transparent 160px, #FF0000 160px) top right no-repeat;
background-size: 50% 100%;
}
<div>
</div>
1 gradients and calc() can be used too :
div {
width: 1440px;
height: 590px;
background:
linear-gradient(45deg, transparent 80px, #FF0000 80px, #FF0000 calc( 100% - 160px), transparent calc( 100% - 160px) );
}
<div>
</div>
Related to duplicate question https://stackoverflow.com/questions/36932294/how-can-i-create-the-object-in-picture-below-using-css-border-radius :
div {
width:980px;
height:460px;
background:linear-gradient(140deg,transparent 200px, #FFCB05 200px) left no-repeat,
linear-gradient(-40deg,transparent 80px, #FFCB05 80px) top right no-repeat;
background-size:50% 100% ;
}
<div>
div shape
</div>
image
<img src="http://i.stack.imgur.com/M48zP.png" />
For the second shape use this:
border-bottom-left-radius:50px;
border-top-right-radius:50px;
Check JSFiddle Demo
Edit:
Question is edited and second shape has been removed.
You can add an element with overflow: hidden;
skew transform the parent by desired angle. Unskew the pseudoelement by the negative of that angle.
Using this approach, you can also add images to background.
div {
height: 100px;
width: 220px;
overflow: hidden;
position: relative;
-webkit-transform: skewX(45deg);
-moz-transform: skewX(45deg);
transform: skewX(45deg);
}
div:before {
content: '';
position: absolute;
left: 10px;
height: 100px;
width: 200px;
background: red;
-webkit-transform: skewX(-45deg);
-moz-transform: skewX(-45deg);
transform: skewX(-45deg);
}
<div></div>
FIDDLE
FIDDLE (with image)

Rounded arrows with CSS [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to create a triangle in CSS3 using border-radius
Are they possible to make with CSS?
Normal arrow:
.some_element:after{
content: '';
height: 0;
width: 0;
position: absolute;
top: 0;
left: 0;
border: 100px solid transparent;
border-top-color: #000;
}
( http://jsfiddle.net/W3xwE/ )
Rounded arrow (I want only the bottom side rounded):
:(
Yes, it is possible! You rotate the box, give it a border-radius and use a 45deg linear-gradient as a background.
DEMO
HTML:
<div class='arrow'></div>
CSS:
.arrow {
width: 7em;
height: 7em;
border-radius: 0 0 2em 0;
margin: 5em;
transform: rotate(45deg);
background: linear-gradient(-45deg, black 50%, transparent 50%);
}
If you want the angle of the arrow to be different, then you can also skew it.
Take into account the fact that CSS gradients are not supported by IE9 (I am not saying "or older" this time because you mention CSS3 among your tags). The solution in that case would be to use a solid background and to somehow make sure the upper part won't show, either by covering it with a preceding element, or by clipping it (see the answer Tim Medora provided).
Also, at this point there is still no support for the unprefixed syntax (although this will soon change :D ), so you will need to either manually add the prefixes -webkit-, -moz-, and -o-. (I did not add them in the demo because Dabblet uses -prefix-free which takes care of doing this.)
Here's a way to do it by placing a rotated square inside a box to control clipping. Personally, I think #Ana's solution is much cleaner.
http://jsfiddle.net/K44mE/14/
<div id="outer"><div id="inner"> </div></div>
#inner{
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-o-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
background-color:silver;
width:100px;
height:100px;
top: -70px;
left: 20px;
position:relative;
-moz-border-radius: 20px;
border-radius: 20px;
}
#outer {
position: absolute;
width: 140px;
height: 70px;
top:10px;
left:10px;
overflow: hidden;
border: 1px solid red;
}
CSS
.arrow {
width: 7em;
height: 7em;
border-radius: 0 0 2em 0;
margin: -2em 2.5em;
transform: rotate(45deg);
background: linear-gradient(-45deg, black 50%, transparent 50%);
}
HTML
<div class='arrow'></div>

Resources