Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Tuesday, 11 January 2011

Using JAVA To Resize Elements

I noticed a cool feature on a Google page while I was getting the custom search going. You can click on the divider between the left-hand bar and the main contents and it hides the left-hand bar. So I thought I'd try and get something similar going on my site.

I looked at the code on the Google page for a while but found it totally impenetrable. So I did a bit of searching around and decided that using some JAVA was the way to go. I found this page at w3scools.com. This is a fantastic site with clearly explained simple examples that you can run with quickly.

Rather than try and implement the ideas on my site straight away I though it best to try some sample bits of code to test the concepts needed.

The first of these is called test.htm. It's pretty simple - all it does is use 1 JAVA function to resize a box on the screen.

The second one is called test2.htm. This does quite a bit more. This has 4 JAVA functions. I have to admit I don't really understand the purpose of the getItem function but I left it in there as it's called by the second function toggleItem, which toggles the display status of box1 on and off.

There are two buttons on the screen, used to call the last two JAVA functions, which toggle the display status of box1 and re-size box2.

It didn't take to long to work it all out thanks to the helpful advice from w3scools.com. Now I need to implement the same ideas on my site.

Saturday, 8 January 2011

Stopping Spambots

All the following is the text from the webpage www.RichsWebArchive.com/aboutthissite/stoppingsmapbots/index.php and it reads as though you are viewing the actual page:

I was concerned about Spambots (evil programs which search web pages for email addresses so they can send you spam) harvesting my email address from the pages on the site.

(added 15.01.2011 - This method has been superseded by the new Pop-up Mail Form.)

I didn't want to do anything too complex just yet using forms or scripts. So the following line of code has made it's way into my site:
< a href='mailto:rich"_at_"richswebarchive"com
?subject=Site Objectives' title='replace "_at_"  
with the at sign and " with a dot.'> 
Send me a message about this page </a>
It looks more complex than it is. the mailto: address is enclosed in single quotes allowing you to pass through the double quotes inside them to the mail client. The user must then edit the email address as per the instructions in the title part of the tag - replace "_at_" with the at sign and " with a dot.

The text in the title part of the tag also shows up as a tool-tip when you hover over the link.
Hopefully anyone reading my site will be savvy enough to deal with this and the double quotes in the email address that gets passed to the mail client should be enough to fool the spambots into ignoring my address.

I fiddled with the CSS for mailto links with the following line:
a[href^="mailto"]:hover:after { 
content: " > please edit address"; }
This adds the text > please edit address after the link when the mouse rolls over the link. I also used the a[href^="mailto"]: selector to set the various colour states for the mailto tag as these are not set when you set the colours for normal links.

Once again, all the preceding text is from the webpage www.RichsWebArchive.com/aboutthissite/stoppingspambots/index.php and it reads as though you are viewing the actual page:

Site Logo

All the following is the text from the webpage www.RichsWebArchive.com/aboutthissite/logo/index.php and it reads as though you are viewing the actual page:

I wanted to set the logo for the site that comes up by the site name in browsers.

The first thing to do is create your logo. It needs to fit in a 16 x 16 pixel box, which is pretty damn small. I started by creating a 160 x 160 pixel .png file in Adobe Fireworks.

Then I found a great website that converts the .png file into the files you need, pops then in a .zip archive with instructions for how to use them. It gives you a static version and an animated one. I renamed one of these and put in the site's root directory.

Instead of putting the code line:

< link rel="shortcut icon" href="/rwaicon1.ico" > 

into every page on the site I decided to make a .inc file called sitewideheadcode.inc and I put the code in there. Then I put a php include to load sitewideheadcode.inc at the end of all the head sections in the code on each page.

So now i can easilly add code to the end of every head section on the site and my logo works. If I need to change the logo it's just one edit.

Once again, all the preceding text is from the webpage www.RichsWebArchive.com/aboutthissite/logo/index.php and it reads as though you are viewing the actual page:

Navigation Bar Links

Friday 7th January 2011


All the following is the text from the webpage www.RichsWebArchive.com/aboutthissite/navbarlinks/index.php and it reads as though you are viewing the actual page:

It occurred to me that the links in the navigation bar can and indeed should stay the same from page to page of the site. So I wanted to have 1 piece of code for the links which I could then call from any page I choose. Thus if I change a link I only need edit one file instead of many.

I wanted a method of importing html into html.

A quick Google search and a bit of reading led me to believe that using a php call include was the easiest way to go about things. It turns out that it was pretty simple too. More of an issue was being able to test pages containing php without having to upload them to a server and this is discussed in the My Sytsem page.

It was really easy to do. I copied the code for the links into a seperate file called navbarlinks.inc, which I saved in the site's root directory/folder. Only the code for the links, not their surrounding div tags. In place of the links in the main XHTML document I put the following line:

<?php include('../navbarlinks.inc'); ?>

This copies the code from navbarlinks.inc directly in it's place.

All that then remained to do was to change the extension of the index.htm file to .php. This tells servers to parse the page for php and translate it into html before they send the page to your browser. I had to upload the files to my server before I could tell if it worked.

Luckily this was one of those rare and joyous occasions where everything worked absolutely right first time. I then went on to getting the php to work locally. That took a bit more time, but it was free and pretty smooth.

