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

10 April, 2017

HTML and CSS in a nutshell | Learn HTML and CSS

If you are new to the programming world HTML is something you should start from. HTML is not really a programming language though but getting to know it is a must have for anyone who wishes to make web applications.



This (not so)little guide/tutorial will cover most of the HTML and CSS and a little bit of HTML5 which would be more than enough to get you started with web development.

Lets start with complete basics.

HTML stands for Hyper Text Markup Language.
HTML is not a programming language, it's a mark-up language meant for defining and formatting web pages.
HTML can be combined with many different programming languages to achieve anything, literally.

CSS stands for Cascading Style Sheet.
CSS is used for defining the style of a webpage.

Let's skip the theory and move to practical.

Overview: 

Part I: Making a Simple HTML Page.

Part II: Learning various HTML tags.

Part III: Basic CSS.

Part I: Making a simple HTML page.

<html><head></head><body>Hello World!</body></html>

Copy the code above in a text file and save the text file as helloWorld.html
Make sure you have file extensions visible from the settings. If not, go to Folder Options > Views and uncheck "Hide file extensions."

Lets break and study different parts of this HTML file.

<html> : Marks the beginning of an HTML page.

<head> : Marks the beginning of an HEAD part of the page. Think of it like an HEADER portion of your webpage. Although you can define or write anything in it but the convention is to only include the HEADER's information in this. HEADER's information could be the TITLE of the webpage, Header image, heading and or menu of the page.

<body> : Marks the beginning of the BODY section of a webpage. This is where we do everything a web page contains. Paragraphs of content, images, forms and everything else you can think of. 

Hello World! : This is the content of a web page. Anything that goes inside the BODY tag is considered the content of the page. Now this content can further be formatted according to the need with various HTML tags which will be discussed below.

</body></head></html> : Marks the ending of respective tag. 


Part II: Learning various HTML tags.

<html>
<head>
<title>Holy Shit I made a WebPage</title>
</head>
<body style="background-color:#CCC; font-family:monospace;">
<i><h1 style="text-align:center;">Remember the name.</h1></i>
<h2 style="text-align:center;">This is so boring.</h2>
<h3 style="text-align:center;">No not really.</h3>
<h4 style="text-align:center;">How and why?</h4>
<h5 style="text-align:center;">What has this world come to.</h5>
<h6 style="text-align:center;">Yea you can't even see me now.</h6>
<p style="text-align:center;"><b>Today is fourth of April,</b> <em>two thousand seventeen</em>. This is a webpage made on <mark>Thinkpad</mark> by <strike>IBM</strike> Lenovo. <u>Did you know!</u> Thinkpad are the only laptop range approved to be used in ISS the International Space Station.</p>
</p><bdo dir="rtl">This is another line to text from right to left.</bdo></p>
<blockquote>There are seven billion people living on this Earth! Can you tell me what every single life is worth?</blockquote>
<h1 style="text-align:center; font-size:500%;">H<sub>2</sub>SO<sub>4</sub></h1>
<h1 style="text-align:center; font-size:500%;">K<sub>2</sub>Cr<sub>2</sub>O<sub>7</sub></h1>
<h1 style="text-align:center; font-size:500%;">(a+b)<sup>2</sup>=a<sup>2</sup>+b<sup>2</sup>+2ab</h1>
</body>
</html>


Take the code above into another HTML file and save it as you like and remember to add .html as it's extension.

Lets break and study different parts in BODY part of this HTML file.

<body style="background-color:#CCC; font-family:monospace;"> In this body tag we have define a style component which is used for defining the CSS. In this particular case we are using In-line CSS(will be discussed later) which sets the background color to #CCC and font to monospace#CCC is the HTML color notation you can use normal color names like BLUE, RED etc. as well. monospace is the font family and you can use any compatible font instead like Arial, Impact etc.

Headings Tag: 

<i><h1 style="text-align:center;">Remember the name.</h1></i> : In this part we made use of In-line CSS again to align the text to center of the page. <h1> tag states that the text between the tag is a Heading. Like wise we have H2, H3, H4, H5 and H6 sub-headings' tag.

By using <i> tag we make the heading italic
Similarly we have <b> tag to make text bold

