Cascading of CSS Rules

As I previously mentioned in one of my other posts, for educational purposes, you may comingle and use inline styling, with internal styling and external styling. However, in private industry and as a best practice measure you should only use external styling. With that said, if you do use all three stylings, you should understand how conflicts between rules are resolved. In other words, if there are two or more rules that apply to the same element or tag, it is important to understand which will apply or take precedence. Before you can determine that, you must know some basic CSS rules.

Last Rule

The last rule states that if two selectors are identical, the latter of the two will take precedence. In the example listed below, the background color for the paragraph element will be red because the last rule is the one that applies.

P{
    background-color: blue;
}

P {
    background-color: red
}

Rule of Specificity

If there is a conflict between two rules where two selectors are selecting the same element or tag, the selector with the more specific selector will have precedence over the other. In the example below, the universal selector is selecting everything and styling it with a red background, however the paragraph selector is also selecting paragraphs and styling it wit a blue background. Is the paragraph element going to have a red background or a blue background? The answer is blue. Why blue? Because the “P” selector is more specific of a selector than the universal selector. Actually, the universal selector is not specific at all. It pics all the elements on a page.

* { 
    background-color: red;
}

P {
    background-color: blue;
}
---html----
<p id="test">Testing</p>

CSS Keywords

In order to override any predetermined rules in CSS, you could use the keyword !important after any property value to indicate that a rule that otherwise would not be as important is now more important because it has the keyword !important after the declaration. keep in mind that the !important keyword must be used for each declaration that you want to declare as more important.

Using the example below, normally the rule of specificity would state that the paragraphs would be blue because the selector is more specific. However, by adding the !important keyword, we are breaking the rule of specificity for that declaration.

* { 
    background-color: red !important;
}

P {
    background-color: blue;
}
---html----
<p id="test">Testing</p>

CSS Rule Sets (valid syntax) & Selectors

What is a CSS Rule

A CSS Rule is a rule which states how an element or tag will look or should look. Using a valid syntax the rule can be applied to a single element or tag or many elements or tags.

CSS Selectors are case sensitive, so they must match element names and attribute values exactly.

CSS Rules Break Down

//Selector
P {
     color: blue;      //Declaration 1
     font-size: 14px;  //Declaration 2
}
Note - The declaration block is defined by the "{}".  Declarations are always placed inside the curly braces and you can place as many declarations as you would like inside of the curly braces.

Selector - selects the element or tag that the CSS rule will style.
Declaration  - defines the style to be applied (the look).
Declaration syntax - declarations are always defined by a declaration block  :  declaration value ;

The colon is the separator between the property or declaration name and the value.
The semicolon defines the end of the declaration. 

Different Types of Selectors

Selector TypeDescriptionExample
Universal SelectorApplies to all elements in the document* {} targets all elements on the page
Type SelectorMatches Elements Namesh1, h2, h3 {} Targets the elements <h1>, <h2><h3> at the same time.
Class SelectorMatches an element whose class attribute value is the same one after the period..test{} Targets any element whos class value = target.
ol.test{} Targets only order lists whose class value is test.
ID SelectorMatches an element whos id attribute value matches the one after the pound or hash symbol#complete {} Matches any element or tag with an id that has a value of complete or id=”complete”
Child SelectorMatches any element who has a direct child of anotherP > a {} Matches any anchor tag that is a direct child of a paragraph.
Descendant SelectorMatches an element or tag that is a descendent of another specified element.P a {} Targets any anchor tag that sits inside of a paragraph element no matter how deep into the paragraph.
Adjacent Sibling SelectorMatches an element that is the next sibling of anotherh4 + p {} Matches any paragraph directly after the h4 but not other paragraphs
General Sibling SelectorMatches a element that is a sibling of another but doesn’t have to directly afterh4 ~p {} Matches any paragraphs that are siblings of an h4.
Selector Types Explained

HTML & CSS Best Practice, Reusability, and Accessibility

