Div shadow is not showing and appearing side by side - html

For some reason Div block shadow is not showing and the last block's shadow is appearing side by side. I don't know what else I need to do. I have z-index and position set to relative but it's still not working as expected.
Edit: I want the blocks to be side by side and responsible.
.main {
padding-top: 10px;
-moz-column-count: 4;
-moz-column-gap: 0;
-webkit-column-count: 4;
-webkit-column-gap: 0;
column-count: 4;
column-gap: 0;
}
.main .columnBlock {
background-color: #fff;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
margin: 0 4px 8px 8px;
-webkit-box-shadow: 0px 2px #d4d6d8;
-moz-box-shadow: 0px 2px #d4d6d8;
box-shadow: 0px 2px #d4d6d8;
position: relative;
z-index: 999;
}
.column {
display: inline-block;
min-width: 140px;
width: 22%;
vertical-align: top;
padding-top: 8px;
}
.column ul {
margin-top: 4px;
margin-bottom: 1em;
}
.column ul {
display: inline-block;
width: 100%;
vertical-align: baseline;
height: 100%;
}
#media screen and (max-device-width: 9999px) {
.column {
width: 100%;
height: auto;
float: none;
}
}
<div class="main" style="width: 100%;">
<div class="columnBlock">
<div class="column">
<ul>
<li>Data 1</li>
<li>Data 2</li>
<li>Data 3</li>
</ul>
</div>
</div>
<!-- .columnBlock -->
<div class="columnBlock">
<div class="column">
<ul>
<li>Data 1</li>
<li>Data 2</li>
<li>Data 3</li>
</ul>
</div>
</div>
<!-- .columnBlock -->
</div>
<!-- .main -->

I believe this is what you're looking for. I removed the column count and gap, and just using margin and floats with #media queries. I added two more columns so you can see it in action.
HTML:
<div class="main" style="width: 100%;">
<div class="columnBlock">
<div class="column">
<ul>
<li>Data 1</li>
<li>Data 2</li>
<li>Data 3</li>
</ul>
</div>
</div>
<!-- .columnBlock -->
<div class="columnBlock">
<div class="column">
<ul>
<li>Data 1</li>
<li>Data 2</li>
<li>Data 3</li>
</ul>
</div>
</div>
<!-- .columnBlock -->
<div class="columnBlock">
<div class="column">
<ul>
<li>Data 1</li>
<li>Data 2</li>
<li>Data 3</li>
</ul>
</div>
</div>
<!-- .columnBlock -->
<div class="columnBlock">
<div class="column">
<ul>
<li>Data 1</li>
<li>Data 2</li>
<li>Data 3</li>
</ul>
</div>
</div>
<!-- .columnBlock -->
</div>
<!-- .main -->
CSS:
.main {
padding-top: 10px;
display: flex;
flex-wrap: wrap;
}
.main .columnBlock {
background-color: #fff;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
margin: 0 4px 8px 8px;
-webkit-box-shadow: 0px 2px #d4d6d8;
-moz-box-shadow: 0px 2px #d4d6d8;
box-shadow: 0px 2px #d4d6d8;
position: relative;
z-index: 999;
float: left;
margin: 5px;
}
#media screen and (max-width:767px) {
.columnBlock {
width: calc(50% - 10px);
}
}
#media screen and (min-width:768px) {
.columnBlock {
width: calc(33.3333% - 10px);
}
}
#media screen and (min-width:992px) {
.columnBlock {
width: calc(25% - 10px);
}
}
.column {
display: block;
vertical-align: top;
padding-top: 8px;
}
.column ul {
margin-top: 4px;
margin-bottom: 1em;
}
.column ul {
display: inline-block;
width: 100%;
vertical-align: baseline;
height: 100%;
}
And here's a working fiddle: https://jsfiddle.net/u2h1cwzt/3/
All your shadows are where they are supposed to be and it's responsive.
Edit: added display: flex, to prevent gaps.
EDIT: Without Flex: https://jsfiddle.net/u2h1cwzt/4/
CSS: WITHOUT FLEX
.main {
padding-top: 10px;
}
.main .columnBlock {
background-color: #fff;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
margin: 0 4px 8px 8px;
-webkit-box-shadow: 0px 2px #d4d6d8;
-moz-box-shadow: 0px 2px #d4d6d8;
box-shadow: 0px 2px #d4d6d8;
position: relative;
z-index: 999;
float: left;
margin: 5px;
}
#media screen and (max-width:767px) {
.columnBlock {
width: calc(50% - 10px);
}
.columnBlock:nth-of-type(odd) {
clear: left;
}
}
#media screen and (min-width:768px) {
.columnBlock {
width: calc(33.3333% - 10px);
}
.columnBlock:nth-of-type(odd) {
clear: none;
}
.columnBlock:nth-of-type(3n+1) {
clear: left;
}
}
#media screen and (min-width:992px) {
.columnBlock {
width: calc(25% - 10px);
clear: none !important;
}
}
.column {
display: block;
vertical-align: top;
padding-top: 8px;
}
.column ul {
margin-top: 4px;
margin-bottom: 1em;
}
.column ul {
display: inline-block;
width: 100%;
vertical-align: baseline;
height: 100%;
}