<p style="text-align:center;"><b>Today is fourth of April,</b> 
<em>two thousand seventeen</em>. This is a webpage made on 
<mark>Thinkpad</mark> by 
<strike>IBM</strike> Lenovo. 
<u>Did you know!</u> Thinkpad are the only laptop range approved to be used in ISS the International Space Station.</p><p>
<bdo dir="rtl">This is another line to text from right to left.</bdo></p>
<blockquote>There are seven billion people living on this Earth! Can you tell me what every single life is worth?</blockquote> : In this part we wrote a paragraph. I'm pretty sure you can point out the bold part in this. 
Then we have <em> tag which stands for emphasize which emphasizes the text in between a little. I have never used it before, and I don't think you will either.
<mark> marks the text in between. Just like we use markers on books and papers. You cannot change the yellow color or mark tag.
<strike> strikes the text. Needs no further explanation.
<u> underlines the text in between.
<blockquote> stands for quoting a block of content like a paragraph. 
<bdo dir="rtl"> stands for Bidirectional Override. It is used to set direction of text. You can replace rtl with ltr which is actually the default. 

<h1 style="text-align:center; font-size:500%;">H<sub>2</sub>SO<sub>4</sub></h1>
<h1 style="text-align:center; font-size:500%;">K<sub>2</sub>Cr<sub>2</sub>O<sub>7</sub></h1>
<h1 style="text-align:center; font-size:500%;">(a+b)<sup>2</sup>=a<sup>2</sup>+b<sup>2</sup>+2ab</h1> 
<marquee><h1>Holy Shit!</h1></marquee> : In this part we have,

<sup> tag which stands for super script makes the text in between appear as super script.

<sub> tag which stands for Sub Script which makes the text in between appear as sub script.

<marquee> runs the text in between from right to left.


That's it.
Now the CSS.

Part III: Links and Images.

<html>
<head>
<title>Mind Blown</title>
</head>
<body>
<p>Image with height and width</p>
<a href="http://shiftescape.com">Click here to open my blog.</a><br/>
<img src="http://i.imgur.com/cqMnINb.gif" alt="Mind Blown" width="640" height="320"/>
</body>
</html>

Create another web page with the code above.
<a href="url-here"> tag is used to create anchor text links.
<br/> tag is used to break the line. You can use either from <br>, </br>, <br/> they all do the same work.
<img src="image-url-here" width="640" height="320"/> tag is used for embedding an image. The alt part stands for alternate text which is still optional and appears when the desired image is unavailable. width and height are speaking for themselves.


Part IV: Dictionary and Lists.

<html>
<head></head><body>

<dl>
<dt>Random Title</dt>
<dd>A random title is something that we make up to fill the title part.</dd>
<dt>Title Again</dt>
<dd>This is the description, yep, pretty small description.</dd>
</dl>

<ol type="i">List of Female DOTA2 Characters
<li>Mercurial</li>
<li>Lina</li>
<li>Rylai</li>
<li>Lanaya</li>
</ol>

</body></html>

Dictionary and list are just another way of representing data in form of lists.
Dictionary has <dt> as data title and <dd> as data definition.
When it comes to list, we have an ordered list
<ol> which numbers the list content and unordered list <ul>.




Part V: Forms and Tables.

<html>
<head>
<title>Registration Form</title>
</head>
<body style="background-color:#CCC; font-family:monospace;">
<h1 style="text-align:center;">Register Now!</h1>
<form name="Registration Form" method="POST" action="demo_form.jsp" align="center">
<table align="center">
<tr>
<td>Select Username: </td><td><input type="text"/></td></tr>
<tr><td>Set Password: </td><td><input type="password"/></td></tr>
<tr><td>Gender: </td><td><select><option value="Male">Male</option><option value="Female">Female</option></select></td></tr>
<tr><td>Address: </td><td><textarea rows="5" cols="21"></textarea></td></tr>
<tr><td>State: </td><td><select><option value="">------------Select State------------</option>
<option value="Andaman and Nicobar Islands">Andaman and Nicobar Islands</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
</select><br/><br/></td></tr>
<tr><td>Select Qualification: </td><td><input type="checkbox" name="B.Tech" value="B.Tech">B.Tech 
<input type="checkbox" name="M.Tech" value="M.Tech">M.Tech 
<input type="checkbox" name="MBA" value="MBA">M.B.A 
<input type="checkbox" name="Phd" value="Phd">Ph.D </td></tr>
</table>
<input type="submit" value="submit"> 
<input type="reset" value="clear"><br/><br/>
</form>
</body>
</html>

