i was wondering if its possible to add gradients to border top without it affecting border right or border left which in this case are transparent. i tried adding a gradient color but it would affect border left and border right im trying to let border left and border right to be transparent
#borderone {
border-top: 33px solid #354658;
border-left: 33px solid transparent;
border-right: 33px solid transparent;
margin: 0 auto;
min-width: 1277px;
}
<div id='borderone'></div>
as you can see this is what i want it to do although i want a gradient background color instead of this solid dark blue color http://jsfiddle.net/EHELN/
See this :
http://css-tricks.com/examples/GradientBorder/
It is enough for me in my career .
For example:
#borderone:first-child:before {
content:'';
position:absolute;
width:100%;
height:4px;
background:linear-gradient(to left, #354658, #9EBBDA);
top:-33px;
left:-5;
}
For your case , you should use before & first-child pseudo-selectors CSS in the same time.
top(in pseudo selector) = -border height = -33 px
FIDDLE: http://jsfiddle.net/abdennour/EHELN/2/
You can get this efect using background for the gradient, and the 2 pseudo elements at the left and right to get the slanted corners
.test {
border-left: 33px solid transparent;
border-right: 33px solid transparent;
height: 33px;
background: linear-gradient(90deg, black, blue);
margin: 0 auto;
min-width: 42px;
background-clip: content-box;
position: relative;
}
.test:before, .test:after {
content: '';
position: absolute;
width: 33px;
height: 100%;
}
.test:before {
background: linear-gradient(45deg, transparent 50%, black 50%);
right: 100%;
}
.test:after {
background: linear-gradient(315deg, transparent 50%, blue 50%);
left: 100%;
}
demo
Looks like I missunderstood the direction. Try this to make it the other way (for webkit)
.test {
border-left: 33px solid transparent;
border-right: 33px solid transparent;
height: 33px;
background: linear-gradient(0deg, black, red);
margin: 0 auto;
min-width: 42px;
background-clip: content-box;
position: relative;
}
.test:before, .test:after {
content: '';
position: absolute;
width: 45px;
height: 45px;
bottom: 0px;
}
.test:before {
-webkit-transform: rotate(45deg);
-webkit-transform-origin: bottom right;
background: linear-gradient(-45deg, black 0, red 32px, transparent 32px);
right: 100%;
}
.test:after {
-webkit-transform: rotate(-45deg);
-webkit-transform-origin: bottom left;
background: linear-gradient(45deg, black 0, red 32px, transparent 32px);
left: 100%;
}
demo 2
if you want to draw a gradient on your border, then you could use border-image or translucide borders with a gradient in bg : DEMO
But then :
You can even drop your translucide borders and make it a padding: DEMO
#borderone {
position:relative;
padding:33px 33px 0;/* well this is just like transparent borders :) */
margin: 0 auto;
height:100px;
background:linear-gradient(
to bottom,
#354658,
#9EBBDA 33px,
transparent 33px
);
}
http://www.colorzilla.com/gradient-editor/
This is for the background and not the border, but you can likely create the same effect you are looking for by using this tool.
Related
First of all, this question might be similar to this, but the shape in my case is different, so it couldn't really help me out.
The trapezoid code is the following:
#light {
/*setting the element*/
border-bottom: 164px solid grey;
border-left: 148px solid transparent;
border-right: 165px solid transparent;
height: 0;
width: 80px;
}
<div id="light"></div>
Just to clarify, I am trying to add the shadow effect, similar to the following example:
#bulb {
/*setting the element*/
background: grey;
width: 200px;
height: 200px;
border-radius: 50%;
/*adding "light" (shadow)*/
box-shadow: 0 0 100px 10px rgba(128, 128, 128, 0.5);
}
<div id="bulb"></div>
When I try to add the regular box-shadow:, my trapezoid becomes a regular rectangle with white parts.
Instead of a box-shadow you could use a drop-shadow filter, e.g.
filter: drop-shadow(0 0 40px #222);
#light {
/*setting the element*/
border-bottom: 164px solid grey;
border-left: 148px solid transparent;
border-right: 165px solid transparent;
height: 0;
width: 80px;
filter: drop-shadow(0 0 40px #222);
}
<div id="light"></div>
More info on MDN
I would create the shape differently using pseudo element with a blur effect:
#light {
width:400px;
height:160px;
position:relative;
}
#light:before,
#light:after{
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:
/*triangle on the right*/
linear-gradient(to top right,grey 49.5%,transparent 50%) right/150px 100%,
/*triangle on the left*/
linear-gradient(to top left, grey 49.5%,transparent 50%) left /150px 100%,
/*rectangle at the center*/
linear-gradient(grey,grey) center/100px 100%;
background-repeat:no-repeat;
}
#light:before {
filter:blur(20px);
}
<div id="light">
</div>
based on css-tricks Double-Box Method you can "have a container box with hidden overflow and another box inside it which is rotate and hangs out of it"
.light {
width: 350px;
height: 135px;
position: relative;
overflow: hidden;
box-shadow: 0 16px 10px -17px rgba(0, 0, 0, 0.5);
}
.light:after {
content: "";
position: absolute;
width: 300px;
height: 300px;
background: #999;
transform: rotate(45deg);
top: 25px;
left: 25px;
box-shadow: -1px -1px 10px -2px rgba(0, 0, 0, 0.5);
}
<div class="light"></div>
In your example, you can't add a proper box-shadow without having these white parts on each side. That is because the CSS border colouring the grey shaped trapeziod DIV.
In the example above, they are using an .SVG file (image), since it is an image, the original shape of it is a trapezoid, not a rectangle with white side like yours.
You will need to draw an .svg in the shape and color you want, and then add a shadow to the element itself.
Here are more informations about SVG.
I hope it helps.
I want to create a striped border.
I want to use the img tag or div tag to include the image on top of the Striped Border.
This is how it needs to look like:
Now I am trying like this with border image as svg.
.feed-item:after {
background: #0055b9;
background: url(../images/studentslab_hover_stripe_bg.svg);
background-repeat: no-repeat;
background-size: 100% 100%;
padding: 4vw 2.7vw 2vw 2vw;
width: 104%;
opacity: 0;
}
.feed-item:hover:after {
opacity: 1;
z-index: -1;
}
But in responsiveness, it's not covering full sometimes because my striped background image has dimension height and width.
So I want to use it like a border. Is there any way?
Use a repeating linear gradient on the pseudo-element and then position it absolutely behind the parent div.
The move it on hover.
div {
width:150px;
height: 200px;
margin:1em auto;
border:2px solid green;
position: relative;
background: white;
}
div:after {
content:"";
position: absolute;
z-index:-1;
top:0;
left:0;
height:100%;
width:100%;
background: repeating-linear-gradient(
-45deg,
transparent 0,
transparent 4px,
blue 4px,
blue 8px);
transition:all .25s ease;
}
div:hover::after {
left:8px;
top:8px;
}
<div>Hover me</div>
You can consider a multipe background coloration like below:
.box {
width: 100px;
height: 200px;
border-right: 10px solid transparent;
border-bottom: 10px solid transparent;
background:
linear-gradient(#fff,#fff) center/calc(100% - 2px) calc(100% - 2px) padding-box,
linear-gradient(blue,blue) padding-box,
linear-gradient(#fff,#fff) top right /10px 10px border-box,
linear-gradient(#fff,#fff) bottom left/10px 10px border-box,
/* you can replace this gradient with your SVG*/
repeating-linear-gradient( -45deg,
transparent 0, transparent 2px,
blue 2px, blue 4px) border-box;
/**/
background-repeat:no-repeat;
display:inline-block;
}
<div class="box"></div>
<div class="box" style="width:200px;"></div>
<div class="box" style="width:200px;height:100px"></div>
I have defined two CSS classes that highlights corners of table cells:
.right
{
background-image: linear-gradient(225deg, green, green 5px, transparent 5px, transparent);
}
.left
{
background-image: linear-gradient(135deg, orange, orange 5px, transparent 5px, transparent);
}
(example of usage)
<td /*some attributes*/ class="right">value</td>
When I use it for table cells, it looks like this:
But both of them sets background so I can't use both of them to the same cell. Is here any way how to highlight both corners of the same cell?
I have already solved this problem, I just made combined class
.note.approving
{
background-image: linear-gradient(225deg, green, green 5px, transparent 5px, transparent), linear-gradient(135deg, orange, orange 5px, transparent 5px, transparent);
}
Here is an alternative solution, using pseudo-elements to insert CSS triangles:
table {
border-collapse: collapse;
}
td {
position: relative;
overflow: hidden;
border: 1px solid #ccc;
padding: 1.6em 1em;
}
td.left::before,
td.right::after {
content: "";
position: absolute;
top: -5px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
td.left::before {
left: -5px;
transform: rotate(90deg);
border-bottom: 10px solid orange;
}
td.right::after {
right: -5px;
transform: rotate(-90deg);
border-bottom: 10px solid green;
}
<table>
<tr>
<td class="left">1</td>
<td class="left right">2</td>
<td class="right">3</td>
</tr>
</table>
While a lot more verbose than OP's own solution (using background gradients), this might have some additional value to some, seeing that the pseudo elements could enable you to add pointer events to them, depending on your exact scenario.
I'm trying the find a way to have a dynamic border with a triangle. For the moment, with the basic gradient effect, this is what I did:
My current effect in action
But as you can see, the background has a gradient and we can see the border background that does not match..
How can I achieve this effect? Also, the text may vary on different screen size and with other words.
Thank you!
Using pseudo-elements and skewX is one clean way to achieve this. Check this out, I'm using a top, left & right border on the element, and then style the before as the left bottom border and the after as the right one:
body {
background-color: white;
background-image: linear-gradient(45deg, #999 25%, transparent 25%, transparent 75%, black 75%, black), linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, #999 75%, #999);
background-size: 10px 10px;
background-position: 0 0, 50px 50px;
}
.dialog {
text-align: center;
color: green;
font-size: 65px;
width: 300px;
height: 120px;
background-color: transparent;
border-width: 5px 5px 0 5px;
border-color: red;
border-style: solid;
display: inline-block;
position: relative;
}
.dialog:before {
content: '';
border-top: 5px solid red;
border-right: 5px solid red;
transform-origin: left top;
transform: skewX(45deg);
position: absolute;
content: ' ';
height: 10px;
width: 46%;
background: inherit;
left: -5px;
bottom: -10px;
}
.dialog:after {
content: '';
border-top: 5px solid red;
border-left: 5px solid red;
transform-origin: left top;
transform: skewX(-45deg);
position: absolute;
content: ' ';
height: 10px;
width: 46%;
background: inherit;
right: -5px;
bottom: -10px;
}
<div class="dialog">Here I am</div>
To achieve this you can make it with a background image, for exemple http://bootsnipp.com/snippets/featured/carousel-reviews-with-rating.
As you can see he take an image and resize it to take only a triangle like this:
.sprite-i-triangle {
background-position: 0 -1298px;
height: 44px;
width: 50px;
}
Try to find an image that meets your expectations. Otherwise you have some exemples in this site. (http://bootsnipp.com)
Below is the image I am trying for, I managed to get a square using CSS, but I am trying for horizontal and vertical line in a square.
.hub{
width: 119px;
height: 101px;
background: #b5adad;
}
<div class="hub"></div>
There are many ways to do this and one would be to use gradients like below: (the image in question was actually a rectangle.)
The approach is very simple - we use 2 linear gradients to create two thin solid colored lines and then position the images such that they match our needs. Linear gradients are used even though it creates only a solid color because it is easier to control size and position of an image than background color.
div {
height: 100px;
width: 200px;
border: 1px solid red;
background-image: linear-gradient(to bottom, red, red), linear-gradient(to right, red, red);
background-repeat: no-repeat;
background-size: 1px 100%, 100% 1px;
background-position: 20px 0px, 0px 10px;
}
<div></div>
We can also create an output which has a fade-out or shadow effect like in the image in question:
div {
height: 100px;
width: 200px;
border: 1px solid;
background-color: gray;
background-image: linear-gradient(to bottom, black, black), linear-gradient(to right, red, transparent), linear-gradient(to right, black, black), linear-gradient(to bottom, red, transparent);
background-repeat: no-repeat;
background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
background-position: 20px 0px, 21px 0px, 0px 10px, 0px 11px;
box-shadow: inset 0px 0px 3px red;
}
<div></div>
Another way is to use :before and :after pseudo-elements:
.hub{
width: 119px;
height: 101px;
background: #b5adad;
position: relative;
padding: 18px 0 0 18px;
}
.hub:after, .hub:before {
content: " ";
background: black;
display: block;
position: absolute;
}
.hub:after {
width: 1px;
height: 100%;
left: 15px;
top: 0;
}
.hub:before {
width: 100%;
height: 1px;
top: 15px;
left: 0;
}
<div class="hub">Lorem ipsum dolor amet</div>