I am new to Javascript & relatively new to HTML. I would like to know what language(pure html or Javascript & html) I should use & some suggestions of an algorithm in order to do the following:
Place 4 squares on a background but position them diagonally. Each square is a link you can click to go to a different page. So how would I be able to position html elements diagonally like my picture below?
http://i54.tinypic.com/2v7uw5u.png
I believe my code would look like this:
<script>
function positionIt()
{
var screenW = // javascript function to get screen width??;
var screenH = // javascript function to get screen height??;
var sq1 = document.getElementById( "square1" );
var sq2 = document.getElementById( "square2" );
var sq3 = document.getElementById( "square3" );
var sq4 = document.getElementById( "square4" );
// What javascript functions set a elements x,y positions?
// Should I use another way of positioning the square (not by absolute terms)
sq1.setXPos( screenW / 4 );
sq1.setYPos( screenH / 4 );
sq2.setXPos( screenW / 3 );
sq2.setYPos( screenH / 3 );
}
</script>
// OR if I use css
.menu { background-color: blue; }
/* Position the square in absolute terms diagonally */
#square1 { x=200; y=200; }
#square2 { x=300; y=300; }
#square3 { x=400; y=400; }
#square4 { x=500; y=500; }
<div class="menu" onload="positionIt()">
<a id="square1" href="home.html"><img src="square.jpg" /></a>
<a id="square2" href="home.html"><img src="square.jpg" /></a>
<a id="square3" href="home.html"><img src="square.jpg" /></a>
<a id="square4" href="home.html"><img src="square.jpg" /></a>
</div>
Live Demo
Live Demo (with
leftproperties order changed to match your mockup)I tried to keep to the numbers you asked for.
HTML:
CSS:
How does this work? See: http://css-tricks.com/absolute-positioning-inside-relative-positioning/