The information below is here for those students who might need some additional documentation on this topic.

  • Reusing code helps to minimize syntax errors.
  • Webpages that include style sheets should be tested on multiple browsers (all website development should be tested on all browsers prior to going live).
  • When designing a webpage, multiple fonts should be used just in case some device is unable to display the font.
  • Well known fonts tend to be the most readable fonts on a web page.
  • Fonts that are declared with ems are always resizable (ems is a relative unit of measurement).
  • Not all browsers uniformly support all CSS declarations.
  • The webkit prefix on a CSS declaration indicates something specific to Safari and Chrome.
  • What is a CSS framework?
  • Names of CSS Frameworks (Bootstrap, Skeleton, Bulma…).
  • What is the purpose of the area element? Click here
  • What is the purpose of the map element? Click here.
  • Accessibility using tabindex=1

Java Classes & Objects

What is a class?

A class is a template that you build. From it, you will stamp out objects based on that class. In other words, think of a class as a blueprint for an object.

What is an object?

An object is something that you get from a class, sounds redundant doesn’t it? No, seriously. Think of an object like this. In your cell phone, you will have contacts. Each contact will have a name, email, phone number, address as an example. A class will be the template you fill out and create an object with that specific information. Each contact that you create will be like creating an object from the contacts class.

What are object instance variables?

Instance variables are variables of an object (the data or fields). For example, if you had a contact (from your phone remember?) object, it would be things like name, address, phone, and email. When you create a contact object from the class object, each object will have those fields. However, those fields will be different for each object based on your contact. Those fields are considered instance variables.

An object created from a class showing its instance variables.

What is a dot operator (.)?

The dot operator allows you to access the instance variables of an object as well as the methods. Using our “contact” example, we can get access directly to the instance variables by using the “.” dot operator like so.

//Make a new object from the Contact class.
Contact c = new Contact();

//Access the instance variables from the Contact object.
c.name     = "Ricardo Rodriguez";
c.email    = "rick@rickrodriguezjr.com";
c.address  = "5012 sw 23st";
c.number    = "5849898";

What are object methods?

Methods are an objects ability to do things. When you create a class, you will need that class to have a way to manipulate the data for the objects the class will create. Using our contact object as an example, our contact class will create a contact object. The contact object will have instance variables such as address, name email, and number. However, how do we collect that data or validate that data, or access that data if we don’t have direct access to the instance variables? We do it via object methods. Those methods are the ones that operate or interact with the instance variables.

It is common in Java that methods read or write data to instance variables without having access to the actual instance variables themselves (encapsulation, later I will explain).

//Create a new object
Contact c = new Contact();

//Create the variables to pass into the methods.
String name = "Ricardo Rodriguez";
String email = "rickrod99@gmail.com";
String address = "5012 sw 23 st";
String number = "5849898";


//Access the methods of the object

//Gets the name value
c.getName();
//Sets the name value
c.setName(String n);
//Gets the address value
c.getAddress();
//Sets the address value.
c.setAddress(String a);
//Gets the email address
c.getEmail();
//Sets the email value
c.setEmail(String e);
//Gets the number value
c.getNumber();
//Sets the number value
c.setNumber(String n);

Different Types Of CSS Stylings

Analyze and Implement Stylings

Inline Styling

Inline styling is a CSS styling type that is defined with the style attribute.   Each value is separated from the next by a semicolon.  
This type of styling is considered inline because it is always placed inside the opening tag of an element.  
It is also considered element level styling.
Has the highest precedence of any styling type.
<p style="font-weight: bold; color:red;">Some Content</p>

Internal Styling

Internal styling - is styling that is considered to be page level styling.
It is always defined by using the <style></style> element in the head of the document.
All CSS rules should be placed between those two tags.
It has the second highest precedence only overriding external styling.
Example
<!doctype html>
<html>
       <head>
              <style>
                     //Internal styling
                     P { color:blue; }
              </style>
       </head>
       <body>
       </body>
</html> 

External Styling

