Tag Archives: css

Javascript Trick: Add a class or ID to an HTML element on hover

Here is the line of code you can use to add a class or ID to an element in your webpage when a user hovers over it (for example: if you want to add a class called “active” to an li element with a class called “top-nav” in the div called “menu” when a user hovers over it):

<script>

	$('#menu li').hover (
	function(){ $('.top-nav').addClass('active')},
	function() {$('.top-nav').removeClass('active')}
	)
</script>

CSS Tricks: Removing the horizontal scrollbar from your divs

Here is the simple CSS code I use to hide horizontal scrollbars from my divs:

overflow-x: hidden;

You can, of course, also use this to hide vertical scrollbars, should you need or want to:

overflow-y: hidden;

 

CSS Tricks: Custom styling for your scrollbars

Here is the simple code I use to style scrollbars in a web page. Simply add this code to your stylesheet:

::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    border-radius: 8px;
   background:#A020F0;
}

::-webkit-scrollbar-thumb {
    border-radius: 8px;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
  background:#fff;
}

And customize it to fit the design that you want!

CSS Tricks: How to use a semi-transparent background in a div without affecting the text

Here is the simple way to add a semi-transparent background to a div without affecting the text elements inside the div.

Instead of this code:

background:#555;
opacity:1;
filter:alpha(opacity=100); /* For IE8 and earlier */

Use this:

background-color:rgba(255,0,0,0.5);

If you dont know the rbga value of the hexidecimal color you want to use, you can find it at http://www.color-hex.com/. Just type the hexidecimal value into the box at the top right corner of the page and click “Get color info.”

Take the rgb value  it provides you and put the three numbers into the paranthese in the block of code above. Then simply add the percent of opacity that you want to add to the background (i.e. 0.5 for 50%, 0.8 for 80%, etc.).

Concrete5: How to add a unique body class to individual pages

Here is the easiest way I have found to add a unique body class to individual pages in a Concrete5 site.

First, in your dashboard go to “Pages and Themes,”then “Attributes,” and add a custom attribute (text field) called bodyclass.

Next, open your theme’s header.php file and add:

class="<?php echo $c->getCollectionAttributeValue('bodyclass')?>"

to your < body > tag, so it reads like this:

<body class="<?php echo $c->getCollectionAttributeValue('bodyclass')?>">

For any page that you want to apply a custom class to, simply add the Body Class custom attribute and type whatever class name you want into the Body Class Custom Attribute text field. When you save your changes, your opening < body > tag will now look like:

<body class="red">

Add a hover effect to button links using CSS

Here is the code I use to add a hover effect to button links.

Copy and paste this code into your stylesheet:

a img {
opacity:.40;
filter:alpha(opacity=40);
filter: “alpha(opacity=40)”;
filter:alpha(opacity=40);
}

a:hover img{
opacity:1;
filter:alpha(opacity=100);
filter: “alpha(opacity=100)”;
filter:alpha(opacity=100);
}

You can see an example of this here.

That’s it!