Check out this helpful code snippet:
HTML:
<p>Your first name: <input id="name" /></p>
<p>Upper case first name: <strong>NAME</strong></p>
<p class="count-names">1</p>
CSS:
.count-names {
position: absolute;
top: 0;
right: 0;
}
The use of position: absolute
ensures the element is positioned absolutely to the document, regardless of other elements.
With top
and right
, you easily define the distance from the top and right sides of the document.
For more information, visit this MDN resource on positioning.
View an example here.
Below is the CSS from the example for styling purposes:
.count-names {
position: absolute;
top: 0;
right: 0;
background: #eee;
margin: 10px;
padding: 10px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}