I'm designing a site for a school project, and I'm trying to design a particular style for the buttons and navigation, but I'm not sure how to go about this.
I considered doing a border effect, but I stopped short as I realized that it doesn't just involve changing individual side's colors but cutting two sides in half and coloring those pieces differently. A gradient on a div behind it might work, but not only would that get complicated, but it would look blurry while I'm going for sharpness like an edge on a 3D shape. Is this doable, or would I have to use images?
EDIT: Wow, looks like there's a lot of methods out there. Code Golf, anyone?
A solution without css gradient if you want to support IE8 too: http://jsfiddle.net/2am780pq/
HTML:
<a class="button">Cool</a>
CSS:
.button {
display: inline-block;
position: relative;
background-color: #4755e7;
padding: 10px 20px;
color: #fff;
}
.button:before {
content: '';
position: absolute;
top: 50%;
bottom: -5px;
left: -5px;
right: -5px;
margin: auto;
background-color: #4451dc;
z-index: -1;
}
.button:after {
content: '';
position: absolute;
top: -5px;
bottom: 50%;
left: -5px;
right: -5px;
margin: auto;
background-color: #5d67e9;
z-index: -1;
}
without gradient nor pseudo-elemts, box-shadow could do the job too:
http://codepen.io/anon/pen/NPaZBd
a{
display: inline-block;
color: #FFF;
padding:5px 1em;
line-height:2em;
background:#4755E7;
margin:1em;
box-shadow:-0.8em -0.8em 0 -0.5em #5d67e9,
0.8em -0.8em 0 -0.5em #5d67e9,
-0.8em 0.8em 0 -0.5em #4451dc,
0.8em 0.8em 0 -0.5em #4451dc;
}
/* add an inside blurry border too ? */
a:nth-child(even) {
box-shadow:-0.8em -0.8em 0 -0.5em #5d67e9,
0.8em -0.8em 0 -0.5em #5d67e9,
-0.8em 0.8em 0 -0.5em #4451dc,
0.8em 0.8em 0 -0.5em #4451dc,
inset 0 0 1px
}
link
link link
link bigger link
link even bigger works still
Yes, with gradient backgrounds and nested elements. This is NOT cross-browser compatible in browsers that do not support CSS3.
Live example: JSFiddle
The HTML:
<span>Click Me</span>
The CSS:
.button {
display: inline-block;
padding: 4px;
background: rgba(115,127,255,1);
background: -moz-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(115,127,255,1)), color-stop(50%, rgba(68,81,220,1)), color-stop(51%, rgba(68,81,220,1)), color-stop(100%, rgba(68,81,220,1)));
background: -webkit-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: -o-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: -ms-linear-gradient(top, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
background: linear-gradient(to bottom, rgba(115,127,255,1) 0%, rgba(68,81,220,1) 50%, rgba(68,81,220,1) 51%, rgba(68,81,220,1) 100%);
}
.button span {
display: inline-block;
background: #4755E7;
color: #fff;
padding: 0.5em 0.75em;
}
Here one element solution, simplier markup :D
<b>Im sexy and i know it!</b>
http://jsfiddle.net/ebdq20vm/1/
b {
padding: 20px;
display: inline-block;
color: #FFF;
background: #5d67e9;
background: -moz-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, #5d67e9), color-stop(51%, #4451dc));
background: -webkit-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: -o-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: -ms-linear-gradient(top, #5d67e9 50%, #4451dc 51%);
background: linear-gradient(to bottom, #5d67e9 50%, #4451dc 51%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5d67e9', endColorstr='#4451dc', GradientType=0);
position: relative;
z-index: 5;
}
b:before {
content:'';
position: absolute;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
background-color: #4755E7;
display: block;
z-index: -1;
}
Related
I have a semi-round button. But I don't know how to bend it for my semi-round button in it's border.
.semi-circle {
display: inline-block;
padding: 9px 16px;
border-radius: 999px !important;
text-align: center;
/*border: 10px solid transparent;*/
/* -moz-border-image: -moz-linear-gradient(right, #FC913A 0%, #FF4E50 100%);
-webkit-border-image: -webkit-linear-gradient(right, #FC913A 0%, #FF4E50 100%);
border-image: linear-gradient(to left, #FC913A 0%, #FF4E50 100%);*/
/*border-image-slice: 1;*/
border: linear-gradient(to right, green 0%, blue 100%);
/*background-image: linear-gradient(to left, #FC913A 0%, #FF4E50 100%);*/
background-image: -o-linear-gradient(to left, #FC913A 0%, #FF4E50 100%);*/
background-image: -moz-linear-gradient(to left, #FC913A 0%, #FF4E50 100%);*/
background-image: -webkit-linear-gradient(to left, #FC913A 0%, #FF4E50 100%);*/
background-image: -ms-linear-gradient(to left, #FC913A 0%, #FF4E50 100%);*/
*/
}
Forgive me for not being able to embed the image because of lack of reputation. Thx for the stack overflow community for its great service.
Here is solution. It works fine in webkit. In other browsers text color is solid.
HTML
<button data-text="Round button"></button>
<button class="active" data-text="Active round button"></button>
CSS
body {
background: #384041;
}
*,
*:before,
*:after {
box-sizing: border-box;
}
button {
display: inline-block;
border: none;
outline: none;
appearance: none;
background: red;
position: relative;
z-index: 3;
height: 60px;
border-radius: 30px;
padding: 0 21px;
font-size: 21px;
box-shadow: -1px -1px 1px 0 black;
background: #4f4f4f;
}
button:before {
content: attr(data-text);
min-width: 144px;
z-index: -1;
border-radius: 27px;
color: #4f4f4f;
}
#media screen and (-webkit-min-device-pixel-ratio:0) { button:before {
background: #4f4f4f;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}}
button:after {
content: '';
position: absolute;
left: 3px;
right: 3px;
top: 3px;
bottom: 3px;
z-index: -2;
border-radius: 30px;
background: #151515;
}
button:hover {
cursor: pointer;
background: linear-gradient(to right, #2084c3 0%, #00caa0 100%);
}
.active {
background: linear-gradient(to right, #2084c3 0%, #00caa0 100%);
}
.active:before{
color: #2084c3;
}
#media screen and (-webkit-min-device-pixel-ratio:0) { .active:before {
background: linear-gradient(to right, #2084c3 0%, #00caa0 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}}
Demo
There are probably better ways to do this, but without further thinking I'd try something like this:
<style type="text/css">
.semi_outer {
padding: 2px;
text-align: center;
border-radius: 11px;
background: linear-gradient(to right, #0f0, #00f);
}
.semi_inner {
margin: 2px;
border-radius: 7px;
background-color: #000;
color: #0f0;
}
.semi_outer:hover {
background: linear-gradient(to right, #c00, #0c0);
}
.semi_outer:active {
background: linear-gradient(to right, #f00, #0f0);
}
</style>
<div class="semi_outer">
<div class="semi_inner">
semi_inner
</div>
</div>
This is your semi-round button . may be it will be helpfull for you.
.outer {
padding: 2px;
text-align: center;
border-radius: 11px;
background: linear-gradient(to right, #0f0, #00f);
width: 200px;
height:30px;
}
.inner {
margin: 3px;
border-radius: 7px;
background-color: #000;
color: #0f0;
height:25px;
}
.outer:hover {
background: linear-gradient(to right, #c00, #0c0);
}
.outer:active {
background: linear-gradient(to right, #f00, #0f0);
}
<div class="outer">
<div class="inner">
BUTTON
</div>
</div>
I'm constructing a site and a piece of the mockup is below
Since I'm using a content management system that builds the HTML, all I have to work with a single h3 tag. I want the line behind to have the width of the div containing the h3 tag. Is this possible?
Here's the closest that I can get: http://jsfiddle.net/rmgtq6h6/
h3.line-behind { width: auto; position: relative; text-align: center}
h3.line-behind:after { content: " "; border-top: 3px solid black; position: absolute; width:100%; top: 50%; left: 0; z-index: 1; }
Here you go:
https://jsfiddle.net/rmgtq6h6/1/
div.line-behind {
width: auto;
position: relative;
text-align: center
}
span {
content: " ";
border-top: 3px solid black;
position: absolute;
width: 100%;
top: 50%;
left: 0;
z-index: -1;
}
h3 {
background-color: #fff;
display: inline-block;
}
}
<div class="line-behind"><span></span>
<h3>Begin My Giving Journey</h3>
</div>
Or take a look here:
http://codepen.io/ericrasch/pen/Irlpm
if i understand correctly this is what are you looking for
h3.line-behind:after {
position:absolute;
content:'';
height:2px;
width:150%;
top:50%;
transform:translateY(-50%);
left:50%;
transform:translateX(-50%);
z-index:-1;
background: linear-gradient(to right, rgba(25,25,25,0) 0%,
rgba(25,25,25,1) 35%,
rgba(255,255,255,0) 36%,
rgba(255,255,255,0) 65%,
rgba(25,25,25,1) 66%,
rgba(25,25,25,0) 100%);}
fiddle here
or another example more practical add another pseudo-element ::before
h3.line-behind:after { position:absolute;
content:'';
height:2px;
width:50%;
top:50%;
transform:translateY(-50%);
left:0;
transform:translateX(-50%);
z-index:-1;
background: #000; }
h3.line-behind:before {position:absolute;
content:'';
height:2px;
width:50%;
top:50%;
transform:translateY(-50%);
right:0;
transform:translateX(50%);
z-index:-1;
background: #000; }
demo here
Place you text in some container
center this text
apply some width to the container
give the container some background color
h3.line-behind { width: auto; position: relative; text-align: center}
h3.line-behind:after { content: " "; border-top: 3px solid black; position: absolute; width:100%; top: 50%; left: 0; z-index: -1; }
#container{
margin:0 auto;
background-color:white;
width:40%;
}
<h3 class="line-behind"><div id="container">Begin My Giving Journey</div></h3>
We can build is easily with these guaranties 👇
No images
No extra
HTML Scalable (that is, you could add larger text
and it automatically sizes to fit)
Fluid
No JavaScript
Method 1: A Pseudo-Element
h1:before {
content:"";
display: block;
border-top: solid 1px black;
width: 100%;
height: 1px;
position: absolute;
top: 50%;
z-index: 1;
}
h1 span {
background: #fff;
padding: 0 20px;
position: relative;
z-index: 5;
}
Demo: http://jsfiddle.net/7s79zwz5/
Method 2: Adjacent Sibling Selector
h1+p {
border-top: solid 1px black;
padding-top: 40px;
margin-top: -40px;
}
Demo: http://jsfiddle.net/v9g3d4ua/
Method 3: Linear Gradient
h1 {
background: -moz-linear-gradient(#ffffff 0%, #ffffff 49%, #000000 50%, #000000 51%, #ffffff 52%, #ffffff 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ffffff), color-stop(49%, #ffffff), color-stop(50%, #000000), color-stop(51%, #000000), color-stop(52%, #ffffff), color-stop(100%, #ffffff));
background: -webkit-linear-gradient(#ffffff 0%, #ffffff 49%, #000000 50%, #000000 51%, #ffffff 52%, #ffffff 100%);
background: -o-linear-gradient(#ffffff 0%, #ffffff 49%, #000000 50%, #000000 51%, #ffffff 52%, #ffffff 100%);
background: linear-gradient(#ffffff 0%, #ffffff 49%, #000000 50%, #000000 51%, #ffffff 52%, #ffffff 100%);
}
Demo: http://jsfiddle.net/2m30vsgm/
Simple answer using grid:
h1 {
display: grid;
grid-template-columns: 1fr max-content 1fr;
align-items: center;
gap: 0.5rem;
}
h1:before,
h1:after {
content: '';
height: 1px;
background-color: #CBD5E1;
}
https://jsfiddle.net/6cq5whgr/
Is there a way to set the size of the image independent from the general size of the background with css?
With following code I set the size of the of the background, so the gradient and the image have the width of 30px.
background(url("../images/icons/double_arrow_37px.svg"), linear-gradient(to top bottom, rgb(171, 129, 85), rgb(148, 112, 74)));
background-size: 30px 37px;
What I need is to set the width of the image to 30px and the gradient to a width of 100% of the button.
I already know the workaround to create a extra image with the correct dimensions, but maybe there is a smarter way with css?
Full Example:
body {
background-color: #000;
}
.button-custom {
color: #fff;
font-family: $font-centennial;
background-image: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg");
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
margin-top: 70px;
padding: 15px 45px;
border-radius: 0;
border: 0;
text-transform: uppercase;
overflow: hidden;
}
.button-custom.bronze {
background-color: #ab8155;
}
.button-custom.bronze:hover {
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), -moz-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), -webkit-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), linear-gradient(to top bottom, #ab8155, #94704a);
background-position: center left;
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
color: #fff;
}
Contact
In CSS3, you can use multiple images background. linear-background is interpreted as an image not a color. Known that, you can write something like that :
body {
height: 600px; /* not relevant for your problem */
width: 600px;
}
div {
height: 500px; /* not relevant for your problem */
width: 500px; /* not relevant for your problem */
border: 3px dashed green; /* not relevant for your problem */
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -moz-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -webkit-gradient(linear, left top, left bottom, color-stop(0%, red), color-stop(100%, blue));
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -webkit-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -o-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -ms-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), linear-gradient(to bottom, red 0%, blue 100%);
background-position: 50% 50%, 50% 50%;
background-repeat: no-repeat, no-repeat;
background-size: 150px, 300px;
}
<div>Yo!</div>
I have a responsive design with 4 fluid blocks.
I want the submit button to be fixed at bottom center.
The problem is, the button is shifted to the right (but not perfectly right-aligned)
Here is my css:
#product-list{
width: 100%;
padding: 0 40px;
margin: 30px 0 0 0;
position:relative;
}
article.products{
float: left;
position:relative;
width: 24%;
margin-top: 5px;
margin-bottom: 5px;
margin-right: 0;
text-align: center;
border: 1px solid #C0C0C0;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
padding: 10px;
background: #fbfbfb;
background-image: -ms-radial-gradient(center, ellipse farthest-corner, #FFFFFF 90%, #EFEFEF 100%);
background-image: -moz-radial-gradient(center, ellipse farthest-corner, #FFFFFF 90%, #EFEFEF 100%);
background-image: -o-radial-gradient(center, ellipse farthest-corner, #FFFFFF 90%, #EFEFEF 100%);
background-image: -webkit-gradient(radial, center center, 0, center center, 506, color-stop(.90, #FFFFFF), color-stop(1, #EFEFEF));
background-image: -webkit-radial-gradient(center, ellipse farthest-corner, #FFFFFF 90%, #EFEFEF 100%);
background-image: radial-gradient(ellipse farthest-corner at center, #FFFFFF 90%, #EFEFEF 100%);
}
article.products input[type="submit"] {
position: absolute;
bottom: 5px;
left: 50%;
}
Here is the html (deleted unnecessary code; it is a dynamic loop for the boxes):
<div id="product-list">
<section class="main">
<article class="products">
<input name="Submit" type="Submit">
</article>
</section>
</div>
You have to place the input in a parent div
<div class="parent_div">
<input name="Submit" type="Submit">
</div>
And use this CSS to arrange it
.parent_div {
position: absolute;
bottom: 5px;
width: 100%;
}
.parent_div input {
margin: 0 auto;
}
So yeah here is your code:
article.products input[type="submit"] {
margin-left: 50%;
margin-right: 50%;
marging-bottom: 5px;
}
Or you could put a padding-bottom: 5px to the container class. Your choice.
I'm in trouble trying to do this :
I managed to do something like this :
display: table-cell;
vertical-align: middle;
background: rgb(245,245,245); /* Old browsers */
background: -moz-linear-gradient(top, rgba(245,245,245,1) 0%, rgba(230,230,230,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(245,245,245,1)), color-stop(100%,rgba(230,230,230,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f5f5', endColorstr='#e6e6e6',GradientType=0 ); /* IE6-9 */
for the main container of text, and :
width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 40px solid #FEEDDD;
display: inline-block;
to do the triangle. I would then place the circle with the number in absolute position inside of it.
But can't figure out how I would do for the triangle "border" to be gradient like the other div, nor giving it a white outer border...
Thanks ahead !
It's definitely possible.
I created not so long ago a back button with a gradient arrow. See this fiddle
So just change the orientation, the colors and resize it to what you want but you've got the idea here I guess.
HTML:
<button>Rejoignez le groupe</button>
CSS:
button {
position: relative;
display: inline-block;
border: 1px solid #555555;
margin: 0;
font-size: 12px;
color: inherit;
cursor: pointer;
height: 30px;
padding: 0 10px;
margin-right: 10px;
font-weight: bold;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #eeeeee), color-stop(100%, #888888));
background: -webkit-linear-gradient(top, #eeeeee, #888888);
background: -moz-linear-gradient(top, #eeeeee, #888888);
background: -o-linear-gradient(top, #eeeeee, #888888);
background: linear-gradient(top, #eeeeee, #888888);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-ms-border-radius: 4px;
-o-border-radius: 4px;
border-radius: 4px;
text-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
-webkit-box-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
-moz-box-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
box-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
}
button:after {
clip: rect(14px, 14px, 28px, 1px);
-webkit-transform: skewX(-35deg);
-moz-transform: skewX(-35deg);
-ms-transform: skewX(-35deg);
-o-transform: skewX(-35deg);
transform: skewX(-35deg);
content: "";
top: 0;
position: absolute;
height: 100%;
width: 8%;
right: -10px;
border-right: inherit;
background: inherit;
-webkit-box-shadow: inherit;
-moz-box-shadow: inherit;
box-shadow: inherit;
}
button:before{
clip: rect(1px, 14px, 14px, 1px);
background: red;
-webkit-transform: skewX(35deg);
-moz-transform: skewX(35deg);
-ms-transform: skewX(35deg);
-o-transform: skewX(35deg);
transform: skewX(35deg);
content: "";
top: 0;
position: absolute;
height: 100%;
width: 8%;
right: -10px;
border-right: inherit;
background: inherit;
-webkit-box-shadow: inherit;
-moz-box-shadow: inherit;
box-shadow: inherit;
}
Tell me if it's too confusing and need some guidance to change orientation, size and colors.
while you probably can manage to do something like that and still maintain a decent fall-backs across the ranges of browsers with successful results... i expect your going to pull out a good chunk of your hair while trying. my suggestion would be to get a few background images made up in Photoshop and break those items up into three different elements
an element for the transparent white circle that can contain the
step #
an element with class for the completed steps to apply the orange gradient background
another element with separate class for the gray gradient
doing things this way you can keep all of your elements "square" without having to worry about support for triangular or circle elements. and just overlay your text in the appropriate places...
i know this might not be exactly what your asking for the css3 way to accomplish everything, but i believe doing things this way allows you to keep it simple & lean