External styling - it is considered site level styling.  This styling is the separation of HTML and CSS.  External styling is best practice when using CSS.  
It is always defined by using the <link> tag to point to an external file of some kind.  The "rel" attribute defines the relationship between the HTML file and the external file.  Additionally, the "href" attribute points to the location of the external file.  In this case, the link tag will be placed in the head of the document.  
Example
<!doctype html>
<html>
       <head>
              <link rel="stylesheet" href="style.css">
       </head>
       <body>
       </body>
</html> 

CSS Precedence

The term precedence is defined as being more important than someone or something else.
In HTML & CSS, stylings do have precedence over one another.
Below is a list of order of precedence:

           1. Inline Styling - has the most precedence and it will overwrite any conflict with any other style always.
           2. Internal styling - has the second most precedence and can overwrite external styling but not inline styling.
           3. External styling - has no precedence and cannot overwrite any other styling type.

As mentioned earlier, external styling is best practice when styling a website.  In private industry, you should always use external styling, and should never comingle two or three of the different styles.   However, for the purpose of a industry certification exam, you can use one or all three styling types at once.

Resolving CSS Conflicts with Precedence

The code below is a basic example of a conflict between inline styling and internal styling.  Notice how the paragraph element has inline styling trying to set the font size of that paragraph to 10 pixels in size.  However, the internal styling is also trying to set the paragraphs to a font size of 14 pixels.  Will the paragraph element make the font size 10 pixels or 14 pixels?  

The paragraph element will make the font size 10 pixels because inline styling overrides internal styling due to its precedence.  

HTML & CSS Well-formed Markup Pages

HTML FUNDAMENTALS

Construct well-formed page markup

Doctype -tag This tag provides information to the browser on what kind of document to expect.
This tag is always the first tag in any HTML document.
(DOCTYPE is not case sensitive and can be written in multiple ways)
<!DOCTYPE html>
HTML element or tag - is the root of the HTML page and is considered a container for all other HTML content in an HTML page.  In other words, HTML holds all other tags and elements on a page.
<html>
</html>
Head element or tags - This is a container for metadata (Metadata - information about information). 
It is always located just above the body element.
You can find such other elements in the head such as title, and link tags.
<head>

</head>
Body - This element or tags define the body of an HTML page.
All HTML elements and tags will have to be defined inside the body's opening and closing tag.
Every HTML page should have the same basic structure and should include the following elements or tags.
Example:
<!doctype html>
<html lang="english">
       <head>
       </head>

       <body>
       </body>
</html>

HTML & CSS Metadata Elements

HTML Fundamentals

Constructing Markup That Uses Metadata Elements

Script Tag - Used to define where Javascript should be placed
Can be used to point to external files where Javascript may be placed using the src attribute.
Note: Typically located in the head of document.
<script>
alert("Hello world!");
</script>
No script tag - used to display other content to users who have either disabled their Javascript or their Javascript is out of date.
Typically located in the head of the document.
<noscript>Your browser is out of date.</noscript>
Style tags - Used to define CSS for an HTML page.
Typically used when creating Internal CSS.
This tag must be placed in the head of the document.
<style>
P { background-color: blue; }
</style>
Link tag - this tag is used to show the relationship between one file and another.  In most cases, you can use the link tag to point to an external CSS file.  However, it can also be used to link an HTML file and a Javascript file.
This tag doesn't contain any content.  It only contains attributes.
rel attribute - defines the relationship between the current file and the external file.
href attribute - defines where the file is located.
<link rel="relationship" href="style.css">
Meta tags - tags that provide information about the webpage.
These tags are always located inside the head of the document.
These tags do not get displayed on the web page.
Metatags are only used by search engines, and developers.
<meta name="keywords" content="HTML, CSS, JavaScript">
<meta name="description" content="Mr. Rodriguez Blog">
<meta name="author" content="Ricardo Rodriguez">
<meta http-equiv="refresh" content="30">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Creating & Installing SSL Certificate on Apache

Purchase a Certificate