Once again, all the preceding text is from the webpage www.RichsWebArchive.com/aboutthissite/navbarlinks/index.php and it reads as though you are viewing the actual page:

Site Objectives

Originally written on Friday 7th January 2011


All the following is the text from the webpage www.RichsWebArchive.com/siteobjectives/index.php and it reads as though you are viewing the actual page:

How much time is there? Eventually I need to earn some money and stop doing this. In the mean time though I hope the site will grow into several different sections coving the main technologies in use on the web.

To begin with I'm concentrating on XHTML and CSS and getting used to writing the code. Next up on this front is to write a form and have the information emailed to me. Maybe I'll try a bit of JAVA to validate the input.

Eventually I'll take a look at some server-side technologies, Perl and MySQL probably.

All the files and associated code for this site are freely available for downloading. You can do whatever you like with them. Generally I'll link a download to a particular page when I've finished it. One thing to be aware of is that these downloads are like a snapshot in time, and may not reflect the current state of the site.

I've found a friend who wants me to write a website for their business too. This is a fantastic opportunity to learn on a real job and earn some money too. I'll be documenting anything new and useful I learn along the way with that here too.

I have also made a companion blog to this website. The main articles here will be copied there but I'm also going to use it just to jot down small quick things I learn along the way.

Once again, all the preceding the text is from the webpage www.RichsWebArchive.com/siteobjectives/index.php and it reads as though you are viewing the actual page:

Scalable Page Layout with Fixed Banner and Navigation Bar

Originally written on Thursday 6th January 2011


All the following is the text from the webpage www.RichsWebArchive.com/aboutthissite/splftnb/index.php and it reads as though you are viewing the actual page:

This page was my first stab at getting XHTML and CSS to work together and it has become the basic design for this site. My goal was to have a fixed top banner and left-hand navigation sidebar with a scrolling main content area, all in a scalable page. This sounds simple but it took me about a day to learn how to get it like this.

I'm sure there are lots of other ways of achieving these goals and probably more simply than I have done it. I am a total novice after all. Hopefully though my solution is pretty straightforward and the code fairly tidy. All formatting, both content and layout, is dealt with by the CSS stylesheet.

There are two files used to produce this page: index.php - the XHTML code for this page and rwa1.css - the stylesheet for this page. The stylesheet rwa1.css must reside 1 directory/folder up from index.php if you want to mess about with them or you can edit the reference that loads the CSS file in index.php.

It maybe that you cannot directly open files with the .php extension in your browser - if this is the case then you can download an older version of the files using the .htm extension instead. All files in the older version must reside in the same directory. Please see the My Sytsem page for information about running php on your system.

I'm going to assume that since you are reading this you have at least some basic knowledge of XHTML and CSS and how they realate to eachother. Most especially you will need to understand the use of class and id element identifiers. They are really the key to how the CSS affects the XHTML. If you don't understand this then you won't get the rest of it. There is a good explanation about both at W3.org.

OK, so now down to talking about the code. The key behind this page is using the stylesheet to manage the layout and keeping the XHTML organised into distinct div tags so that the content picks up the correct formatting from the stylesheet.

I'm not going to go into minute detail about how every value and attribute is set, I'd fall asleep doing it. Hopefully I will point out the key facts and you can work out the rest by mucking about with the code yourself. Take bits out, put bits in, move them around, change values and properties and see what happens. It's always easy to use comments to block sections of code and then easy to remove them too.

The head section is quite simple. It sets the character set to utf-8, sets the page title - this shows up in your browser as a tab-lable - and calls the stylesheet rwa1.css.

The body section is where all the action is. It contains 4 distinct div tags. Each one neatly contains all the content for a specific section on the page. The names are meaningful.

The first div is of id titlebar. This places a rectangle at the top of the screen with the page title which is also a link back to the Home page. There are several formatting properties set in the stylesheet for this. These are the three relevant lines:

#titlebar {position:fixed; top:0px; left:1%; 
 margin-top:5px; background:#FF0000; 
 width:98%;}
#titlebar a {color:#FFFFFF;} 
 /* fix title bar links to solid white */
#titlebar h1 {font:30px "Helvetica Bold", 
 sans-serif; text-align:center;} 
    

Briefly, this code fixes the bar at the top of the page, i.e. it will not scroll, sets the background colour, the link colour to solid white, regardless of state, and sets the font properties.

Next up is the navigation div. This places the sidebar at the left of the screen and the links inside it. The CSS is fairly similar to that for the titlebar. The only major difference is that the display property is set to block - this makes the links come out on separate lines with less code in the XHTML.

The contents div comes next. This is the section which contains all this text. The only feature of note here is the CSS property/value pair overflow:auto which tells the browser to add the scrollbar if it's needed. I ended up adding this pair to the navigation div too.

Finally there is one further div called pagelinks. This was just a test originally to see if I could get a scalable and scrollable box on the page. The idea of putting links to various parts of this page came later.

There's one more thing I want to mention about the CSS and it's to do with the scalability or dynamic re-sizing of the page. Play with the window size of the browser window you are using to view this page and you will notice that the sections dynamically re-size themselves as you do it. This is achieved by using percentage values for many of the values in the CSS code.

Once again, all the preceding text is from the webpage www.RichsWebArchive.com/aboutthissite/splftnb/index.php and it reads as though you are viewing the actual page: