I am developing a website for a client based upon Google material design (i.e. heavy use of cards).
What I am wanting is to have the first card of the page be constantly peeking just above the bottom of the screen at the half way point of the floating action button like in the image below.
My problem is that this does not work well when the site is being viewed on different devices with screen resolutions. I have tried using percentage and em's to pad this card from the top but these have failed and the card changes position. My remaining option would be to use media queries but this would potentially prove to be convoluted.
The following is the CSS for the card as it currently exists:
#content-card
{
position: relative;
display: table;
background-color: white;
top: 0;
left: 0;
right: 0;
width: 100%;
overflow: hidden;
box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.3);
z-index: 2;
height: auto;
}
Any advice and insight into how I could achieve the desired effect is welcome.
Thanks :)
Basic jfiddle implementation as requested :- https://jsfiddle.net/7fudv084/1/
As you can see, the <div> sticks to the top of the screen, but it goes back to its original position when scrolling back to the top of the page. The element with position: sticky; is positioned regarding the user's scroll position.
position:absolute. You can also use position absolute as well as setting all the viewport sides (top, right, bottom, left) to 0px will make the div takes the full screen. You can also set height and width to 100% instead of setting 0 to top, right, bottom and left.
I do not have to add one for horizontal as div is a block-level element that will take the full width horizontally by default. You can also use position absolute as well as set all the viewport sides (top, right, bottom, left) to 0px will make the div take the full screen.
You can also use position absolute as well as setting all the viewport sides (top, right, bottom, left) to 0px will make the div takes the full screen..box { background: red; position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; } You can also set height and width to 100% instead of setting 0 to top, right, bottom and left.
Use vw (viewport width) instead of percentage. 1vw = 1/100th of the viewport width - regardless of device PPI, etc. So, if you want the div to remain proportionally fixed regardless of device size and scren resolution - set your horizontal axis position with VW.
Example:
.somediv{ margin-right:20vw}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With