If you are interested in securing your site, and you are the administrator for the site, follow these steps.  These steps are for creating and installing an SSL certificate on a Apache server.  However, on other web servers it will be similar but I recommend looking for other documentation.

One can purchase an SSL certificate from any SSL provider.  I purchased a certificate from a site called Cheap SSL Certificates.  Yes, they were the cheapest.  You can visit them by going to Cheap SSL Certificates.  Each certificate is $6.98 per year or you can pay for three years and it works out roughly to about $4.00 a year.

HINT: Cheap SSL Certificates also provide chat support for a total of $5.00.  Very reasonable and they did provide great support if you are not sure how to configure the certificates.
  1. Create an account with your SSL provider (
    Cheapsslsecurity.com  purchase a certificate
    cheapsslsecurity.com

     

    cheapsslsecurity.com).  

PRODUCTS

Look at their products, and you should see a list of the various certificates available.  I purchased a regular domain certificate for one subdomain.  This will only work for one subdomain.  You will need to purchase more certificates if you have multiple subdomains.  SSL CertificatesAnother option is to purchase a wild card certificate.

PURCHASE

Once purchased, you will have to generate your CSR certificate.  CSR stands for Certificate Signing Request, which is a certificate that you will generate from your server.  You can also be able to use the web based CSR generation tool.  This tool will ask you details about the administrator to the site.  

GENERATE CSR

Generate the certificate through the sellers CSR web based generation tool.

Web Based CSR Generator
Generate CSR

A copy of the CSR Request should be placed in a file called subdomain.domain.com.csr, and download the private key, which should go in a file called subdomain.domain.com.key.   

Alternatively, you can use the Openssl command generated by the CSR generation tool use on your command line on your server:

openssl req -new -newkey rsa:2048 -sha256 -nodes -out sub.domain.com.csr -keyout sub.domain.com.key -subj "/C=US/ST=Florida/L=Plantation/OU=Ricks Blog/CN=sub.domain.com"

This will reflect your domain settings. Running this command will generate two files, your CSR and your Key.You will not have to create your certificate from the seller.  Enter your content or CSR value into the sellers interface to generate the certificate.  

VALIDATE CERTIFICATE

You will need to validate the certificate, one way to do it is by creating a TXT record through your DNS host.  I use Godaddy, so you can manage your DNS and create a TXT file with the hash code provided by your SSL seller.  It might take up to an hour to update the DNS.  Once this is done you will be able to validate that you are the owner of the domain.

DNS TXT File for
DNS TXT file for validation

 

SSL Seller Zip Content
Certificate File Download and Needed Files.

Once it has been validated, you can download your certificate.  You will get multiple files in a zip file.  The content will look like this: 

Copy the contents from the www_domain_com file into your csr file.

Place a copy of the My_CA_Bundle file in your directory where your certificates will be.

For Permissions and ownerships of the files, please see the section at the bottom.

PERMISSIONS

You should change the ownership of these files to whatever user runs your webserver.  In my case its apache.  For example, you can change the file permissions with 
chown apache:apache file

Also, your file permissions should be 600 for both.
chmod 600 filename

CONFIGUERING APACHE

Whether you use your virtualhost file or your httpd.conf file to configure your apache webserver is up to you and how you have configured your server. Here are the basics.

#SSL STUFF...
      SSLEngine on
      SSLCertificateFile /etc/apache2/crts/mysite.crt
      SSLCertificateKeyFile /etc/apache2/crts/mysite.key
      SSLCertificateChainFile /etc/apache2/crts/DigiCertCA.crt
  • SSLCertificateFile – point to the location of your crt file.
  • SSLCertificateKeyFile – will point to your key file.
  • SSLCertificateChainFile should point to the file you received from the download from your SSL seller.

If you need further information on how to configure your Apache web server, you the following link. https://www.digicert.com/kb/csr-ssl-installation/apache-openssl.htm

Java Primitive Data Type Values

Data types for java
Data Types in Java

Primitive Values