Lets break and study different part of this HTML file.

The code above is an example of a Sign Up form using HTML. 
The purpose of an HTML form is usually to take user data and pass it to a file that can save it or process it accordingly. In the example above we have 

<form name="Registration Form" method="POST" action="demo_form.jsp">

This form uses POST method and sends the data it collects to demo_form.jsp

To take an input from the user we use <input type="text"/>

To create a check box <input type="checkbox" name="Some name" value="Value">Some name

Likewise we have different input types for forms which you can find through google and on w3School website.

In the example above we are using a table to format and align the content of the form. 
The table has the following structure, always

<table>
<tr><th>Column Heading 1 |</th> <th>  Column Heading 2</th></tr>
<tr><td>Row 1, Column 1 |</td> <td>Row 1, Column 2 </td></tr>
<tr><td>Row 2, Column 1 |</td> <td>Row 2, Column 2 </td></tr>
</table>

The table below is made using the exact code above

               Column Heading 1  |    Column Heading 2
                   Row 1, Column 1  |    Row 1, Column 2
                   Row 2, Column 1  |    Row 2, Column 2


Part VI: Basic CSS.

This will cover only the basic aspects of CSS. No animation, no transition. 
By saying that I wanted to aware you of the power of CSS. 
CSS is a powerful means of designing and can be used for making interactive and beautiful web pages.

There are three ways of using a CSS with HTML. All three will result in similar outcomes. Difference comes in handling and memory consumption.
  1. In-line CSS
  2. Internal CSS
  3. External CSS

1. In-line CSS
When the style for an HTML tag is defined within the tag itself, it's called in-line CSS.
Eg. <h1 style="text-align:center;">Remember the name.</h1>


2. Internal CSS
When the style for an HTML tag and the page itself is defined in the HEAD section of the page using the style tag, it's called internal CSS.
Eg.
<head>
<style type = "text/css" media ="all">
body {
background-color: #CCC;
}
h1 {
color: #EEE;
margin-left: 40px;
}
</style>
</head>

3. External CSS
When the style for an HTML page is defined using an external CSS file.
Eg. <head>
<link rel="stylesheet" type="text/css" href="styleSheet.css" media="all"/>
</head>

The code above in the HEAD section makes a link with the file stylesheet.css placed in the same folder as the HTML file.

The content of styleSheet.css could be following.

////////////////styleSheet.css//////////////////
h1{
color: red;
}
p{
color: blue;

}
////////////////end styleSheet///////////////

You can define as many HTML components in the external CSS. 
If two HTML components are to carry the same properties, you can define them as

h1, h2, h3{
color: red;
}


To collectively apply some style to a part of html file, enclose the part in a DIV tag.

<div id = "myID"> <p><h1>... </p></div>
<div class = "myClass"> <p.....</p></div>

In appearance there is no difference in id and class made using CSS.

