Monday 25 January 2010

CSS Hacks: Removing the horizontal scroll bar



Sometimes when you've coded up your website in CSS no matter what width fixes you try you'll still see that horrible horizontal scrollbar on your website's pages. Although it is harmless and doesn't effect how your site displays (For the most part) im taking about something like this:

When scroll bars are needed they are acceptable but this tutorial will show you a easy way of removing it. Via using a small code in your stylesheets






overflow-x: hidden;

This code simply hides your horizontal scroll bar. Simply think of it like this. You have graph that has a Y axis and X axis. The Y axis is the vertical line the X axis is the horizontal line, simular to this your overflow-y: is your vertical scrollbar (Going down) and your overflow-x: is your horizontal scrollbar going across. You can also expand on this code by using such codes like:






overflow-x:auto;overflow-x: visible;

overflow-x: scroll;

This can also be applied to the overflow-y: property

To place the code properly it needs to placed within a special part of your stylesheet:






html {overflow-x: hidden;}

This is most simpliest way to place this code into your stylesheet, however it can be placed in other CSS properties such as the body tag and general divs. However if you place the code anywhere but the html { property you need to make sure you define some sort of width/height/position/float etc.






html, body {margin: 0px;

background-color:#FFFFFF;

padding: 0px;

overflow-x: hidden; }

Placing this hack in your pages (Not in a stylesheet)

This hack can also be used to stop scrollbars in other things such as text area's to do this you would simply use this code:






<textarea cols="35" rows="4" style="overflow-x: hidden;">No scroll bar!</textarea>

Using the code above your text box will look like this:



The great thing about this small code is that it hides any horizontal scrollbar in anything HTML related as well as hiding the bottom scroll bar on your browser window!

This CSS hack isn't valid in CSS 2.1 but is valid in CSS 3. Be aware of that! Consult W3.org's CSS validators for more information on different CSS levels as well as validation on CSS, and how to make sure your using valid CSS!

 

Tuesday 12 January 2010

C++ Syntax: Switch

C++ Syntax: switch
Description
The switch statement provides a convenient alternative to the if when dealing with a multi-way branch. Suppose we have some integer value called test and want to do different operations depending on whether it has the value 1, 5 or any other value, then the switch statement could be employed:-
switch ( test ) {

case 1 :
// Process for test = 1
...
break;

case 5 :
// Process for test = 5
...
break;

default :
// Process for all other cases.
...

}

It works as follows:-
The expression, just test in this case, is evaluated.
The case labels are checked in turn for the one that matches the value.
If none matches, and the optional default label exists, it is selected, otherwise control passes from the switch compound statement
If a matching label is found, execution proceeds from there. Control then passes down through all remaining labels within the switch statement. As this is normally not what is wanted, the break statement is normally added before the next case label to transfer control out of the switch statement. One useful exception occurs when you want to do the same processing for two or more values. Suppose you want values 1 and 10 to do the same thing, then:-
case 1 :
case 10:
// Process for test = 1 or 10
break;

works because the test = 1 case just "drops through" to the next section