HTML Layout over background DIV - html

I am trying to achieve the layout in the image below. The hidden-container div is positioned at 0, 0 on the parent main-container div and shown on button click.
I have done a mock up fiddle here.. The col size is smaller so it is easier to see in the fiddle.
.content {
margin: 50px auto 0 auto;
}
#main-container {
width: 100%;
max-width: 500px;
max-height: 200px;
overflow: hidden;
margin: 50px auto 0 auto;
}
#hidden-container {
padding: 0;
max-width: 500px;
max-height: 200px;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1047;
}
#plyr-container {
padding: 0;
max-width: 300px;
max-height: 200px;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1048;
background-color: red;
}
#info-container {
max-width: 300px;
max-height: 200px;
width: 100%;
height: 100%;
z-index: 1048;
right: 0;
top: 0;
box-sizing: border-box;
-webkit-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
-moz-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
}
#plyra,
#plyrb {
padding: 0;
text-align: left;
position: absolute;
max-width: 300px;
max-height: 200px;
width: 100%;
height: 50%;
z-index: 1049;
}
#plyra {
left: 0;
top: 0;
height: 50%;
background-color: green;
}
#plyrb {
left: 0;
top: 50%;
height: 50%;
border-top: 1px solid black;
background-color: yellow;
}
<div class="content">
<div id="main-container">
<div id="hidden-container">
<div id="plyr-container">
<div id="plyra"></div>
<div id="plyrb"></div>
</div>
<div id="info-container"></div>
</div>
</div>
</div>
Any help is appreciated.

You can do this using flexbox. I did some modification with changing the # to class instead. You have some unnecessary properties, like z-index, top, left. Those properties won't work unless you have absolute or relative on the element. You don't need them to position it and in this particular case they really do nothing. Is this something you where looking for?
I strongly recommend reading this article on css-tricks.com about flexbox.
DEMO: Fiddle
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.content {
margin: 50px auto 0 auto;
}
.main-container {
width: 100%;
overflow: hidden;
margin: 50px auto 0 auto;
background-color: deepskyblue;
}
.hidden-container {
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
background-color: lightcoral;
}
.plyr-container {
flex-basis: 100%;
flex-grow: 1;
min-height: 300px;
display: flex;
flex-direction: column;
background-color: red;
}
.info-container {
flex-basis: 300px;
flex-grow: 1;
flex-shrink: 0;
-webkit-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
-moz-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
background-color: deeppink;
}
.plyra,
.plyrb {
text-align: left;
flex-basis: 50%; //use this instead of width
flex-grow: 1;
flex-shrink: 0;
}
.plyra {
background-color: green;
}
.plyrb {
border-top: 1px solid black;
background-color: yellow;
}
<div class="content">
<div class="main-container">
<div class="hidden-container">
<div class="plyr-container">
<div class="plyra">a</div>
<div class="plyrb">a</div>
</div>
<div class="info-container">d</div>
</div>
</div>
</div>

Refer this as an example you could even do that using display:inline-block, along-with css calc() function to minus the width of 300px from overall container to align two column i.e col1 and col2 as below,
#container {
width: 100%;
height: 100vh;
font-size: 0;
}
#container > .col1 {
width: calc(100% - 300px);
height: 100%;
background: #111;
display: inline-block;
}
#container > .col1 > .c1 {
width: 100%;
height: 50%;
background: pink;
display: inline-block;
}
#container > .col1 > .c2 {
width: 100%;
height: 50%;
background: lightblue;
display: inline-block;
}
#container > .col2 {
width: 300px;
height: 100%;
background: yellow;
display: inline-block;
}
<div id="container">
<div class="col1">
<div class="c1"></div>
<div class="c2"></div>
</div>
<div class="col2"></div>
</div>

Related

Prevent shadow bleeding with position absolute element?