i think this is what you are looking for (if i understood right). i added angularjs ng-repeat but it's just for convenient. there is also a link for a version with only html and css.
link1 - with angular https://jsfiddle.net/suunyz3e/1408/
link2 - only html and css https://jsfiddle.net/suunyz3e/1410/
html:
<div ng-app="myModule" ng-controller="myCtrl">
<div class="div-item" ng-repeat="item in loopArray">
<ul>
<li>Data 1</li>
<li>Data 2</li>
<li>Data 3</li>
</ul>
</div>
</div>
css:
.div-item{
display:inline-block;
min-width:140px;
background-color:#fff;
margin:5px;
border:1px solid red;
border-radius: 4px;
-webkit-box-shadow: 0px 2px #d4d6d8;
-moz-box-shadow: 0px 2px #d4d6d8;
box-shadow: 0px 2px #d4d6d8;
}
angualrjs
angular.module('myModule', [])
.controller('myCtrl', function ($scope) {
$scope.loopArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
});

Related

css mega menu border issue

i am trying to make a mega menu with border to look good but the border is not 100% width of box here is my code :
.mega-menu {
display: block;
overflow: hidden;
position: absolute;
top: 90px;
max-width: 630px;
background: rgb(45, 98, 214);
z-index: 1;
padding: 10px;
}
.mega-menu a {
display: block;
color: white;
margin: 5px;
font-size: 15px;
border-bottom: 1px solid rgba(255, 255, 255, 0.45);
}
.row-reset {
margin-left: 0;
margin-right: 0;
}
<div class="mega-menu">
<div class="row row-reset">
<div class="col-xl-6">
<ul>
<li>test 1</li>
<li>test 2 </li>
<li>test 3</li>
</ul>
</div>
<div class="col-xl-6">
<ul>
<li>test 4</li>
<li>test 5 </li>
<li>test 6</li>
</ul>
</div>
</div>
</div>
here is what i mean i want the border to be from this :
From This to This
since you are using bootstrap you need to customize each element.
.mega-menu {
display: block;
overflow: hidden;
position: absolute;
top: 90px;
max-width: 630px;
background: rgb(45, 98, 214);
z-index: 1;
}
.mega-menu a {
display: block;
color: white;
margin: 5px;
font-size: 15px;
}
.row-reset {
margin-left: 0;
margin-right: 0;
}
.mega-menu > div > div {
padding: 0;
}
.mega-menu > div > div ul {
padding: 0;
margin-bottom: 0rem;
}
.mega-menu > div > div ul li {
list-style: none;
border: 1px solid #ffffff;
padding: 5px 25px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div class="mega-menu">
<div class="row row-reset">
<div class="col-xl-6">
<ul>
<li>test 1</li>
<li>test 2 </li>
<li>test 3</li>
</ul>
</div>
<div class="col-xl-6">
<ul>
<li>test 4</li>
<li>test 5 </li>
<li>test 6</li>
</ul>
</div>
</div>
</div>
.mega-menu{
display: block;
overflow: hidden;
position: absolute;
top: 90px;
max-width: 630px;
background: rgb(45, 98, 214);
z-index: 1;
padding: 10px;
}
.mega-menu a{
display: block;
color: white;
margin: 5px;
font-size: 15px;
}
.row-reset{
margin-left: 0;
margin-right: 0;
}
.row-reset ul{
padding-left: 0;
}
.row-reset ul li{
border-bottom: 1px solid rgba(255, 255, 255, 0.45);
list-style: none;
}
.row-reset ul li:last-child {
border-bottom: 0px;
}
.row-reset .column ul{
border-right: 1px solid rgba(255, 255, 255, 0.45);
}
.row-reset .column:last-child ul{
border-right: 1px solid transparent !important;
}
<div class="mega-menu">
<div class="row row-reset">
<div class="col-xl-6 column px-0">
<ul>
<li>test 1</li>
<li>test 2 </li>
<li>test 3</li>
</ul>
</div>
<div class="col-xl-6 column px-0">
<ul>
<li>test 4</li>
<li>test 5 </li>
<li>test 6</li>
</ul>
</div>
</div>
</div>
You could do it as follows. It is mostly bootstrap which will be easy to code. I have used table in this case which would probably be a better choice in this case.
.mega-menu {
display: block;
overflow: hidden;
position: absolute;
top: 90px;
max-width: 630px;
background: rgb(45, 98, 214);
z-index: 1;
padding: 10px;
}
.mega-menu a {
display: block;
color: white;
margin: 5px;
font-size: 15px;
border-bottom: 1px solid rgba(255, 255, 255, 0.45);
}
.table,
td {
border: 1px solid white !important;
background-color: blue;
width: 260px !important;
font-weight: 730;
font-size: 22px;
}
td {
padding: 5px 20px !important;
}
* {
color: white !important;
}
.row-reset {
margin-left: 0;
margin-right: 0;
}
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<div class='container'>
<table class="table table-hover table-bordered font-weight-bolder table-sm mt-5">
<tbody>
<tr>
<td>test 1</td>
<td>test 4 </td>
</tr>
<tr>
<td> test 2</td>
<td>test 5 </td>
</tr>
<tr>
<td> test 3</td>
<td>test 6 </td>
</tr>
</tbody>
</table>
<div>
</div>
Hope this helps !

Div with backgroun color within Div with pre-determined width

I feel like I should be able to figure this out but I really can't...
I basically have a div that is contains another set of divs/elements. I want the first div within this container to have a background color to effectively give the parent div a colored top bar/portion. The closest I can get is using display: flex; to give it full height coloring, but I can't get it the way I want. Any help is appreciated.
.container {
border: 1px solid grey;
border-radius: 4px;
padding: 0px 10px 10px 10px;
}
.content {
height: 400px;
}
.sp-h3 {
display: flex;
background-color: #008ed0;
color: white;
}
* {
box-sizing: border-box;
}
.container::before,
.container::after {
content: "";
clear: both;
}
<div class="container">
<div class="sp-h3">
<h3>Bob McBob</h3>
</div>
<div class="content">
<p>Just for something</P>
<ul>
<li>The number 1</li>
<li>The number 2</li>
<li>The number 3</li>
<li>The number 4</li>
</ul>
</div>
</div>
You could set padding to the child elements, instead of setting it to the whole .container.
.container {
border: 1px solid grey;
border-radius: 4px;
}
.content {
height: 400px;
padding: 0px 10px 10px 10px;
}
.sp-h3 {
display: flex;
background-color: #008ed0;
color: white;
padding: 0px 10px 10px 10px;
}
* {
box-sizing: border-box;
}
.container::before,
.container::after {
content: "";
clear: both;
}
<div class="container">
<div class="sp-h3">
<h3>Bob McBob</h3>
</div>
<div class="content">
<p>Just for something</P>
<ul>
<li>The number 1</li>
<li>The number 2</li>
<li>The number 3</li>
<li>The number 4</li>
</ul>
</div>
</div>
You can consider a simple gradient coloration on the container so you won't have the issue related to padding:
.container {
border: 1px solid grey;
border-radius: 4px;
padding: 0px 10px 10px 10px;
background:
linear-gradient(to bottom,#008ed0 60px,transparent 0);
}
.content {
height: 400px;
}
.sp-h3 {
display: flex;
color: white;
}
* {
box-sizing: border-box;
}
.container::before,
.container::after {
content: "";
clear: both;
}
<div class="container">
<div class="sp-h3">
<h3>Bob McBob</h3>
</div>
<div class="content">
<p>Just for something</p>
<ul>
<li>The number 1</li>
<li>The number 2</li>
<li>The number 3</li>
<li>The number 4</li>
</ul>
</div>
</div>

When the parent is float:left and the child is fixed, how to set position?

I would like to change the picture above as shown below.
Please refer to the code below.
I'm wondering how to solve this problem without 'padding-left, margin-left'
.nav-wrap {
position: relative;
overflow: hidden;
top: -2px;
width: 33.33333333333333%;
float: left;
}
.sidebar-nav {
position: fixed;
width: 380px;
padding-top: 95px;
padding-bottom: 95px;
padding-left: 20px;
padding-right: 20px;
height: 100%;
float: left;
clear: both;
overflow-y: hidden;
display: block;
background: transparent;
background: rgba(0, 0, 0, 0.28);
z-index: 10;
}
.content-wrap {
width: 66.66666666666666%;
background: #fff;
float: left;
height: 100%;
position: relative;
padding: 45px 50px;
overflow: hidden;
}
<div class="nav-wrap">
<div class="sidebar-nav">
</div>
</div>
<div class="content-wrap">
</div>
Try this instead - I've created a barebone for you without bootstrap. You can start from here.
<ul id="mainWrapper">
<li class="left-wrap">
<div class="menuList">
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
</div>
</li>
<li class="right-wrap">
Content here...
</li>
</ul>

CSS - How to place absolute div correctly

I have the following code:
.menu{
border: solid red;
border-width: 1px 1px 0px 1px;
background-color:black;
color:white;
width: 60px;
}
.dropdown{
position:absolute;
background-color: grey;
width:100px;
}
.dropdown ul{
list-style:none;
padding:10px;
margin: 0;
}
.zoom{
zoom:300%;
}
<div class="menu zoom">
Click me
<div class="dropdown">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>
How can I place my dropdown menu to the same x position as the parent, without removing the border? I already tried 'box-sizing: border-box', but somehow it doesn't work.
Set position: relative on parent element and on child set position left to same negative value as left border width of parent element.
.menu {
border: solid red;
border-width: 1px 1px 0px 1px;
background-color: black;
color: white;
width: 60px;
position: relative;
}
.dropdown {
position: absolute;
background-color: grey;
width: 100px;
left: -1px;
}
.dropdown ul {
list-style: none;
padding: 10px;
margin: 0;
}
.zoom {
zoom: 300%;
}
<div class="menu zoom">
Click me
<div class="dropdown">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>
Keeping the parent as positon:relative and giving the child position:absolte with top:100%; and left:-1px ( where -1 is taken because the width of border is 1 from left)
Here is the working snippet:
.menu {
border: solid red;
border-width: 1px 1px 0px 1px;
background-color: black;
color: white;
width: 60px;
position: relative;
}
.dropdown {
position: absolute;
background-color: grey;
width: 100px;
left: -1px;
top:100%
}
.dropdown ul {
list-style: none;
padding: 10px;
margin: 0;
}
.zoom {
zoom: 300%;
}
<div class="menu zoom">
Click me
<div class="dropdown">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>

CSS position relative forcing the height of element

I have two (almost) clone elements (#container and #container-shadow). The same css rules are supposed to be applied equally to them. However, the second .box3 div element is four times the height it should be. Why is that?
codepen -> http://codepen.io/thiagoh/pen/aJwbOZ
CSS code
#container {
position: relative;
top: -90px;
left: 400px;
float: left;
}
#container-shadow div,
#container div {
width: 280px;
box-sizing: border-box;
position: relative;
}
.box3 {
background-color: lightgray;
line-height: 24px;
padding: 4px;
border: 1px solid black;
}
.box4 {
background-color: darkgray;
border: 1px solid black;
border-top: 0px;
padding: 0;
left: 10px;
}
.box4 ul {
padding: 0;
margin: 0;
}
.box4 li {
list-style: none;
line-height: 24px;
padding: 4px;
border-bottom: 1px solid lightgray;
}
HTML code
<div style="height: 100px;"></div>
<div id="container">
<div class="box3">
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
<div id="container-shadow">
<div class="box3">
why this element is this height?
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
current result
expected result
PS: Note the position of the boxes. That's the required position in my situation. clear:both on #container-shadow does not fix my problem.
You should not use the float:left on the #container, it should look like this:
#container {
position: relative;
top: -90px;
left: 400px;
}
here is an updated codepen:Codepen
This is because you have a float: left on your #container which is not cleared - add this after the #container:
<div style="clear:both"></div>
to clear the float - see demo below:
#container {
position: relative;
top: -90px;
left: 400px;
float: left;
}
#container-shadow div,
#container div {
width: 280px;
box-sizing: border-box;
position: relative;
}
.box3 {
background-color: lightgray;
line-height: 24px;
padding: 4px;
border: 1px solid black;
}
.box4 {
background-color: darkgray;
border: 1px solid black;
border-top: 0px;
padding: 0;
left: 10px;
}
.box4 ul {
padding: 0;
margin: 0;
}
.box4 li {
list-style: none;
line-height: 24px;
padding: 4px;
border-bottom: 1px solid lightgray;
}
<div style="height: 100px;"></div>
<div id="container">
<div class="box3">
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
<div style="clear:both"></div><!-- ADDED THIS -->
<div id="container-shadow">
<div class="box3">
why this element is this height?
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
EDIT:
If you don't want the #container-shadow to drop down, you can relatively position it and float it to left using something like this:
#container-shadow {
float: left;
left: -275px;
position: relative;
}
See demo below:
#container {
position: relative;
top: -90px;
left: 400px;
float: left;
}
#container-shadow div,
#container div {
width: 280px;
box-sizing: border-box;
position: relative;
}
.box3 {
background-color: lightgray;
line-height: 24px;
padding: 4px;
border: 1px solid black;
}
.box4 {
background-color: darkgray;
border: 1px solid black;
border-top: 0px;
padding: 0;
left: 10px;
}
.box4 ul {
padding: 0;
margin: 0;
}
.box4 li {
list-style: none;
line-height: 24px;
padding: 4px;
border-bottom: 1px solid lightgray;
}
#container-shadow {
float: left;
left: -275px;
position: relative;
}
<div style="height: 100px;"></div>
<div id="container">
<div class="box3">
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
<div id="container-shadow">
<div class="box3">
why this element is this height?
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
I would suggest removing float and use inline-block for #container and #container-shadow (note that I have swapped their position in the markup) and then apply positioning to the #container to get the desired result:
#container {
position: relative;
top: -90px;
left: 50px;
display: inline-block;
}
#container-shadow {
display: inline-block;
}
#container-shadow div,
#container div {
width: 280px;
box-sizing: border-box;
position: relative;
}
.box3 {
background-color: lightgray;
line-height: 24px;
padding: 4px;
border: 1px solid black;
}
.box4 {
background-color: darkgray;
border: 1px solid black;
border-top: 0px;
padding: 0;
left: 10px;
}
.box4 ul {
padding: 0;
margin: 0;
}
.box4 li {
list-style: none;
line-height: 24px;
padding: 4px;
border-bottom: 1px solid lightgray;
}
<div style="height: 100px;"></div>
<div id="container-shadow">
<div class="box3">
why this element is this height?
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
<div id="container">
<div class="box3">
</div>
<div class="box4">
<ul>
<li>line 1</li>
<li>line 2</li>
<li>line 3</li>
<li>line 4</li>
</ul>
</div>
</div>
The solution is simple.
Remove this:
float: left;
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
The float: left attempts to force container-shadow to occupy this space causing distortion.
It's your same code just comment the float:
#container {
position: relative;
top: -90px;
left: 400px;
/* float: left;*/
}
#container-shadow div,
#container div {
width: 280px;
box-sizing: border-box;
position: relative;
}
.box3 {
background-color: lightgray;
line-height: 24px;
padding: 4px;
border: 1px solid black;
}
.box4 {
background-color: darkgray;
border: 1px solid black;
border-top: 0px;
padding: 0;
left: 10px;
}
.box4 ul {
padding: 0;
margin: 0;
}
.box4 li {
list-style: none;
line-height: 24px;
padding: 4px;
border-bottom: 1px solid lightgray;
}