I want the block elements inside CSS columns to have box shadow. The following, simplified code renders as expected in IE10 and Firefox 21, but in current Chrome version (28.0.1500.72) shadows near the column sides are trimmed.
The images present results in IE/FF (on the left), and Chrome on the right:
(there's also some vertical shift, but it's not an issue)
Here's the jsfiddle:
http://jsfiddle.net/buli_pl/KxYRc/1/
div#column-container {
/* Set 2 columns*/
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
div#column-container div {
background-color: yellow;
/* set shadow for yellow elements */
box-shadow: 0px 1px 3px #000;
-webkit-box-shadow: 0px 0px 15px #000;
-moz-box-shadow: 0px 0px 15px #000;
box-shadow: 0px 0px 15px #000;
/* Make sure that yellow div is not split between columns */
display: inline-block;
width: 100%;
/* the rest - just to better present the problem */
height: 70px;
margin-top: 0;
margin-bottom: 20px;
}
<div id="column-container">
<div>box 1</div>
<div>box 2</div>
<div>box 3</div>
<div>box 4</div>
<div>box 5</div>
<div>box 6</div>
</div>
Am I misusing some of those properties, or this is a Chrome issue? How can it be fixed at the moment?
Just happened upon a potentially more straightforward solution that seems to work. Applying transform: translateZ(0); to the elements with box-shadows seems to be resolving this issue. In the supplied code, you would add this to your div#column-container div rule.
.container{
break-inside: avoid;
column-count: 2;
column-gap: 2rem;
}
.box{
border-radius: 4px;
box-shadow: 2px 2px 20px rgba(0, 0, 0, 0.2);
margin-bottom: 1rem;
padding: 1rem;
break-inside: avoid;
transform: translateZ(0);
}
https://codepen.io/MarkitDigital/pen/RdLoRG
You could use flexbox for this instead of css columns.
FIDDLE
NB: This currently doesn't work in Firefox because it still doesn't support the flex-wrap property, however according to caniuse - this will be supported in version 28
CSS
div#column-container {
height: 270px; /* NB: IE requires the height property. max-height won't work on IE)*/
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: flex-start;
}
EDIT: (Updated FIDDLE which includes support for Firefox)
As per #buli's suggestion to temporarily use the -moz-colums-count for Firefox as long as flex-wrap is not supported:
Well, you could do this with the #supports which allows us to perform feature queries - sort of like Modernizr, but with CSS.
The good thing here, is that Firefox supports them.
So if I add the following code: (updated as per Pavlo's suggestion)
#supports (not (flex-wrap: wrap)) and (-moz-columns: 2) {
div#column-container {
-moz-column-count: 2;
column-count: 2;
display: block;
width: 50%;
}
}
Now, Firefox will use CSS columns, whereas other browsers will use flexbox.
this should work too : http://codepen.io/anon/pen/fiHCv
(from my comment to get your feeling about it :) )
It might work using calc() to reduce width of blocks to let shadows being seen and rework margin and padding for nicer layout
div#column-container {
/* Set 2 columns*/
column-count: 2;
column-gap:0;
width:80%;
margin:auto;
padding:20px 0;
}
div#column-container div {
background-color: yellow;
box-shadow: 0px 0px 15px #000;
/* Make sure that yellow div is not split between columns */
display: inline-block;
/* leave room for shadow to be drawn */
width: calc(100% - 30px);
/* the rest - just to better present the problem */
height: 70px;
margin: 20px;
}
manage margin and padding, so top of columns may be on same vertical level and fit to your grid
Here's a simple work-around for Chrome: For your yellow blocks, just change the width and the margin. For the drop-shadow to show up you want to make sure there is some margin room around the block.
width: 80%;
margin: 1em 10%;
http://jsfiddle.net/dPg2n/1/ --- Works in both Chrome 31 and FireFox 10.0.2.
Chrome is failing to compensate for the extra width added by the shadow.
If you add "text-align: center;" to the div#column-container, the yellow inner div will center and you can now see shadow on the left edge.
If change the insignificant "width: 100%;" on the yellow inner div to "width: 85%;" (or a width of your choice) now there is room for the entire shadow.
div#column-container {
/* Set 2 columns*/
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
/* insignificant - except text-align, which corrects Chrome */
width: 50%;
text-align: center;
}
div#column-container div {
background-color: yellow;
/* set shadow for yellow elements */
box-shadow: 0px 1px 3px #000;
-webkit-box-shadow: 0px 0px 15px #000;
-moz-box-shadow: 0px 0px 15px #000;
box-shadow: 0px 0px 15px #000;
/* Make sure that yellow div is not split between columns */
display: inline-block;
/* the rest - width was significant for Chrome, you may need to adjust for your real project */
width: 85%;
height: 70px;
margin-top: 0;
margin-bottom: 20px;
}
Here is a jsFiddle.
Had similar issues with a 3 column layout. Chrome cut the box-shadow but only on top in column 2 and 3...
box-shadow cut
Margin Workaround:
.item {
box-shadow: 0px 0px 15px #000;
display: inline-block;
margin-top: 15px; /* same as box-shadow blur */
width: 100%;
}
.container{
column-count: 3;
column-gap: 30px;
margin-top: -15px;/* negative value same as box-shadow blur & item margin-top */
}
I think column-count is conflicting with chrome...
Try This:
div#column-container {
/* Set 2 columns*/
/* insignificant */
width: 50%;
}
div#column-container div {
background-color: yellow;
/* set shadow for yellow elements */
box-shadow: 0px 0px 15px #000;
-webkit-box-shadow: 0px 0px 15px #000;
-moz-box-shadow: 0px 0px 15px #000;
/* Make sure that yellow div is not split between columns */
display: inline-block;
/* the rest - not significant */
width: 46%;
height: 70px;
margin-top: 0;
margin-bottom: 20px;
margin-right: 2%;
float:left;
}
div#column-container {
/* Set 2 columns*/
overflow: hidden;
padding: 5px;
display: block;
/* insignificant */
width: 50%;
}
div#column-container div {
background-color: yellow;
float: left;
width: 40%;
margin: 5%;
/* set shadow for yellow elements */
box-shadow: 0px 1px 3px #000;
-webkit-box-shadow: 0px 0px 15px #000;
-moz-box-shadow: 0px 0px 15px #000;
box-shadow: 0px 0px 15px #000;
/* Make sure that yellow div is not split between columns */
display: block;
/* the rest - not significant */
height: 70px;
}
This will give you almost similar look.
And the Fiddle is here.
P.S.Alter the margin and width values by yourself to make the boxes closer as per your requirement.
Here's a related bug filed with chromium. Basically, it seems that chrome just isn't that good at rendering the css columns properties. https://code.google.com/p/chromium/issues/detail?id=467196
A quick workaround is to surround your boxes in larger transparent divs that leave enough room for the shadow. This solves both of the problems.
<div id="column-container">
<div class="outer"><div>box 1</div></div>
<div class="outer"><div>box 2</div></div>
<div class="outer"><div>box 3</div></div>
<div class="outer"><div>box 4</div></div>
<div class="outer"><div>box 5</div></div>
<div class="outer"><div>box 6</div></div>
</div>
div#column-container {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
div#column-container div {
background-color: yellow;
box-shadow: 0px 1px 3px #000;
-webkit-box-shadow: 0px 0px 15px #000;
-moz-box-shadow: 0px 0px 15px #000;
box-shadow: 0px 0px 15px #000;
width: 100%;
height: 70px;
margin: 0;
}
.outer {
break-inside: avoid;
padding-top: 0px;
padding-left: 4px;
padding-right: 4px;
padding-bottom: 20px;
}
.box {
break-inside: avoid;
column-count: 2;
column-gap: 2rem;
}
.item {
border-radius: 4px;
box-shadow: 2px 2px 20px rgba(0, 0, 0, 0.2);
margin-bottom: 1rem;
padding: 1rem;
break-inside: avoid;
transform: translateZ(0);
}
Related
My buttons keep expanding to container width. I want to make them normal, just wrapped around the text. The size depends on how long the text is.
Does anyone know what I'm doing wrong?
Thanks!
.btn {
display: inline-block;
padding: 10px 30px;
cursor: pointer;
background: var(--orange-color);
color: white;
border-radius: 5px;
box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
Most probably you have a width: 100% on your button in some part of your CSS file.
Or the containing element is a flex-container with flex-direction: column. This also may cause the button to stretch to the width of the container. (caused by the default align-items: stretch)
.btn {
display: inline-block;
padding: 10px 30px;
cursor: pointer;
background: var(--orange-color);
color: white;
border-radius: 5px;
box-shadow: 0 3px 10px rgba(0,0,0,0.2);
width: max-content; /* pushes the width to be the size of the content */
max-width: 100%; /* ensures the button doesn't overflow the container */
}
I'm working on an internet layout using CSS grid, and one of my grid areas is a navbar. I have tried to make buttons inside the navbar using divs. I have tried to use the :hover selector on the div to change the mouse to pointer, change the bg color, etc, but it isn't working.
When I force hover in chrome using dev tools it acts as if there were no code for hover on the button at all. I have tried to use the hover on the navbar itself, and it works but the strange thing is that it causes the hover to function correctly on the button as well. So, if I apply the same hover rules to the navbar, I can hover over the navbar or over the button and they both work.
For my assignment I have to use SCSS, so the code below is the compiled CSS code. Can the SCSS cause problems like this?
.myGrid {
display: -ms-grid;
display: grid;
grid-template-areas: "nav nav nav nav nav" background-color: white;
width: 85%;
margin: auto;
margin-top: 0px;
}
.myGrid section {
text-align: center;
-webkit-box-shadow: 0px 15px 20px black;
box-shadow: 0px 15px 20px black;
overflow: hidden;
}
#myNavMenu {
background-color: brown;
-ms-grid-row: 3;
-ms-grid-column: 1;
-ms-grid-column-span: 5;
grid-area: nav;
height: 100px;
margin-top: 20px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
-webkit-box-shadow: 0px 0px 20px black;
box-shadow: 0px 0px 20px black;
}
.myButton {
background-color: white;
width: 100px;
height: 30px;
padding: 5px;
margin: auto;
border-radius: 8px;
z-index: 2;
}
.myButton :hover {
cursor: pointer;
}
<main class="myGrid">
<section class="navMenu" id="myNavMenu">
<h3>Nav</h3>
<div class="myButton" id="button1"> MyButton </div>
</section>
</main>
the space between .myButton and :hover causes all the mess.
.myButton :hover {
cursor: pointer;
}
Here is a working version https://jsfiddle.net/m0sc9ugb/
I have 2 divs, one nested inside of the other. According to the page design, the nested div needs to appear normally inside its parent on a large screen, as in this image.
But on a small screen, the nested div needs to appear to be above the parent div, as in this image.
I don't want to position the child element absolutely, because it's a very poor and inflexible choice, especially for a responsive page.
HTML for divs / CSS for divs (on a large screen only):
.container-div {
background-size: 100% auto;
margin-bottom: 20px;
-webkit-box-shadow: 0px 1px 3px 0px rgba(0,0,0,.73), 0px 0px 18px 0px rgba(0,0,0,.13);
-moz-box-shadow: 0px 1px 3px 0px rgba(0,0,0,.73), 0px 0px 18px 0px rgba(0,0,0,.13);
box-shadow: 0px 1px 3px 0px rgba(0,0,0,.73), 0px 0px 18px 0px rgba(0,0,0,.13);
}
.child-div {
position: absolute;
border: 3px solid white;
width: 400px;
height: 200px;
margin-bottom: 10px;
margin-right: 10px;
bottom: 0;
}
<div class="container-div">
<div class="child-div">
...
</div>
</div>
Use an inner-parent and flexbox.
.parent {
display: flex;
flex-flow: column-reverse;
}
.inner-parent {
background: red;
}
.child {
background: blue;
}
#media screen and (min-width: 640px) {
.parent {
flex-flow: column;
background: red;
}
}
/* Reset and basic styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.parent {
align-items: center;
width: 200px;
}
.inner-parent {
height: 50px;
width: 100%;
padding: 20px;
text-align: center;
}
.child {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20px;
height: 50px;
width: 75%;
}
<div class="parent">
<div class="inner-parent">PARENT</div>
<div class="child">CHILD</div>
</div>
When smaller than 640px use .inner-parent as the lower div and use the real parent when larger than 640px by making it's background color match. To fix the order just switch from column-reverse to column or just use order to change the order of just one of the child divs.
I am not sure how to explain this at all other than showing the problem. I have the following code:
#photoBox {
-webkit-column-count: 4;
-moz-column-count: 4;
column-count: 4;
-webkit-column-break-inside: avoid; /* Chrome, Safari */
page-break-inside: avoid; /* Theoretically FF 20+ */
break-inside: avoid-column; /* IE 11 */
display:table; /* Actually FF 20+ */
}
#photoBox img{
width: 100% !important;
height: auto !important;
display: block;
}
#photoBox .photo{
position: relative;
float: left;
box-shadow:
0px 0px 0px 2px rgba(0,0,0,0.6),
0px 0px 0px 14px #fff,
0px 0px 0px 18px rgba(0,0,0,0.2),
6px 6px 8px 17px #555;
margin: 25px;
}
#photoBox .title {
position: absolute;
background-color:rgba(255,255,255,0.7);
color: #000;
text-align: center;
font-weight: bold;
width: 100% !important;
bottom: 0;
}
I get the following results:
What i would like to get is the images to "fill in all the spaces"
Like so:
I was able to do this in the second screen using a mess of tricks that will not allow me to use my current styling to work at all.
Can someone guide me with what i am doing wrong with this CSS to get my desired results?
Thanks!
JAC
Use masonry jquery library to handle the problem:
Include masonry
script src="/path/to/masonry.pkgd.min.js"
2.If you have the following html:
<div class="grid">
<div class="grid-item">...</div>
<div class="grid-item grid-item--width2">...</div>
<div class="grid-item">...</div>
...
</div>
3.Then your script should be like:
$('.grid').masonry({
itemSelector: '.grid-item',
columnWidth: 200
});
4.And the CSS:
.grid-item { width: 200px; }
.grid-item--width2 { width: 400px; }
I'm trying to get some elements to move slightly when the user mouses over them (they form buttons on a navbar). However, my code doesn't seem to work. The text in the boxes should also be clickable but that doesn't seem to work either. Here's the code:
#navbar {
position: relative;
width: max-width;
height: auto;
margin-left: 2%;
}
.nav_tab{
background-image: url('dark_exa.png');
border: 2px dashed grey;
/* rounded borders of 5px in firefox */
-moz-border-radius:10px;
/* rounded borders of 5px in chrome and other browsers */
-webkit-border-radius:10px;
/* rounded borders of 5px in browsers that support css3 */
border-radius:10px;
/* shadows for different browsers */
-moz-box-shadow: 0 0 0 3px black, 2px 1px 4px 4px rgba(10,10,0,.5);
-webkit-box-shadow: 0 0 0 3px black 2px 1px 4px 4px rgba(10,10,0,.5);
box-shadow: 0 0 0 3px black, 2px 1px 6px 4px rgba(10,10,0,.5);
position: relative;
height: auto;
width:20%;
z-index: -1;
margin-left: 2%;
margin-right: 2%;
top: -30px;
display: inline-block;
}
.nav_tab:hover{
position: relative;
top: +5px;
}
h1 {
font-size:40px;
text-align: center;
color: white;
font-family: "Gabriela";
margin: 20px;
margin-top: 130px;
}
h2 {
font-size:30px;
text-align: center;
color: white;
font-family: "Gabriela";
margin: 10px;
margin-top: 40px;
}
And the HTML:
<div id="navbar">
<div class="nav_tab"><h2>Zues</h2></div>
<div class="nav_tab"><h2>Jack</h2></div>
<div class="nav_tab"><h2>Denise</h2></div>
<div class="nav_tab"><h2>Joel</h2></div></div>
I'm not entirely sure what's going on here, though I presume it's some kind of parent-child issue.
Thanks.
The link is not clickable because you gave the .nav_tab class a negative z-index value just adjust it to a value => 0 and it'll work.
The z-index: -1; of the .nav_tab css it's your problem, it makes the container behind the page so any mouse event won't work (hover, pointer, etc) remove it and your ready to go:
see the jsfiddle demo:
http://jsfiddle.net/QmVFR/64/