I'm developing a dropdown and I'm having an issue because I want to have an absolutely positioned container of items to appear when you hover over it, but the issue is that the shadow from this bleeds onto the actual dropdown itself. Here's a reproduction:
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}
.dropdown {
position: relative;
width: 200px;
height: 40px;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
background-color: #efefef;
}
.items {
display: none;
position: absolute;
overflow: hidden;
overflow-y: auto;
width: 100%;
height: 100px;
top: 100%;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
background-color: #f7f7f7;
}
.dropdown:hover .items {
display: block;
}
.item {
padding: 5px 10px;
}
<div class="dropdown">
<div class="items">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
<div class="item">d</div>
</div>
</div>
<div>hello</div>
As you can see, the top portion of the shadow from the .items container is visible when you mouse over the dropdown. Here's a picture of what I'm referring to:
The obvious solution is to just make the box shadow apply to only the dropdown, but then the issue is that since the items container is position absolute, it doesn't receive the box shadow.
Is there any way around this?
You could add a :before element on the .dropdown with a smaller height than he items. Like this:
.dropdown:hover:before {
position: absolute;
content: "";
width: 100%;
height: 98px;
box-shadow: rgb(0 0 0 / 24%) 0px 6px 8px;
background: red;
bottom: -100px;
z-index: 0;
}
Also, remove the shadow from the .items element.
I think Jackson has the right idea with using a pseudo element.
Although my approach would be the following:
.dropdown:hover::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background-color: #efefef;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}
.dropdown {
position: relative;
width: 200px;
height: 40px;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
background-color: #efefef;
}
.items {
display: none;
position: absolute;
overflow: hidden;
overflow-y: auto;
width: 100%;
height: 100px;
top: 100%;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
background-color: #f7f7f7;
}
.dropdown:hover .items {
display: block;
}
.dropdown:hover::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background-color: #efefef;
}
.item {
padding: 5px 10px;
}
<div class="dropdown">
<div class="items">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
<div class="item">d</div>
</div>
</div>
<div>hello</div>
A second approach could be to grow the height of .dropdown on hover, and set the items list to a position not relative to .dropdown's height:
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}
.dropdown {
position: relative;
width: 200px;
height: 40px;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
background-color: #efefef;
}
.items {
display: none;
position: absolute;
overflow: hidden;
overflow-y: auto;
width: 100%;
height: 100px;
top: 40px;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
background-color: #f7f7f7;
}
.dropdown:hover .items {
display: block;
}
.dropdown:hover {
height: 140px;
}
.item {
padding: 5px 10px;
}
<div class="dropdown">
<div class="items">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
<div class="item">d</div>
</div>
</div>
<div>hello</div>

Why doesn't my box-shadow overlap correctly on these flex children?

So basically the design of the page should look like this:
And when I try to implement through HTML and CSS:
as you can see here the Navbar's box shadow overlaps the header.
*{
margin: 0;
}
#main-container {
display: flex;
background-color: ##f3f3f3;
width: 100%;
height: 100%;
}
.main-container-right {
width: 100%;
height: 800px;
position: relative;
}
#main-nav {
width: 100px;
height: 800px;
background-color: #f3f3f3;
position: sticky;
display: flex;
flex-direction: column;
border: 1px solid #c4c4c4;
box-shadow: 0px 4px 10px 10px rgba(0, 0, 0, 0.25);
z-index: 0;
}
#header {
display: flex;
height: 30px;
width: 100%;
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
z-index: 1;
position: sticky;
}
<div id="main-container">
<nav id="main-nav">
</nav>
<div class="main-container-right">
<header id="header">
</header>
</div>
</div>
I tried to add z-index and positioning the elements, it didn't seem to work. Is there any fix for it?
Here is the problem in a CodePen: https://codepen.io/biljx/pen/rNzwwqd
EDIT: I couldn't fix the z-index problem but managed to get shadow like the original design by using drop-shadow instead of box-shadown filter: drop-shadow(0px 30px 10px rgba(0, 0, 0, 0.25) );
#main-nav {
width: 100px;
height: 800px;
background-color: #f3f3f3;
position: sticky;
display: flex;
flex-direction: column;
border: 1px solid #c4c4c4;
/*box-shadow: 0px 4px 10px 10px rgba(0, 0, 0, 0.25);*/
filter: drop-shadow(0px 30px 10px rgba(0, 0, 0, 0.25) );
z-index: 0;
}
I can't figure out why all these manipulations with z-index? The blocks are already in the correct order. But, as long as you have a transparent #header, the shadow of #main-nav will be visible. So just add a background color for the #header:
* {
margin: 0;
}
#main-container {
display: flex;
width: 100%;
height: 100%;
background-color: #f3f3f3;
}
.main-container-right {
position: relative;
width: 100%;
height: 800px;
}
#main-nav {
position: sticky;
display: flex;
flex-direction: column;
width: 100px;
height: 800px;
border: 1px solid #c4c4c4;
background-color: #f3f3f3;
box-shadow: 0px 4px 10px 10px #0004;
}
#header {
position: sticky;
display: flex;
height: 30px;
width: 100%;
background-color: #f3f3f3;
box-shadow: 0px 4px 4px #0004;
}
<div id="main-container">
<nav id="main-nav">
</nav>
<div class="main-container-right">
<header id="header">
</header>
</div>
</div>