Classes in CSS are suffixed with a dot(.) operator and IDs can be suffixed with an hash(#) which is still optional.
Eg. 
myID{
background-color: red;
}

.myClass{
background-color: blue;
}


That's it.

Go explore, experiment.

28 December, 2016

Finishing up our First Blogger theme


I used this for my sidebar.

.sidebar li {
    text-transform: uppercase;
list-style: none;
line-heigth: 1.4px;
}
.sidebar h2 {
    font-size: 14px;
    font-weight: 400;
    text-transform: uppercase;
    margin-left: 30px;
    margin-top: 30px;
}
.sidebar .widget {
    font-size: 12px;
}


Of course you are free to play around with whatever you like.

Also I have added CSS to make a read more button at the home page as follows.

.readmore a {
    padding: 8px 15px;
    text-transform: uppercase;
    background: #333;
    color: #fff;
}

.readmore a:hover {
color: #FFFFFF;
text-decoration: none;
}

Then I defined a little CSS as

.post-footer{
    padding: 18px 22px 10px 22px;
    background-color: #f5f4f4;
}
.primary h3 {
    font-size: 2em;
}

Now the post-footer part is the one where "Posted by eff on 12/12/16 ..etc" is written. This is done to distinguish it from the post content. And I just resized font in the title on home page.
With this I conclude my blank template. It will be available for free download and will be open source. You can create your own versions and let me know if you like.

I would feel proud to display them on here for downloads.

The complete blank template download is below.

27 December, 2016

Making the homepage more attractive and simple

Uptill now we have a responsive design which has little to no design CSS added to it.
This time we are going to add a little bit to the design. We are going to make post summary and post images to appear on the homepage as or like featured content.
In short we are going to make post thumbnails, and summary for our home page.
To do this I took help from this post.

To do this we use a Javascript that uses the first image in a post and creates an excerpt which then is shown.

To do this search for

<data:post.body/>

There are only 2 occurrences of this in our theme. Replace the 2nd occurrence with 

<b:if cond='data:blog.pageType != &quot;static_page&quot;'>
<b:if cond='data:blog.pageType != &quot;item&quot;'>
<div expr:id='&quot;summary&quot; + data:post.id'><data:post.body/></div>
<script type='text/javascript'>createSummaryAndThumb(&quot;summary<data:post.id/>&quot;,&quot;<data:post.url/>&quot;,&quot;<data:post.title/>&quot;);</script>
 <span class='readmore' style='float:right;'><a expr:href='data:post.url'>Read More &#187;</a></span></b:if></b:if>
<b:if cond='data:blog.pageType == &quot;item&quot;'><data:post.body/></b:if>
<b:if cond='data:blog.pageType == &quot;static_page&quot;'><data:post.body/></b:if>



For this to work, we need to define following javascript code as well.

Go to the HEAD section of the template and past following code just before </HEAD>

<script type='text/javascript'>
posts_no_thumb_sum = 490;
posts_thumb_sum = 400;
img_thumb_height = 160;
img_thumb_width = 180;
</script>
<script type='text/javascript'>
//<![CDATA[
function removeHtmlTag(strx,chop){
if(strx.indexOf("<")!=-1)
{
var s = strx.split("<");
for(var i=0;i<s.length;i++){
if(s[i].indexOf(">")!=-1){
s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length);
}
}
strx = s.join("");
}
chop = (chop < strx.length-1) ? chop : strx.length-2;
while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++;
strx = strx.substring(0,chop-1);
return strx+'...';
}
function createSummaryAndThumb(pID, pURL, pTITLE){
var div = document.getElementById(pID);
var imgtag = "";
var img = div.getElementsByTagName("img");
var summ = posts_no_thumb_sum;
if(img.length>=1) {
imgtag = '<span class="posts-thumb" style="float:left; margin-right: 10px;"><a href="'+ pURL +'" title="'+ pTITLE+'"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px" /></a></span>';
summ = posts_thumb_sum;
}

var summary = imgtag + '<div>' + removeHtmlTag(div.innerHTML,summ) + '</div>';
div.innerHTML = summary;
}
//]]>
</script>

