Tuesday, October 2, 2018

How to center div/something both in horizontally and vertically

We know that the content inside <body> and </body> tags is visible in webpages. Lets create a div inside the body tags with a class container using the lines <div class="container"> and </div>. And there we will take a line "Test Content" inside the div with h1 header tag. So the codes will look like below...


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS Tricks</title>
</head>
<body>
    <div class="container">
        <h1>Test Content</h1>
    </div>
</body>
</html>


Now we will create a stylesheet in the same directory named style.css and write the following codes below in it.

.container {
    width: 960px;
    height: 700px;
    border: 1px solid #d7d7d7;
}

Then we will add the stylesheet using the line <link rel="stylesheet" href="style.css"> , this line should be before the closing </head> tag. Now we will see something like below the image when we will browse the webpage.

Now add the css margin: 0 auto; to centre the container. The webpage will look like below the image.
We know the container height is 700px , so we can vertically center the text if we want to use the css line-height: 700px; But there is a problem if there are more than one tag/content. The line height will work for both/all of them. That's why there will be a gap of the provided line height between those content.

We can simply centre the text both vertically and horizontally just using four lines of css codes. We will use display: table; for the .container class and will use display: table-cell; vertical-align: middle; and text-align: center;
So, now the complete css codes will look like below...

.container { 
 width: 960px;
 height: 700px;
 border: 1px solid #d7d7d7;
 margin: 0 auto; display: table;


h1 {
 display: table-cell;
 vertical-align: middle;
 text-align: center; 
}

Thursday, September 6, 2018

Facebook video is not playing in Firefox Browser in Ubuntu

When you are using Ubuntu distro of Linux OS and the Firefox Browser can't play videos on Facebook, then follow the steps to solve it.
Step 01: Go to Preferences>General>Digital Rights Management (DRM) Content and check the box Play DRM-controlled content

Step 02: Press ctrl+alt+t to open terminal and then use sudo apt install libavcodec-extra to install libavcodec-extra.

Step 03: After completing installation, use the command line reboot to restart your system.

Your Firefox browser will be able to run videos from Facebook after restarting your system.

Monday, August 27, 2018

Creating custom domain for localhost in Ubuntu

We browse websites using a link/url like http://localhost/examplesite while developing a website/web application in localhost. But we can set a custom domain like dev.example or example.dev to visit the website we are developing. I am covering here in this post how to set up custom domain in Ubuntu. But setting up custom domain in Windows and Mac platform are almost same.

Step 01: Open terminal by pressing the key binding below
ctrl+alt+t

Step 02: Change the directory to etc using the command line cd /etc cd /etc

Step 03: Now open the hosts file with gedit using the command line sudo gedit hosts
sudo gedit hosts

Step 04: Now add this line 127.0.0.1    dev.laraframe and save the hosts file
127.0.0.1    dev.laraframe

Step 05: Change directory to sites-enabled using this command line
cd /etc/apache2/sites-available/

Step 06: Use ls command to see the files inside sites-enabled folder, there you will see a file named 000-default.conf

Step 07: Now we will copy and rename this file as custom.conf using the command sudo cp 000-default.conf custom.conf

Step 08: We will open this custom.conf file in a text editor using the command sudo gedit custom.conf

Step 09: Then we will add these following lines below...
But you need to change some information against your localhost settings.
<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName example.com 

    ServerAlias www.example.com

    DocumentRoot /var/www/html/projectfolder
    <Directory "/var/www/html/projectfolder">
                Options +FollowSymLinks
                AllowOverride All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> 

Step 10: We have to enable the custom.conf now using the command line sudo a2ensite custom.conf


Step 11: Need to reload apache2 using the command line
systemctl reload apache2

Step 12: Restart apache2 using sudo service apache2 restart 

Step 13: Now visit the site with your custom domain using your favorite browser