Adding small arrow under current page in WordPress with CSS - html

I have a menu that has one gradient type for default state, and one for the hover/active state. The current page is just like the hover/active state, but with an arrow under it. I can't figure out the best way to get that arrow to show up. I tried a border image, but that didn't look right since the button size is different depending on the length of the menu item. Here is the current CSS I am using to create the two different styles:
.main-nav li a {
float: left;
font-size: 15px;
color: #333;
padding: 10px 15px;
text-shadow: 1px 1px #DDD;
border-right: 1px solid rgba(0, 0, 0, .3);
border-left: 1px solid rgba(255, 255, 255, .5);
background-image: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0.0, #B3D09E),
color-stop(0.75, #A0B88E)
);
background-image: -o-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: -moz-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: -webkit-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: -ms-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: linear-gradient(to bottom, #B3D09E 0%, #A0B88E 75%);
transition: all 300ms;
-moz-transition: all 300ms;
-o-transition: all 300ms;
-webkit-transition: all 300ms;
}
.main-nav .current-menu-item a, .main-nav .current-page-ancestor a, .main-nav li a:hover {
color: #FFF;
background-image: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, #043420),
color-stop(1, #075A36)
);
text-shadow: none;
background-image: -o-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: -moz-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: -webkit-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: -ms-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: linear-gradient(to bottom, #043420 0%, #075A36 100%);
}
I would like to avoid using jquery if I can. I feel like there should be some way to do this using just CSS instead of placing an image in the center of the button with jquery. Do I place an invisible div under each button with the arrow image centered and display it on the current page?
This is what I was given to follow for my menu. They didn't use quite the correct terminology. The 'Active' part of the image is the Current Page style:

You can use pseudo elements in CSS to add content, like ::after. By using the border property with different widths and colors you get a triangle shape. The only thing that can be a bit tricky is if you need the gradient to continue on to the arrow.
I put together a small demo. Hover the links in the menu to see the arrow.
DEMO
li:hover::after {
content: ' ';
position: absolute;
border: solid 10px transparent;
border-top: solid 0px transparent;
border-width: 10px;
left: 50%;
margin-left: -10px;
border-color: #222 transparent transparent transparent;
}

Related

Gradient line with dashed pattern

I need to create a dashed line with a linear gradient.
I managed to create a dashed line using <hr /> and the following styling:
line {
border: 0px;
border-bottom: 2px dashed;
}
And I also know that to achieve a gradient I need to do:
background: -webkit-gradient(linear, 0 0, 100% 0, from(white), to(black));
Based on the code in your own answer, it looks like you need a line which is a gradient in itself (from blue to green) and also have dashed pattern. This is not possible to achieve with one gradient image because spaces cannot be introduced in the middle of a gradient.
However, you can achieve the same effect without using any extra elements (real/pseudo) by using background-image stacking like in the below snippet:
.line {
margin-top: 50px;
height: 2px;
background: linear-gradient(to right, transparent 50%, #223049 50%), linear-gradient(to right, #00b9ff, #59d941);
background-size: 16px 2px, 100% 2px;
}
body{
background-color: #223049;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="line"></div>
The second gradient in the above snippet is the same as the one in your answer (except the usage of the latest standard cross-browser syntax). The first gradient is the replacement for your hr and it is nothing but a repeating gradient which is transparent for 50% of image's width and the color you need for the other 50%. The background-size of the first gradient image is set as 16px 2px where 16px is the width and 2px is the height. The width of the image determines the width of the dashes. The height (2px) determines the thickness of the line.
Thanks for help I finally got it working myself but embedding a dashed line into a div. The <hr/> has the colour of the element I want the line in, giving the effect of "hiding" part of the line. Here is the code, however if someone has a nice answer I'm curious.
.line {
height: 2px;
background: -webkit-gradient(linear, 0 0, 100% 0, from(#00b9ff), to(#59d941));
}
.dashed {
border: 0px;
border-bottom: 2px dashed;
border-color: #223049;
}
<div class="line">
<hr class="dashed"/>
</div>
jsFiddle
Using pseudo-elements you can achieve dashed-border and can customize it also, in any direction(have described for one side in my JSFiddle).
Here's my JSFiddle
HTML
<div class="dashed-border"></div>
CSS
.dashed-border {
position: relative;
border-bottom: 3px dashed #fff;
}
.dashed-border::before {
content:"";
border-top:3px dashed #FFF;
position: absolute;
top:0;
left:6px;
right:0;
width: 100%;
height: 3px;
z-index: 2;
}
.dashed-border:after {
content:"";
position: absolute;
bottom: -3px;
left: -3px;
}
.dashed-border::after {
right: -3px;
height: 3px;
background-image: -webkit-gradient(linear, left top, right top, color-stop(0%, #1e5799), color-stop(50%, #2989d8), color-stop(51%, #207cca), color-stop(100%, #7db9e8));
background-image: -webkit-linear-gradient(left, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
background-image: -moz-linear-gradient(left, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
background-image: -o-linear-gradient(left, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
background-image: -ms-linear-gradient(left, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
/* IE10+ */
background-image: linear-gradient(to right, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
/* W3C */
}
Hope it will work for you.

Transition from a gradient to a non-gradient background on hover

I am using a gradient to set the background color on one element. The thing is, I am also having an "hover" background but not using the gradient. At the minute, when I hover on an element having the class .tinted it flashes as it first display no background and then apply the rgba(0,0,0,0.65)
Is there any way that the transition could directly go from background: gradient(left, rgba(0,0,0,0.65), rgba(0,0,0,0.30)) to rgba(0,0,0,0.65) ?
.tinted {
transition: background-color 500ms linear;
background: -webkit-linear-gradient(left, rgba(0,0,0,.65), rgba(0,0,0,.30));
background: -o-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background: -moz-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background: linear-gradient(to right, rgba(0,0,0,.65), rgba(0,0,0,.30));
}
.tinted:hover {
background: rgba(0, 0, 0, 0.65);
}
You need to define the gradients with background-image and the plain color with background-color:
.tinted {
transition: background-color 500ms linear;
background-image: -webkit-linear-gradient(left, rgba(0,0,0,.65), rgba(0,0,0,.30));
background-image: -o-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background-image: -moz-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background-image: linear-gradient(to right, rgba(0,0,0,.65), rgba(0,0,0,.30));
}
.tinted:hover {
background-color: rgba(0, 0, 0, 0.65);
}
DEMO
This Is What you Can Use For This Approach:
#box{
width: 200px;
height: 300px;
background-color: orange;
background-image: -webkit-linear-gradient(top, crimson 0%, transparent 100%);
transition: all 1s ease-in-out;
}
#box:hover{
background-color: crimson;
}
<div id="box"></div>
A posibility is to set a gradient that has 2 parts, one with the color changing, and the other with a constant color.
And change the part of the gradient that you are showing with background-image.position
.test {
width: 300px;
height: 100px;
background-image: linear-gradient(to right, rgba(0,0,0,0.65) 50%, rgba(0,0,0,0.3));
background-size: 200% 100%;
background-position: 100% 0%;
transition: background-position 1s;
margin: 10px;
}
.test:hover {
background-position: 0% 0%;
}
#test2 {
background-image: linear-gradient(to right, blue 50%, red 100%);
}
<div class="test"></div>
<div class="test" id="test2"></div>

Creating button with gradients in CSS

What i am trying to achieve is simple. A client wants this button:
http://i59.tinypic.com/207b56p.png
provided in the design PSDs replicated in html. I have been playing around with different gradients and such and have only been able to achieve this:
background-image: -webkit-gradient(linear, left top, left bottom, from(#FEC1F4), to(#FF2DFF));
background-image: -webkit-linear-gradient(top, #FEC1F4, #FF2DFF);
background-image: -moz-linear-gradient(top, #FEC1F4, #FF2DFF);
background-image: -ms-linear-gradient(top, #FEC1F4, #FF2DFF);
background-image: -o-linear-gradient(top, #FEC1F4, #FF2DFF);
background-image: linear-gradient(to bottom, #FEC1F4, #FF2DFF);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#FEC1F4, endColorstr=#FF2DFF);
which is by far not even close.
Is there a way to make this button with gradients in CSS or not?
If theres not what is the proper way to use images as button backgrounds in HTML? Because not all buttons are the same size and an image background might be distorted in places. (Any best practices?)
You could do it like this:
DEMO
body {
margin: 50px;
}
div {
overflow: hidden;
position: relative;
width: 400px;
height: 50px;
background: -webkit-linear-gradient(to bottom, #FF5EFF 0%, #FF5EFF 50%, #FF2DFF 51%, #FF2DFF 100%);
background: -moz-linear-gradient(to bottom, #FF5EFF 0%, #FF5EFF 50%, #FF2DFF 51%, #FF2DFF 100%);
background: -ms-linear-gradient(to bottom, #FF5EFF 0%, #FF5EFF 50%, #FF2DFF 51%, #FF2DFF 100%);
background: -o-linear-gradient(to bottom, #FF5EFF 0%, #FF5EFF 50%, #FF2DFF 51%, #FF2DFF 100%);
background: linear-gradient(to bottom, #FF5EFF 0%, #FF5EFF 50%, #FF2DFF 51%, #FF2DFF 100%);
}
div:before, div:after {
content:'';
position: absolute;
bottom: 0;
height: 36px;
width: 36px;
margin-left: -36px;
transform-origin: 100% 100%;
transform: rotate(45deg);
background: #FEC1F4;
}
div:before {
left: 0;
}
div:after {
right: 0;
}
<div></div>
*Side note: You may need to change the colors.
Solution without using CSS 3:
Use background-image in order to recreate the 3D effect inside the button.
Use box-shadow in order to create the shadow effect around the button.
Just a quick example how your code would be:
.btn{
width:100px;
height: 50px;
background-image: url('image.png');
background-color: #cccccc;
-moz-box-shadow: 3px 3px 5px 6px #ccc;
-webkit-box-shadow: 3px 3px 5px 6px #ccc;
box-shadow: 3px 3px 5px 6px #ccc;
}
If you need to reuse your button with on different size inside your website, you can slice your PSD button in three parts (look image attached), HTML would be something like this.
<div class="btn">
<div class="left">
</div>
<div class="center">
</div>
<div class="right">
</div>
You can set the widht of .center as percentage and .left and .right with fixed sizes and background images.

Tag or attribute to disable influence on preceding element's position

I am trying to make an interesting bar I saw, Its purpose was to be a frame on the bottom of the browser with many social media links in the form of images to remind the visitor to share however this one was interesting to me because the images did not look like they could be created in the frame because from my experience image's top left has to be in the tag that created it however these were not, they produced from the frame with half the images outside (about 20px frame height and 40 image height).
First I tried by making the frame with its background gradient, limited its height put the images inside it and offsetting the images up - the bar insists on being on the top half of the images.
Next I tried making the gradient in a separate DIV inside another with contains both the images and the background, then offsetting the images down into the bar - Just pushes the bar down.
If it is possible to tell the browser to (through css properties obviously) to not consider the bar's position when coming across the images next, the images should render in the same place, then I don't see any problems offsetting them half up.
Apologies I can't share a JSFiddle as I don't know how to use images there. So heres the code I explained last.
div#shareBar div {
background: rgb(204,204,204);
background: -moz-linear-gradient(top, rgb(204,204,204) 0%, rgb(140,140,140) 16%, rgb(204,204,204) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(204,204,204)), color-stop(16%,rgb(140,140,140)), color-stop(100%,rgb(204,204,204)));
background: -webkit-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -o-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -ms-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: linear-gradient(to bottom, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cccccc', endColorstr='#cccccc',GradientType=0 );
border-top: 1px solid black;
height: 26px;
}
HTML:
<div id="shareBar" style="border: 1px solid red;">
<img src="Images/facebook.png"/>
<img src="Images/Twitter.png" />
<img src="Images/G+.png" />
<img src="Images/Letter.png" />
<div></div>
The images are 32x32 icons, so if the images where to be in the middle the padding would have to be 10px.
Here's how I would do it:
HTML
<div id="socialBar">
Facebook
Twitter
G+
Email
</div>
Note no secondary div
CSS
#socialBar {
height:48px;
padding-left:10px;
background: rgb(255, 255, 255);
/* Old browsers */
background: -moz-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, rgba(255, 255, 255, 1)), color-stop(51%, rgba(0, 0, 0, 1)), color-stop(53%, rgba(204, 204, 204, 1)), color-stop(73%, rgba(140, 140, 140, 1)), color-stop(100%, rgba(204, 204, 204, 1)));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* IE10+ */
background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#cccccc', GradientType=0);
/* IE6-9 */
}
#socialBar a
{
display:inline-block;
width:32px;
height:32px;
background-image:url(http://cdn.robcubbon.com/wp-content/uploads/2012/02/social-media-gif.gif);
/*PLease use your own image preferably one with a trasparent background*/
text-indent:-999px;
background-position: 0 -32px;
}
#socialBar a.facebook
{
background-position: -96px -32px;
}
#socialBar a.facebook:hover
{
background-position: -96px 0;
}
#socialBar a.twitter
{
background-position: -128px -32px;
}
#socialBar a.twitter:hover
{
background-position: -128px 0;
}
#socialBar a.email
{
background-position: -64px -32px;
}
#socialBar a.email:hover
{
background-position: -64px 0;
}
#socialBar a.gPlus
{
background-position: 0 -32px;
}
#socialBar a.gPlus:hover
{
background-position: 0 0;
}
Example: http://jsfiddle.net/b34Gs/
How It Works
I used http://www.colorzilla.com/gradient-editor/ to edit you gradient to stop halfway up the bounding div which is given a fixed height.
Next I've set up the a tags to be inline-blocks to be the height and width of the icons. Then the inner text is shifted out of the viewport with text-indent.
I have then used CSS Spriting to give the icons the appropriate background using only one image.
As an added bonus, I've added a simple hover effect, again ussing the sprite, by shifting the background image.
Update
So baisically there is no "bar". What there is, is a fairly complicated gradient that is white for the top 50% set as the background of a div. This gives the appearance of the link icons being partially embeded in a "bar". This can be demostrated by replacing the gradient with a solid background colour: http://jsfiddle.net/b34Gs/2/.
Plan B
In your question, you mention "disabling influence". My above solution does not do this, it provides the illusion of it by manipulating the background gradient. What you are referring to is known as removing an element from the natural flow of the document. This is commonly done in two ways: float:left|right or position:absolute;. As a matter of personal preference, if I can keep elements in their natural flow, I will.
For my following examples the HTML is the same as the above. I have also restored your original, full-height gradient to #scocialBar.
Floats
#socialBar a
{
position:relative; //New
float:left; //New
top:-16px; //New
margin-right:5px; //New
display:inline-block;
width:32px;
height:32px;
background-image:url(http://cdn.robcubbon.com/wp-content/uploads/2012/02/social-media-gif.gif);
text-indent:-999px;
background-position: 0 -32px;
}
position:relative; performs the function of indicating that offsets are relative to the elements' 'natural' position. top:-16px; is indicating that the elements' top edge is offset by 16px. margin-right:5px; gives some horizontal spacing to the <a> tags.
Example: http://jsfiddle.net/b34Gs/4/
Absolute Positioning
Add position:relative to the #scocialBar style. This performs the function of indicating that child elements are positioned relative to this element. As we are adding position:absolute to the child <a> elements we have to explicitly position them as they will default to the top, left corner of their nearest ancestor element with position:relative
#socialBar a
{
position:absolute;
top:-16px;
display:inline-block;
width:32px;
height:32px;
background-image:url(http://cdn.robcubbon.com/wp-content/uploads/2012/02/social-media-gif.gif);
text-indent:-999px;
background-position: 0 -32px;
}
#socialBar a.facebook
{
background-position: -96px -32px;
}
#socialBar a.twitter
{
left:50px;
background-position: -128px -32px;
}
#socialBar a.email
{
left: 130px;
background-position: -64px -32px;
}
#socialBar a.gPlus
{
left: 90px;
background-position: 0 -32px;
}
Example: http://jsfiddle.net/b34Gs/1/
NOTE I have borrowed the sprites from some one elses website for this example. You whould use your own and makesure that it has a transparent background so the rounded edges are handled better than what the example has.
In particular, it has several solution for positioning. my example used minus margin but also you can use position, background-image, etc.
HTML:
<div id="shareBar" style="border: 1px solid red;">
<div class="bar">
<img src="http://static.iconarchive.com/static/images/social/twitter-icon.png"/>
<img src="http://static.iconarchive.com/static/images/social/facebook-icon.png" />
</div>
</div>
CSS:
div#shareBar .bar {
margin-top: 25px;
background: rgb(204,204,204);
background: -moz-linear-gradient(top, rgb(204,204,204) 0%, rgb(140,140,140) 16%, rgb(204,204,204) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(204,204,204)), color-stop(16%,rgb(140,140,140)), color-stop(100%,rgb(204,204,204)));
background: -webkit-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -o-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -ms-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: linear-gradient(to bottom, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cccccc', endColorstr='#cccccc',GradientType=0 );
border-top: 1px solid black;
height: 26px;
}
div#shareBar .bar img {
margin-top: -25px;
}

How can I change the color of a tapered hr?

http://jsfiddle.net/ZMfBv/
hr {
border: 0;
border-color:blue;
background-color:blue;
color:blue;
height: 4px;
background:#fff;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,hsla(0,0%,0%,0)), color-stop(50%,hsla(0,0%,0%,.75)), color-stop(100%,hsla(0,0%,0%,0)));
background: -webkit-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: -moz-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: -ms-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: -o-linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
background: linear-gradient(left, hsla(0,0%,0%,.75) 10%, hsla(0,0%,0%,0) 100%);
}
I wish to change the hr's color to blue.Clearly, the color, background-color setting is not working, how can I do this?
update: Here is a black background with a white to gray gradient hr
body {background-color: black;}
hr {
height: 4px;
border: 0;
background: -webkit-linear-gradient(left, #f3ffff, #555555);
background: -moz-linear-gradient(left,#f3ffff, #555555);
background: -o-linear-gradient(left, #f3ffff, #555555);
background: linear-gradient(left, #f3ffff, #555555);
}
http://jsfiddle.net/ZMfBv/3
background: linear-gradient(to right, rgba(3,0,221,0.75) 10%, rgba(255,255,255,1) 100%);
Use blue as the color, rather than black. You can use this for creating css gradients.
I guess, you want a solid blue color, right ?
I so then here is the simplest solution.
hr {
border: 0;
border-color:red;
color:red;
height: 4px;
background: blue;
}
http://jsfiddle.net/ZMfBv/13/