<b:if cond='data:blog.pageType != &quot;static_page&quot;'>
<b:if cond='data:blog.pageType != &quot;item&quot;'>
<style type='text/css'>
.post-footer {display: none;}
.post {margin-bottom: 10px; border-bottom: 1px dotted #E6E6E6; padding-bottom: 20px;}
 .readmore a {text-decoration: none; }
</style>
</b:if>
</b:if>


That's all.
You can also download the theme I have made with all the changes below.


Making the theme responsive

Uptil the previous post we had completed a theme wtih a sidebar and a footer. Now if you might not have noticed that our theme's images and sidebar breaks in the smaller screens. So here we are going to make our theme responsive.

To do so we will use 

@media (min-width: 1200px)
.container {
    width: 1040px;
}





This is used for the browser to distinguish which CSS is to be used.

We will simply add 
@media (min-width: 1200px)
to our container, body, main, sidebar and if you are using my version primary and secondary tags instead of main and sidebar respectively.  

I used this

@media all and (min-width: 1020px) and (max-width: 4080px){
.container
{
width: 1020px;
margin: auto;
}
.primary{
width: 70%;
float: left;
}
.secondary{
float: left;
width:30%;
}
}/* media all and (min-width: 800px) and (max-width: 1020px) */

@media all and (min-width: 800px) and (max-width: 1020px){
.container
{
width: 800px;
margin: auto;
}
.primary{
width: 70%;
float: left;
}
.secondary{
float: left;
width:30%;
}
}/* media all and (min-width: 800px) and (max-width: 1020px) */

@media all and (min-width: 100px) and (max-width: 640px){
.container
{
width: 100%;
margin: auto;
}
.primary{
width: 100%;
float: left;
}
.secondary{
float: left;
width:100%;
}
}/* media all and (min-width: 100px) and (max-width: 640px) */


This covers 3 types of views which are ones with width 100 to 640px which will cover almost all phones and some tablets, and others are ones with 800px to 1020px wide display and 1020px and beyond for which I used 4080px.

Also I removed the padding of 20px I added to container in previous posts because it was causing problem with the page(scroll was appearing).

Download the responsive Blank template for Blogger from below.
Download link: https://drive.google.com/open?id=0B8Qb2-H0P8xIR19aVFFxYzJ6WG8

Adding a sidebar to Blogger theme

Now that we have a template that shows posts properly, we need to setup the sidebar.
Also we are making a responsive design here we will be ensuring that page doesn't breaks on different browsers and devices.

In previous versions of the Blank template you must have noticed that we added a footer and sidebar module to our theme. And you would have probably noticed that you can add the widgets to this area. Now all we have to do is to take this module and show it to the right of our theme so that it appears like a sidebar.
Now if you look back to our code, the module was

 <b:section class='sidebar' id='sidebar' showaddelement='yes'>

I removed other parts since this is our concerns with. This part has the class 'sidebar' being used. So we are going to define this sidebar in the CSS section. 
To do so add this.
#sidebar {
    float: left;
    width: 30%;

}


Now our sidebar is ready. But this doesn't really do anything and our sidebar doesn't look anything like a sidebar. This is because we have not defined any container to our theme and even if it floats left, it takes the left reference from the body section which again is still undefined. Now we will define an outer section to enclose the main and the side bar. 

#container
{
padding: 20px;
width: 1020px;
margin: auto;;

}

Padding so that the content appears fine and margin: auto to align the content in the center of the screen.
Now we need to define our main as well.
#main {
    float: left;
    width: 70%;

}

Now if you have added content to your footer, you theme would break. To fix that we need to define our footer as well.
#footer
{
width: 100%;
float: left;

}

Now this float:left is important. I might revisit this to align the footer contents to the center. But it still works for now.


Applying a font and changing font color

Previously we had made a blank blogger template which can show the images in the post properly in any device, we fixed the head section not showing the page title in the tab. Now we are going to change the font and font colors for our little theme.
For this we will add the font in body section in CSS.

Of course you can use any font as you like. Just make sure it is supported everywhere or there is no use of defining it.

Now we need to set a particular color for our links. So that it doesn't look low quality with visited and not-visited links in your blog.

For this we will add this:


again you are free to mess around with.

You can download the blank template from below.
Download link: https://drive.google.com/open?id=0B8Qb2-H0P8xIRnpmUllpRXViTFU





Blank template Update One HEAD section fixed

So this is the round up of this session for now. I will get back to this after some hours and a game or two of DOTA.

In previous to previos post the theme we made had no title defined in its head section.
Download this version for the HEAD section fix and images width defined.

Download link: https://drive.google.com/open?id=0B8Qb2-H0P8xIclhuOFZkOFhWRlE


Setting up a logo and images size

In previous post we created our demo template which had no CSS design defined. Also the images I used in the post were considerable big which I did on purpose. Now when the screen size is reduced the image size remains same. This way the image overflows the view area on device. Which is not acceptable when making responsive designs. So we are going to make the images in our blog fit the view area of visitors.
To do so we simply define the image size to be 100% by default.
That is add

.post-body img {
max-width: 100%;
max-height: auto;
display: block;
margin: auto; 
}
   


to the CSS of out theme.
This will not only apply to the images in the post. 

Featured Post

Content Writing VS Content Marketing: How are Both Different From Each Other?

Regardless of how long the businesses have been introduced to digital marketing, it is often seen that they confuse the terms of marketing. ...