2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								title: Lock an Element to its Parent with Absolute Positioning
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 19:34:32 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 Remember to use < a > **`Read-Search-Ask` **</ a >  if you get stuck. Try to pair program  and write your own code 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								## Lock an Element to its Parent with Absolute Positioning
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 19:34:32 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								##  Hint: 1
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Use `position: absolute;` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								>  _try to solve the problem now_
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								##  Hint: 2
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Use the `right`  and `top`  properties.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								>  _try to solve the problem now_
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## Spoiler Alert!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								**Solution ahead!**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< style > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  #searchbar  {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    position: absolute;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    top: 50px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    right: 50px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  section {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    position: relative;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< / style > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< body > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  < h1 > Welcome!< / h1 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  < section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    < form  id = "searchbar" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < label  for = "search" > Search:< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < input  type = "search"  id = "search"  name = "search" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < input  type = "submit"  name = "submit"  value = "Go!" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    < / form > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  < / section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< / body > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 19:34:32 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								### Code Explanation:
 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 19:34:32 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*   `#searchbar{}`  selects all the elements with the ID of `searchbar` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*   `position: absolute;`  positions the element with respect to its nearest ancestor having `position: relative;` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*   `top: 50px;`  and `right: 50px;`  offsets the element by `50px`  to the bottom and left respectively.