Saturday, December 3, 2016

Friday, February 20, 2015

Center a div relative to parent div

Hi,

In this post I will write some codes to help center a div relative to a parent div. This is unlike the my earlier post which centers the div relative to the viewport/window. Lets begin.


HTML Codes

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>How to ...</title>
  <style>
    #child {
     width:300px;
     height:300px;
     background:green;
     position:relative;
     left:50%;
     top:50%;
     margin-left:-150px;
     margin-top:-150px;
    }

    #parent {
      display: block;
      position: absolute;
      width: 400px;
      height: 400px;
      background: red;
      bottom: 0;
      left: 0;
    }
  </style>
</head>
<body>
<div id="parent">
   I am parent div.
  <div id="child">Center within the parent div.</div>
</div>
</body>
</html>

Center a div relative to viewport

Hi,

Here I will write some codes that will help center a div relative to the viewport. Let's begin with centering a div relative to viewport. The viewport is the display area for a web page on screen. Here you will find information about centering a div on the screen, i.e. center to the whole viewing window. 

DEMO

HTML Codes

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>How to ...</title>
  <style>
    #child {
     width:300px;
     height:300px;
     background:green;
     position:fixed;
     left:50%;
     top:50%;
     margin-left:-150px;
     margin-top:-150px;
    }

    #parent {
      display: block;
      position: absolute;
      width: 400px;
      height: 400px;
      background: red;
      bottom: 0;
      left: 0;
    }
   </style>
</head>
<body>
<div id="parent">
   I am parent div.
  <div id="child">Always center no matter where the Parent div is</div>
</div>
</body>
</html>

Saturday, December 8, 2012

Install SystemC 2.3.0 on Linux


1. Download SystemC source from Accellera.

2. Decompress the package using the command
tar -xvf systemc-2.3.0.tgz

3. Change to the top level directory systemc-2.3.0
$cd systemc-2.3.0

4. Make a directory  systemc-2.3.0 for installation in your /usr/local/ path.
$mkdir /usr/local/systemc-2.3.0

5. Make a directory “objdir” in the directory systemc-2.3.0
$mkdir objdir

6. Change to objdir
$cd objdir

7. now type:
export CXX=g++

8. Run configure from objdir:
../configure --prefix=/usr/local/systemc230

9. And then:
make

10. Install by typing command:
sudo make install

At this Point we are done with installation of SystemC 2.3.0. This version is packed with TLM package also. Here we can run our first Hello World! program.

Open your favourite "text editor" and enter the following program:


#include <systemc.h>

SC_MODULE (hello_world) {
  SC_CTOR (hello_world) {
  }

  void say_hello() {
    cout << "Hello World systemc-2.3.0.\n";
  }
};

int sc_main(int argc, char* argv[]) {
  hello_world hello("HELLO");
  hello.say_hello();
  return(0);
}


Save the file as hello.cpp

Use following command to export variable SYSTEMC_HOME.
export SYSTEMC_HOME=/usr/local/systemc230/

Now you can use following command to compile the program:

for 32-bit OS:
g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -Wl,-rpath=$SYSTEMC_HOME/lib-linux -o hello hello.cpp -lsystemc -lm

for 64-bit OS:
g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux64 -Wl,-rpath=$SYSTEMC_HOME/lib-linux64 -o hello hello.cpp -lsystemc -lm

Once the program has compiled type following to run your program:
./hello

and you should get output:

SystemC 2.3.0-ASI --- Dec 8 2012 20:50:24
Copyright (c) 1996-2012 by all Contributors,
ALL RIGHTS RESERVED


Hello World system 2.3.