Saturday, February 14, 2015

CSS Layout - Relative and Absolute Position

CSS Layout - Relative and Absolute

The position property is crucial to CSS layout. It has a couple of possible values. This article gives a simple example to help you understand the two most important values: relative and absolute.

CSS Sample

<style type="text/css">
.relative1 {
  position: relative;
  border: 1px solid red;
  color: red;
}
.relative2 {
  position: relative;
  top: -20px;
  left: 20px;
  width: 500px;
  border: 1px solid green;
  color: green;
}
.relative3 {
  position: relative;
  border: 1px solid orange;
  color: orange;
}
.absolute1 {
  position: absolute;
  top: -20px;
  left: 20px;
  width: 500px;
  border: 1px solid blue;
  color: blue;
}
.absolute2 {
  position: absolute;
  top: -20px;
  left: 20px;
  width: 500px;
  border: 1px solid black;
  color: black;
}
</style>
<div style="margin: 30px">
<div class="relative1"><p>relative1</p><p></p><p></p></div>
<div class="relative2"><p>relative2</p><p></p><p></p></div>
<div class="absolute1"><p>absolute1</p><p></p><p></p></div>
<div class="relative3"><p>relative3</p>
<div class="absolute2"><p>absolute2</p><p></p><p></p></div>
</div>
</div>


CSS Rules


There are two rules to remember:
  1. Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. In the example above, relative2 should be under relative1, however, since we set its top and left properties, it goes higher and to the left of its normal position. 
  2. A absolutely-positioned element is positioned relative to the nearest positioned ancestor (container). If an absolutely-positioned element has no positioned ancestors, it uses the document body. In the example above, absolute2 use relative3 as ancestor and adjusts accordingly. While absolute1 does not have an ancestor, so it adjusts according to the document.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

Thursday, February 12, 2015

HTML5 CSS3 Moon | HTML 5 & CSS 3 - Create a Moon

CSS 3 Moon Code

The code below creates a red moon with animation:
<style>
.moon {
 margin: 50px 0 0 0;
 width: 200px;
 height: 200px;
}
.moon_left {
 width: 100px;
 height: 100px;
 background: red;
 border-radius: 50px;
}
.moon_right {
 width: 102px;
 height: 102px;
 top: -101px;
 left: -1;
 position: relative;
 background: white;
 border-radius: 50px;
 -webkit-animation: moon_right_position_change 5s ease-in 2s infinite alternate; /* Chrome, Safari, Opera */
 animation: moon_right_position_change 5s ease-in 2s infinite alternate;
}

/* Chrome, Safari, Opera */
@-webkit-keyframes moon_right_position_change {
 25% {left: 25px;}
 50% {left: 50px;}
 100% {left: 100px;}
}

/* Standard syntax */
@keyframes moon_right_position_change {
 25% {left: 25px;}
 50% {left: 50px;}
 100% {left: 100px;}
} 

</style>
<div class="moon">
 <div class="moon_left"></div>
 <div class="moon_right"></div>
</div>


Create a Successful Online Store at Bigcommerce! Try it Free Now!

HTML5 CSS3 Star | HTML 5 & CSS 3 - Create a Pentagram

CSS3 Pentagram (Five-Pointed Star) Code
The code below creates a yellow star
<style>

/* Chrome, Safari, Opera */
@-webkit-keyframes pentagram_animation {
 0% {-webkit-transform: rotate(0deg);}
 25% {-webkit-transform: rotate(90deg);}
 50% {-webkit-transform: rotate(180deg);}
 75% {-webkit-transform: rotate(270deg);}
 100% {-webkit-transform: rotate(360deg);}
}

/* Standard syntax */
@keyframes pentagram_animation {
 0% {transform: rotate(0deg);
 -ms-transform: rotate(0deg);}
 25% {transform: rotate(90deg);
 -ms-transform: rotate(90deg);}
 50% {transform: rotate(180deg);
 -ms-transform: rotate(180deg);}
 75% {transform: rotate(270deg);
 -ms-transform: rotate(270deg);}
 100% {transform: rotate(360deg);
 -ms-transform: rotate(360deg);}
} 

.pentagram {
 margin: 120px 0 0 0;
 width: 200px;
 height: 200px;
 -ms-transform-origin: 55px 15px; /* IE 9 */
    -webkit-transform-origin: 55px 15px; /* Chrome, Safari, Opera */
    transform-origin: 55px 15px;
 -webkit-animation: pentagram_animation 5s linear 1s infinite normal; /* Chrome, Safari, Opera */
 animation: pentagram_animation 5s linear 1s infinite normal;
}
.pentagram_top {
 width: 0;
 height: 0;
 border-top: 34px solid yellow;
 border-left: 55px solid transparent;
 border-right: 55px solid transparent;
}
.pentagram_left {
 width: 0;
 top: -34px;
 position: relative;
 border-top: 34px solid yellow;
 border-left: 55px solid transparent;
 border-right: 55px solid transparent;
 transform: rotate(72deg);
 -ms-transform: rotate(72deg);
 -webkit-transform: rotate(72deg);
}
.pentagram_right {
 width: 0;
 top: -68px;
 position: relative;
 border-top: 34px solid yellow;
 border-left: 55px solid transparent;
 border-right: 55px solid transparent;
 transform: rotate(-73deg);
 -ms-transform: rotate(-73deg);
 -webkit-transform: rotate(-73deg);
}
</style>
<div class="pentagram">
 <div class="pentagram_top"></div>
 <div class="pentagram_left"></div>
 <div class="pentagram_right"></div>
</div>



Create a Successful Online Store at Bigcommerce! Try it Free Now!

Tuesday, February 10, 2015

XML - WstxParsingException: Illegal processing instruction target ("xml")

I got the following error when I was restarting JBoss AS 7.
com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.

JBoss complained it could not parse the standalone.xml.
Soon I realized that I accidentally added a empty line before the xml declaration. Something like:
[empty line]
<?xml version="1.0" encoding="utf-8"?>
[other xml content]
So please keep in mind whenever you encounter this error, do check your xml file and put the xml declaration as the first line of the file.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

Sunday, February 8, 2015

HTML5 CSS3 Triangle | HTML 5 & CSS 3 - Create a Triangle

CSS 3 Triangle Code


The code below creates a black triangle

<style>
.triangle {
 width: 0;
 height: 0;
 border-left: 50px solid transparent;
 border-right: 50px solid transparent;
 border-bottom: 100px solid black;
}
</style>
<div class="triangle"></div>


CSS3 Add Border Color

If we give the borders a color, what will happen?
<style>
.triangle2 {
 width: 0;
 height: 0;
 border-left: 50px solid red;
 border-right: 50px solid blue;
 border-bottom: 100px solid black;
}
</style>
<div class="triangle2"></div>



Create a Successful Online Store at Bigcommerce! Try it Free Now!