Inline block elements positioned with one fixed and the other relative

I am trying to get two inline-block elements to position where the left side #faqBlock remains positioned fixed and then #blueBox is positioned relative. This basic functionality is working in the snippet, but the containerRight is overtaking containerLeft.
How can I main the containers width and inline-block display while having #faqBlock being positioned fixed?
#page-wrap {
margin-top: 70px;
max-width: 100%;
}
#containerLeft,
#containerRight {
display: inline-block;
vertical-align: top;
box-sizing: border-box;
height: 200vh;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: blue;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
/*-- Container Right --*/
#containerRight {
width: 60%;
position: relative;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div>
<div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>
Elements with position fixed aren't in the regular flow, so it won't ever take up space in the way you are imagining. You can add margin-left: 40%; (equal to the width of the left container) onto the right container to make it look like it's holding space.
If this isn't what you are looking for, let me know!
#page-wrap {
margin-top: 70px;
max-width: 100%;
}
#containerLeft, #containerRight {
display: inline-block;
vertical-align: top;
box-sizing: border-box;
height: 200vh;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0,0,0,0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: blue;
box-shadow: 10px 5px 5px rgba(0,0,0,0.12);
}
/*-- Container Right --*/
#containerRight {
width: 60%;
position: relative;
margin-left: 40%;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div><div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>
All you need to assign is left:40% to your containerRight as it's already positioned relative
As your width of fixed container is 40%.
#page-wrap {
margin-top: 70px;
max-width: 100%;
border: 1px solid;
}
#containerLeft,
#containerRight {
vertical-align: top;
box-sizing: border-box;
height: 200vh;
border: 2px solid red;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
border: 2px solid orange;
background: blue;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
/*-- Container Right --*/
#containerRight {
left: 40%;
width: 60%;
position: relative;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div>
<div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>

HTML / CSS columns overlap

