1616918747
CSS Vertical Text Typography | CSS Writing-mode & Text-orientation Property
#css #programming #web-development
1650870267
In the previous chapters you've learnt how to select individual elements on a web page. But there are many occasions where you need to access a child, parent or ancestor element. See the JavaScript DOM nodes chapter to understand the logical relationships between the nodes in a DOM tree.
DOM node provides several properties and methods that allow you to navigate or traverse through the tree structure of the DOM and make changes very easily. In the following section we will learn how to navigate up, down, and sideways in the DOM tree using JavaScript.
You can use the firstChild
and lastChild
properties of the DOM node to access the first and last direct child node of a node, respectively. If the node doesn't have any child element, it returns null
.
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
console.log(main.firstChild.nodeName); // Prints: #text
var hint = document.getElementById("hint");
console.log(hint.firstChild.nodeName); // Prints: SPAN
</script>
Note: The
nodeName
is a read-only property that returns the name of the current node as a string. For example, it returns the tag name for element node,#text
for text node,#comment
for comment node,#document
for document node, and so on.
If you notice the above example, the nodeName
of the first-child node of the main DIV element returns #text instead of H1. Because, whitespace such as spaces, tabs, newlines, etc. are valid characters and they form #text nodes and become a part of the DOM tree. Therefore, since the <div>
tag contains a newline before the <h1>
tag, so it will create a #text node.
To avoid the issue with firstChild
and lastChild
returning #text or #comment nodes, you could alternatively use the firstElementChild
and lastElementChild
properties to return only the first and last element node, respectively. But, it will not work in IE 9 and earlier.
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
alert(main.firstElementChild.nodeName); // Outputs: H1
main.firstElementChild.style.color = "red";
var hint = document.getElementById("hint");
alert(hint.firstElementChild.nodeName); // Outputs: SPAN
hint.firstElementChild.style.color = "blue";
</script>
Similarly, you can use the childNodes
property to access all child nodes of a given element, where the first child node is assigned index 0. Here's an example:
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
// First check that the element has child nodes
if(main.hasChildNodes()) {
var nodes = main.childNodes;
// Loop through node list and display node name
for(var i = 0; i < nodes.length; i++) {
alert(nodes[i].nodeName);
}
}
</script>
The childNodes
returns all child nodes, including non-element nodes like text and comment nodes. To get a collection of only elements, use children
property instead.
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
// First check that the element has child nodes
if(main.hasChildNodes()) {
var nodes = main.children;
// Loop through node list and display node name
for(var i = 0; i < nodes.length; i++) {
alert(nodes[i].nodeName);
}
}
</script>
1616918747
CSS Vertical Text Typography | CSS Writing-mode & Text-orientation Property
#css #programming #web-development
1596530868
Want to develop a website or re-design using CSS Development?
We build a website and we implemented CSS successfully if you are planning to Hire CSS Developer from HourlyDeveloper.io, We can fill your Page with creative colors and attractive Designs. We provide services in Web Designing, Website Redesigning and etc.
For more details…!!
Consult with our experts:- https://bit.ly/3hUdppS
#hire css developer #css development company #css development services #css development #css developer #css
1623809439
Hello, World! In this article, we will try to grasp the concepts of one of the trickiest and crucial topics in CSS.
Position layout property in CSS is solely used to place and position elements respectively in an HTML document. They assign respective positions to HTML elements so that the overall design of our page is maintained and managed well.
The widely used positions property in CSS are as follows:
1. Static position:
When an HTML element gets assigned with
static
position, the various position properties likeleft
,right
,top
andbottom
doesn’t work. Elements in an HTML document carry static position by default.
Let’s copy and paste the code below in an IDE to view what’s happening.
<!DOCTYPE html>
<html lang="en">
<head>
<style>
#Section {
height: 200vh;
width: 800px;
border: 5px solid blue;
background-color: cyan;
font-family: monospace;
font-size: 2rem;
text-align: center;
}
#Div1, #Div2, #Div3 {
border: 4px solid red;
font-size: 1.5rem;
width: 200px;
height: 100px;
text-align: center;
display: inline-block;
}
#Div2 {
position: static;
left: 20px;
top: 50px;
}
</style>
</head>
<body>
<section id="Section">
<p>This is Section</p>
<div id="Div1">
<p>This is Div 1</p>
</div>
<div id="Div2">
<p>This is Div 2</p>
</div>
<div id="Div3">
<p>This is Div 3</p>
</div>
<section>
</body>
</html>
Upon adding position property
static
to the selector idDiv2
, we saw that the position ofDiv2
box didn’t change. Hence, we can conclude that elements with positionstatic
doesn’t get affected byleft
, right
,top
orbottom
properties.
2. Relative position:
When an element gets assigned with position
relative
, the position properties likeleft
,right
,top
andbottom
affects the element’s position in the page relative to its normal position asstatic
.
Let’s copy and paste the code below to
Div2
selector to replace the previous position property.
#Div2 {
position: relative;
left: 20px;
top: 50px;
}
We can see that the
Div2
box changed its position relative to its normal orstatic
position, i.e.20px
from theleft
and50px
from thetop
. Upon applyingrelative
position property to an element, other contents in the same box won’t get affected and change positions
3. Fixed position:
This position property is used to freeze an element in a particular location of the page so that scrolling doesn’t affect the visibility or location of the element. When we apply
fixed
value to a selector, it gets removed from the flow of the HTML document, i.e. the selector element gets uprooted from its actual position, becomes relative to the entire viewport, and doesn’t get scrolled.
Let’s copy and paste the code below to know the difference.
<!DOCTYPE html>
<html lang="en">
<head>
<style>
#Section {
height: 400vh;
width: 800px;
border: 5px solid blue;
background-color: cyan;
font-family: monospace;
font-size: 2rem;
text-align: center;
}
#Div1, #Div2, #Div3 {
border: 4px solid red;
font-size: 1.5rem;
width: 200px;
height: 100px;
text-align: center;
display: inline-block;
}
#Div2 {
position: fixed;
left: 0;
top: 0;
}
</style>
</head>
<body>
<section id="Section">
<p>This is Section</p>
<div id="Div1">
<p>This is Div 1</p>
</div>
<div id="Div2">
<p>This is Div 2</p>
</div>
<div id="Div3">
<p>This is Div 3</p>
</div>
<section>
</body>
</html>
After scrolling, we can see that the id
Div2
gets fixed in the topmost corner of the document.
4. Absolute position:
Just like
fixed
position, theabsolute
position property removes selectors from the flow. As the element gets removed from its normal position, the parent element doesn’t regard it as its child anymore. The element becomes relative to the document.
#css #css3 #css-position-property #tutorials #learning-css #html-css
1624434810
Hello fellow learner! In this tutorial, we will learn how to write string text on Images in Python using the OpenCV putText() method. So let’s get started.
Table of Contents
OpenCV Python is a library of programming functions mainly aimed at real-time computer vision and image processing problems.
OpenCV contains putText()
method which is used to put text on any image. The method uses following parameters.
BGR
format, i.e., first blue color value, then green color value, and the red color value all in range 0 to 255.#python modules #opencv #opencv puttext() #writing text on images #opencv puttext() - writing text on images #puttext() - writing text