xxxxxxxxxx
The types of positioning in CSS are-
1)static: this is the default value.We cannot use top,bottom,left and right and
z-index value with static position.
2)relative: the element is positioned relative to its normal position.We can
move relative element using top,bottom,left and right.
3)absolute: the element is positioned absolutely to its first positioned parent.
We can moved element and provide z-index. For example we position parent relative
and move child using absolute property.
4)fixed: the element is positioned related to the browser window.
5)sticky: the element is positioned based on the user's scroll position.After
element goes to scroll position it act as fixed and we give it using top,left,
right,bottom.
xxxxxxxxxx
// relative: Positions the element relative to its normal positon and will leave a gap at its normal position * /
// position: relative; * /
// absolute: Positions the element relative to the positon of its first parent * /
// position: absolute; * /
// top: 34px; left: 134px; * /
// fixed: Positions the element relative to the browser window; * /
// position: fixed;
//right: 4px; bottom: 2px * /
// sticky
// position:sticky
// top:3px
xxxxxxxxxx
The element is removed from the normal document flow, and no space is created
for the element in the page layout. It is positioned relative to its closest
positioned ancestor, if any; otherwise, it is placed relative to the initial
containing block. Its final position is determined by the values of top, right,
bottom, and left.
.element {
position: absolute;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
}
xxxxxxxxxx
div.static {
position: static;
border: 3px solid #73AD21;
}
//Another example
div.relative {
position: relative;
left: 30px;
border: 3px solid #73AD21;
}
xxxxxxxxxx
#my-parent {position: absolute}
#my-parent .my-wrapper {position: relative} /* Since you've added the wrapper in HTML */
#my-parent .my-wrapper .my-child {position: absolute} /* Now you can play with it */
xxxxxxxxxx
.relative1 {
position: relative;
}
.relative2 {
position: relative;
top: 20px;
left: 20px;
background-color: white;
width: 500px;
}
xxxxxxxxxx
class Graph {
private val adjList: HashMap<Int, MutableList<Int>> = HashMap()
// Adds a vertex to the graph
fun addVertex(vertex: Int) {
if (!adjList.containsKey(vertex)) adjList[vertex] = mutableListOf()
}
// Adds an edge between two vertices
fun addEdge(v1: Int, v2: Int) {
adjList[v1]?.add(v2)
adjList[v2]?.add(v1) // Since it's an undirected graph
}
// Removes a vertex and its associated edges
fun removeVertex(vertex: Int) {
while (adjList[vertex]?.isNotEmpty() == true) {
val adjacentVertex = adjList[vertex]?.first()
removeEdge(vertex, adjacentVertex!!)
}
adjList.remove(vertex)
}
// Removes an edge between two vertices
fun removeEdge(v1: Int, v2: Int) {
adjList[v1]?.remove(v2)
adjList[v2]?.remove(v1)
}
// Displays the graph
fun display() {
for ((vertex, edges) in adjList) {
println("$vertex -> $edges")
}
}
}
// client code to test Graph Implementation in Kotlin
fun main() {
val graph = Graph()
graph.addVertex(1)
graph.addVertex(2)
graph.addVertex(3)
graph.addVertex(4)
graph.addEdge(1, 2)
graph.addEdge(1, 3)
graph.addEdge(2, 4)
graph.addEdge(3, 4)
graph.display()
graph.removeEdge(2, 4)
graph.removeVertex(3)
graph.display()
}