From 076c604f599c1feb2204f9049c28998c2bde825a Mon Sep 17 00:00:00 2001 From: The Coding Aviator <34807532+thecodingaviator@users.noreply.github.com> Date: Sat, 9 Mar 2019 19:34:32 +0530 Subject: [PATCH] Added solution to Lock an Element to its Parent with Absolute Positioning (#34317) * Update index.md * Update index.md --- .../index.md | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/guide/english/certifications/responsive-web-design/applied-visual-design/lock-an-element-to-its-parent-with-absolute-positioning/index.md b/guide/english/certifications/responsive-web-design/applied-visual-design/lock-an-element-to-its-parent-with-absolute-positioning/index.md index 29361f3888..f436dbeb8e 100644 --- a/guide/english/certifications/responsive-web-design/applied-visual-design/lock-an-element-to-its-parent-with-absolute-positioning/index.md +++ b/guide/english/certifications/responsive-web-design/applied-visual-design/lock-an-element-to-its-parent-with-absolute-positioning/index.md @@ -1,10 +1,54 @@ --- title: Lock an Element to its Parent with Absolute Positioning --- + +![:triangular_flag_on_post:](https://forum.freecodecamp.com/images/emoji/emoji_one/triangular_flag_on_post.png?v=3 ":triangular_flag_on_post:") Remember to use **`Read-Search-Ask`** if you get stuck. Try to pair program ![:busts_in_silhouette:](https://forum.freecodecamp.com/images/emoji/emoji_one/busts_in_silhouette.png?v=3 ":busts_in_silhouette:") and write your own code ![:pencil:](https://forum.freecodecamp.com/images/emoji/emoji_one/pencil.png?v=3 ":pencil:") + ## Lock an Element to its Parent with Absolute Positioning -This is a stub. Help our community expand it. +## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 1 -This quick style guide will help ensure your pull request gets accepted. +Use `position: absolute;`. - +> _try to solve the problem now_ + +## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 2 + +Use the `right` and `top` properties. + +> _try to solve the problem now_ + +## Spoiler Alert! + +![warning sign](//discourse-user-assets.s3.amazonaws.com/original/2X/2/2d6c412a50797771301e7ceabd554cef4edcd74d.gif) + +**Solution ahead!** + +```html + + +

Welcome!

+
+ +
+ +``` + +### Code Explanation: + +* `#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.