CSS - make button clickable underneath another element? - css

I have a button inside a div, the button is positioned on the left with display flex
I have another div below that that also contains a button.
I have positioned the bottom div on top of the top div by giving the bottom div a negative top margin.
The button in the bottom div is still clickable but now the button in the top div is not clickable because the bottom div is covering it.
Is it possible to have BOTH buttons clickable in this situation.
I know I can use pointer-events: none; on the top div but I want both clickable
I know I can rearrange the layout but is it it possible like this.
.wrap {
max-width: 800px;
border: 1px solid grey;
}
.top-button button {
display: flex;
margin-left: auto;
}
.bottom {
border: 1px solid red;
margin-top: -40px;
}
button {
cursor: pointer;
padding: 10px 15px;
}
<div class="wrap">
<div class="top-button">
<button class="btn">x</button>
</div>
<div class="bottom">
<button class="btn">Click</button>
</div>
</div>

The only way I know of to do this would be to manually catch the click-events on your top-button div and then somehow invoke the click handlers of underlying elements. You could use Event.preventDefault() to prevent the event from bubbling up the DOM and then use Document.elementsFromPoint() to see if you hit your button and if so, invoke its click handler.

Related

Is it possible to dynamically position a "tooltip" (div) such that it does not go outside the window using only CSS?

I have code that makes popups (I recommended to do this by an accessibility consultant) based on focus using only CSS and tag attributes. It works great until the focused element is too near the right side or bottom of the window, and then I need specific markup to flip the tooltip to the other side of (or above) the focused element.
I'd like to have generic CSS that "just works" without knowing the placement of the focused element ahead of time (this is for a responsive layout that reflows for different window sizes)
I know I can solve this with Javascript, and there is already a question talking about that (Display a div on mouse enter, cannot be seen if mouse position is in the right-most) but I'd really like to do it using only CSS.
Fiddle: https://jsfiddle.net/e6g39Lvb/
HTML:
<div id="wrapper">
<p>
<input type="text" /> Place cursor here and hit "tab" key to move focus
</p>
example link 1
<div class="rightside">
example link 2
<br />
<a class="corrected" href="#" title="this only works if I already know it's on the right edge of the screen">example link 3</a>
</div>
</div>
CSS
#wrapper{
margin: 1em;
}
.rightside{
text-align: right;
}
*:not(:hover):focus{
position:relative;
border: 1px solid red;
}
*[title]:not(:hover):focus:after { /* show tooltip on focus but user default for hover */
text-align: left;
border: 1px solid #fc0;
padding: 3px 6px;
color: black;
background: #fffea1;
content: attr(title) !important;
position: absolute;
width: auto;
min-width: 5em;
max-width: 15em;
transform: translate(0.5em,-30%);
}
.corrected[title]:not(:hover):focus:after {
transform: translate(-100%,-30%);
left: -0.5em;
}
Just to be clear: I know to achieve this with JS, I'm looking for a CSS only answer (if it's possible)

resize only visible at the bottom of the div

I'm working on a Vue app,and want to resize the elements on mouse drag.
<div class="mails">
<MailContent class="mail-list" />
<MailItems class="mail-list" />
</div>
And the CSS is the following:
.mail-list {
border-right: 1px solid lightgray;
resize: horizontal;
overflow: auto;
}
This little indicator is only visible when the page is scrolled down to the bottom. Is there any way add this function when the border is dragged?

Display all the inner blocks when using "target" in CSS

I created tabs in HTML/CSS. Those tabs are hyperlinks that target blocks ("div") on click. The content is not displayed for inner blocks (sub-blocks) not sure why.
<div id="contents">
<div id="content1">
<div>content not displayed</div>
</div>
<div id="content2"> content displayed </div>
<div id="content3"> content displayed</div>
</div>
The issue seems to come from the CSS.
You have :
#contents div {
border: 1px black dotted;
display: none;
}
#contents div:target {
display: block;
}
which hides all div inside contents and their children, and when targeted you only change the display of the div, not it's children. So the div inside content1 is never displayed.
There are many ways to fix this.
One way would be to only hide the direct children of #contents :
#contents>div {
border: 1px black dotted;
display: none;
}
Another way would be to only hide div that have an id :
#contents div[id] {
border: 1px black dotted;
display: none;
}
In Chrome right click on the element and select inspect, in the dev tools that open look for the css style that is causing your issue.

CSS: How to keep scrollable & static modal elements in sync on iOS/Safari

A site whose code I inherited brings up a modal when an element on the page is selected, and in Chrome and native Android environments, the behavior is as expected. However, in Safari/iOS the behavior needs to be fixed.
In Safari/iOS, when you drag the modal to scroll, there are a few problems:
the close button can lag, exposing some of the content below the scrollable content, esp when swiping down on the content quickly
when dragging up, the content can pull away from the close button and create a gap, only snapping back when lifting your finger (clumsily; the button will disappear momentarily as the content snaps back to its default position and then reappear)
when scrolling down (swiping up) and then quickly scrolling up (swiping down), the close button will attach itself to the content on the elastic rebound, and only then pop back into its desired "static" position
I am not attached to the elastic easing, if getting rid of it is the only way to maintain compatibility across environments.
HTML:
<html>
<head></head>
<body></body>
<div id="modal">
<div id="content">
<!-- modal heading + text -->
</div>
<div class="close-button">
Close
</div>
</div>
</html>
CSS:
#modal {
position:fixed;
overflow: auto;
padding: 0 5px 0 5px;
z-index: 9;
-webkit-overflow-scrolling: touch;
}
#content {
z-index: 9999;
}
.close-button {
padding-top: 10px;
border-top: 1px solid #999;
background-color: #fff;
clear: both;
height: 30px;
}

CSS/IE7: The Case of the Extending Background-Image

The situation:
There a collapsible advanced search box. It is made up of a search box div that contains a boxhead div and a boxbody div. Inside the boxbody div, there is a searchToggle div. When the user clicks "Show/Hide", the display style property of the searchToggle div is toggled between block and none. (The search fields are hidden and the search boxbody gets much smaller).
The 2 background-images for the body of the search box are set via the css of the searchBox div and the boxbody div. In IE7, when the searchToggle div is hidden, the background-image from the searchBox div extends on the left more than it should (see Here). It shows up correctly when the display of the searchToggle div is block (see
Here). Everything show up correctly, in both cases, in IE8 and FF.
The relevant HTML:
<div class="searchBox">
<div class="boxhead">
<h2></h2>
</div>
<div class="boxbody">
<div id="searchToggle" name="searchToggle">
</div>
</div>
</div>
The relevant CSS:
.searchBox {
margin: 0 auto;
width: 700px;
background: url(/images/myImageRight-r.gif) no-repeat bottom right;
font-size: 100%;
text-align: left;
overflow: hidden;
}
.boxbody {
margin: 0;
padding: 5px 30px 31px;
background-image: url(/images/myImageLeft.gif);
background-repeat: no-repeat;
background-position: left bottom;
}
I added an empty div in boxbody before searchToggle. It fixed the problem.

Resources