I made a fiddle here.
Why does dice-canvas-container use the full width of the window and not stop at the start of attack-canvas-container?
Is it because both columns are positioned absolute?
<div id="attack-container">
<div id="dice-canvas-container">
<div id="plyra-dice-canvas"></div>
<div id="plyrb-dice-canvas"></div>
</div>
<div id="attack-canvas-container">
..................
</div>
</div>
If suitable with your requirement then you can go with flex css instead of position: absolute
#attack-container {
padding: 0;
text-align: center;
/* position: absolute; */
max-width: 1728px;
max-height: 1080px;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1047;
/* float:left; */
display:flex;
}
#dice-canvas-container {
padding: 0;
text-align: center;
max-width: 1428px !important;
max-height: 1080px;
width: 100%;
height: 100%;
/* position: absolute; */
left: 0;
top: 0;
opacity: 0.8;
z-index: 1048;
/* display: block; */
/* float:left; */
background-color: red;
min-height:150px;
}
#attack-canvas-container {
#extend %background-gradient;
max-width: 300px;
max-height: 1080px;
font-size: 90%;
width: 100%;
height: 100%;
z-index: 1048;
/* position: absolute; */
right: 0;
top: 0;
box-sizing: border-box;
text-align: left;
-webkit-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
-moz-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
min-height: 150px;
}
#plyra-dice-canvas,
#plyrb-dice-canvas {
padding: 0;
text-align: left;
position: absolute;
max-width: 1428px;
max-height: 540px;
width: 100%;
height: 50%;
z-index: 1049;
}
#plyra-dice-canvas {
left: 0;
top: 0;
height: 50%;
}
#plyrb-dice-canvas {
left: 0;
top: 50%;
height: 50%;
border-top: 1px solid $brand-primary;
}
<div id="attack-container">
<div id="dice-canvas-container">
<div id="plyra-dice-canvas"></div>
<div id="plyrb-dice-canvas"></div>
</div>
<div id="attack-canvas-container">
</div>
</div>
Check the updated Fiddle.
Because you are using position: absolute (1) with width: 100% (2) for both containers in combination with z-index (3).
(1) : because of this, both container are absolutely positioned, not relatively.
(2) : since both have 100% width, they will overlap the other one.
(3) : the one with the higher z-index wins the upper hand.
You need to change the absolute positioning and give proper widths to the divs.

Is it possible to add image as box shadow with css?

Is it possible to add image as box shadow, for example to put image with dots instead of standard shadow?
https://i.stack.imgur.com/DOJGh.png
or somehow to replace shadow from picture with dots?
to get effect like this on picture down here
http://prntscr.com/fvjnht
Did you want something like this? It's not exactly box-shadow, but it imitates it.
You can set whatever image you like as a background for .image::after.
html, body {
margin: 0;
}
body {
width: 100vw;
height: 100vh;
}
.contain {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.image{
position: relative;
width: 200px;
height: 200px;
background-image: url(http://via.placeholder.com/200x200);
}
.image::after {
content: '';
background: linear-gradient(to bottom, #333, red);
position: absolute;
width: 100%;
height: 100%;
bottom: -10px;
right: -10px;
z-index: -1;
}
<div class="contain">
<div class="image"></div>
</div>
I think this is exactly what you are looking for:
body {
background: black;
}
#logo {
width: 200px;
height: 200px;
display: block;
position: relative;
}
#logo::after {
content: "";
background: url("https://rfclipart.com/image/big/3f-a9-1a/red-dotted-halftone-background-Download-Royalty-free-Vector-File-EPS-183199.jpg");
opacity: 0.4;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
border-radius: 50%;
z-index: -1;
}
img {
width: 90%;
height: 90%;
padding: 5%;
display: block;
float: left;
border-radius: 50%;
box-shadow: 0px 0px 40px #ccc;
-moz-box-shadow: 0px 0px 40px #ccc;
-webkit-box-shadow: 0px 0px 40px #ccc;
}
<div id="logo">
<img src="http://icons.iconarchive.com/icons/graphicloads/colorful-long-
shadow/256/User-icon.png" alt=""/>
</div>
Kind of like this?
.image_carousel img {
margin-right: 14px;
display: block;
float: left;
box-shadow: 3px 3px 1px #ccc;
-webkit-box-shadow: 3px 3px 1px #ccc;
-moz-box-shadow: 3px 3px 1px #ccc;
}
<div class="image_carousel"><img src="//placehold.it/300/f80/fff" alt=""/></div>
Credit goes to Joseph Marikle.
Like this?
span {
border: 2px dotted red;
display: inline-block;
}
img {
padding: 0;
margin: 0;
display: block;
}
<span class="dotted-border"><img src="http://placehold.it/200"/></span>