Category Archives: Stack Overflow

Answer by Nasser Torabzade for How to get my div boxes to go together

you just need to:

  1. use float:left for your sidebar and content. this makes them go to the left side of the line. you should use this when you need two (or more) elements side by side. read this for a description on how float works.

  2. move sidebar element to before content.

  3. also use display:inline-block for your sidebar and content. so they can have width and height.

  4. add an element with clear:both after them. this clears float on both sides, and allows next elements not to have float.

  5. please note that border-width is not counted as element width, and your content no longer needs a margin-right value.

=================================

<html>
<head>
<style>
    @charset "utf-8";
   /* CSS Document */

    #header {
        height: 250px;
        width: 728px;
        border: dashed #000;
        text-align:center;
        font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
        font-size:12px;
    }

    #footer {
        height: 28px;
        width: 728px;
        border: dashed #000;
        text-align:center;
        font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
        font-size:12px;
    }

    #left-nav {
        float:left;
        display:inline-block;
        height: 500px;
        width: 150px;
        border: dashed #000;
        text-align: center;
        font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
        font-size: 14px;
        position: relative;
    }

    #content-box {
        float:left;
        display:inline-block;
        height: 500px;
        width: 572px;
        border: dashed #000;
        margin-right: 0px;
        margin-top: 0px;
        margin-bottom: 0px;
    }

    #clear{
        clear:both;
    }

    #container{
        display:inline-block;
    }
    body{
            text-align:center;
    }
</style>
</head>

<body>
<div id="container">
    <div id="header">
        this is the header
    </div>


    <div id="left-nav">
        <ul id="left-nav-links">
            <li> <a href="#"> Link Item #1 </a></li>
            <li> <a href="#"> Link Item #2 </a></li>
            <li> <a href="#"> Link Item #3 </a></li>
            <li> <a href="#"> Link Item #4 </a></li>
            <li> <a href="#"> Link Item #5 </a></li>
        </ul>
    </div>

    <div id="content-box">
    </div>

    <div id=clear></div>

    <div id="footer">
        this is the footer
    </div>
</div>
</body>
</html>

Answer by Nasser Torabzade for socket io mouse click event

Client side:

In client side, you should first define an event listener for every type of event you need (using jQuery). In that listener, simply emit an socket.io event containing ID of element that triggered the event, so server can broadcast that to all other clients.

Also, if an event received from server, you should simulate that on it's corresponding element via jQuery.

$(document).on('click', function(event){
    socket.emit('myClick', {id: event.target});
}

var socket = io.connect('http://localhost');

socket.on('myClick', function (data) {
    $(data.id).trigger('click');
}

Server side:

In server side, just emit whatever event that was triggered, to all other clients except sender.

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
    socket.on('myClick', function (data) {
        socket.broadcast.emit('myClick', data);
    });
});

Answer by Nasser Torabzade for socket io mouse click event

Client side:

In client side, you should first define an event listener for every type of event you need (using jQuery). In that listener, simply emit an socket.io event containing ID of element that triggered the event, so server can broadcast that to all other clients.

Also, if an event received from server, you should simulate that on it's corresponding element via jQuery.

$(document).on('click', function(event){
    socket.emit('myClick', {id: event.target});
}

var socket = io.connect('http://localhost');

socket.on('myClick', function (data) {
    $(data.id).trigger('click');
}

Server side:

In server side, just emit whatever event that was triggered, to all other clients except sender.

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
    socket.on('myClick', function (data) {
        socket.broadcast.emit('myClick', data);
    });
});

Answer by Nasser for socket io mouse click event

client side:

in client side, you should first define an event listener for every type of event you need (using jQuery). in that listener, simply emit an socket.io event containing ID of element that triggered the event. so server can broadcast that to all other clients.

also, if an event received from server, you should simulate that on it's corresponding element via jQuery.

$(document).on('click', function(event){
    socket.emit('myClick', {id: event.target});
}

var socket = io.connect('http://localhost');

socket.on('myClick', function (data) {
    $(data.id).trigger('click');
}

server side:

in server side, just emit whatever event that was triggered, to all other clients except sender.

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
    socket.on('myClick', function (data) {
        socket.broadcast.emit('myClick', data);
    });
});