What are primitive values? They are considered the most basic data types in Java.

Java Data Types

  • Here is the list of primitive values:
    • byte – a number between -128 to 128
    • short – 16 bit with a range of -32768 to 32768
    • integer – 32 bit whole number. Range -2147483648 to 2147483647
    • long – 64 bit number with a range of
      -9223372036854775808 to 9223372036854775807
    • double – a decimal point value with a range of 64 bit
      4.94065645841246544e-324 to 1.79769313486231570e+308
    • float – is a 32 bit value 1.40239846e-45f to 3.40282347e+38f
    • boolean – has only two possible values which are true and false.
    • char – a single 16 bit Unicode character with a minimum value of ‘\u0000’ or a maximum value of ‘\uffff’ (65,535 inclusive).d

Java programming is considered to be a statically typed language. This means that all variables must be declared according to their size before they can be used.

Think of it as if someone asked you to carry 2 ounces of water around a house and on one hand you have a cup that holds 6 ounces that is empty and another that holds 24 ounces. It would seem a waste of space and weight to carry 2 ounces of water in a 24 ounces cup when you can use a 6 ounce cup just fine to carry the 2 ounces of water. Using the 24 ounce cup of water to carry 2 ounces of water is a waste of resources. This is the same concept when declaring a variable in Java; you must be mindful of the value your container will hold. We need to make sure that the container is appropriate in size to hold the value, but at the same time the container itself is not too large where we are wasting resources.

For example: int i = 0;

By doing this, you ensure that the program stores the data needed in a appropriate container. A variables data type will determine the type of container that Java will allocate for storing your data.

Examples

Here are some examples of usage of primitive types.

boolean answer = true;

char characterV = ‘c’;

byte b = 127;

short s = 30000;

int i = 210000;

double d1 = 3.23

float f1 = 124.12f;

If you are interested in practicing some data types, click here.

If you would like to contact me, please go to http://www.rickrodriguezjr.com/contactme.html

Hashtags and why they are important to understand

Basic Understanding of Hashtags

Introduction

This article is about explaining how a hashtag helps to organize and index content for social media. I felt compelled to do this because I feel like the younger generation might understand that it is important to use hashtags, but I don’t believe they really understand why and what is happening behind the scenes. Just recently I was at a training, and most of the people were fairly young, at least younger than me, but most did not understand the significance or how a hashtag works. So if you want to know why hashtags are important to use and how they work, this is the article for you.

What is a hashtag?

The hashtag has been around before the telephone was invented. The symbol, “#” was known as a pound. For a very long time, we knew the symbol as a pound and nothing else. Today some people still know it as a pound, but most folks know it as a hashtag, especially when it is associated with social media. So, what does a hashtag do? Really, a hashtag helps to organize or group content on social media or any other site that needs some type of data organization by using a word or words together proceeded by a pound sign (hashtag).

There are many reasons why you would want to use hashtags and how you should use them on different social media sites. However, this is not the article for that. If you need more information, I recommend reading the article entitled, “How to use hashtags in social media.”

What an actual hashtag does.

The main purpose of this article is to understand what the hashtag does. As we mentioned before, a hash tag is nothing more than a keyword. How do these keywords group and organize content? In the most simple way, each time you create some content and associate a hashtag with it, the word with the hashtag (keyword) is being put in one table in a database, and the content that is being associated with it is being placed in another table. This creates between two tables in a database relationship knowns as one to many relationship. This relationship is what helps to index content. By searching for that keyword, in turn that keyword will give you the results of all the content it points to. For example, if you posted three posts to a social media site, and used the hashtag #owner, then every end user who searches for the keyword “owner”, the results will be the posts that are linked to that keyword. Hashtags are important as they help to organize and group content for simpler searching.

References used on this article

https://digitalmarketinginstitute.com/blog/how-to-use-hashtags-in-social-media#heading_38454

https://iamyogesh.medium.com/what-is-the-best-approach-to-store-hashtags-in-a-database-caa796d714d4