summaryrefslogtreecommitdiff
path: root/Content
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2024-02-28 11:51:41 -0700
committerNavan Chauhan <navanchauhan@gmail.com>2024-02-28 11:51:41 -0700
commit507d51b356de707b5b8d3e1832fbf3684415f07c (patch)
treedf2483fb0329c75f9f4e2489aa0b0791d3c24555 /Content
parent2ede57d571e382f5aae167bd2a059a12fa1108ea (diff)
add example to post
Diffstat (limited to 'Content')
-rw-r--r--Content/posts/2024-02-26-control-element-under-another-element-html-css.md42
1 files changed, 42 insertions, 0 deletions
diff --git a/Content/posts/2024-02-26-control-element-under-another-element-html-css.md b/Content/posts/2024-02-26-control-element-under-another-element-html-css.md
index 1c253fe..cbdfe6a 100644
--- a/Content/posts/2024-02-26-control-element-under-another-element-html-css.md
+++ b/Content/posts/2024-02-26-control-element-under-another-element-html-css.md
@@ -33,3 +33,45 @@ In CSS, this can be done by:
}
```
+Let us try this in a simple example.
+
+## Example
+
+Here, we create a button and overlay a transparent box
+
+```html
+<div style="height: 200px; width: 300px; background-color: rgba(255, 0, 0, 0.4); z-index: 2; position: absolute;">
+A box with 200px height and 200px width
+</div>
+<button style="z-index: 1; margin-top: 20px; margin-bottom: 200px;" onclick="alert('You were able to click this button')">Try clicking me</button>
+```
+
+<hr>
+
+<div style="height: 200px; width: 300px; background-color: rgba(255, 0, 0, 0.4); z-index: 2; position: absolute;">
+A box with 200px height and 300px width
+</div>
+<button style="z-index: 1; margin-top: 20px; margin-bottom: 200px;" onclick="alert('You were able to click this button')">Try clicking me</button>
+<hr>
+
+As you can see, you cannot click the button because the red box comes in the way. We can fix this by adding `pointer-events: none` to the box.
+
+```html
+<div style="height: 200px; width: 300px; background-color: rgba(0, 255, 0, 0.4); z-index: 2; position: absolute; pointer-events: none;">
+A box with 200px height and 300px width
+</div>
+<button style="z-index: 1; margin-top: 20px; margin-bottom: 200px" onclick="alert('You were able to click this button')">Try clicking me</button>
+</div>
+```
+
+<hr>
+
+<div style="height: 200px; width: 300px; background-color: rgba(0, 255, 0, 0.4); z-index: 2; position: absolute; pointer-events: none;">
+A box with 200px height and 300px width
+</div>
+<button style="z-index: 1; margin-top: 20px; margin-bottom: 200px" onclick="alert('You were able to click this button')">Try clicking me</button>
+</div>
+
+
+
+