It would be lovely to have the option of where to place a box-shadow. Currently I have a div with some padding. The background color is set to clip on the content-box. That's good. However the box-shadow that I have appear on hover begins at the border-box. Perhaps there is some super secret css I don't know (one can wish, right?)
I know I can add another div after .wrapper, but I'm looking to avoid that. More curious if it is actually possible to position the box-shadow on the content-box.
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
transition: box-shadow 0.2s ease-in-out 0s;
background-clip:content-box;
}
.wrapper:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
You do already have this wrapper you talk about , the <a> around it.
You need to style it too and apply the shadow to it:
.wrapper a {
padding-bottom:1px;/* to deal with collapsing margin if not reset (to <p> here) */
display:block;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper a:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
background-clip:content-box;
}
.wrapper a {
padding-bottom:1px;
display:block;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper a:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
pseudo approach
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
background-clip:content-box;
position:relative;
}
.wrapper:before {
content:'';
position:absolute;
pointer-events:none; /* allow to reach links or inside wrapper content */
top:0;
bottom:1em;
left:0;
right:1em;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper:hover:before {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
Just use margin-bottom: 1em; margin-right: 1em; in your wrapper instead of padding.
CODE SNIPPET:
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
margin-bottom: 1em;
margin-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
transition: box-shadow 0.2s ease-in-out 0s;
background-clip:content-box;
}
.wrapper:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
Another way is to apply the padding-top to the .page class instead of the .container class. A code snippet below might explain
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height: 100%;
width: 100%;
padding-top: 50px;
}
.container {
width: 30%;
margin: 0 auto;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img {
width: 100%;
background-clip: content-box;
}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
</div>
Here's a solution that works with background-clip:content-box;
Use the following instead of box-shadow :
filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.15));
-webkit-filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.15));
Related
I have the following CSS for a button:
.Button {
background-color: #somehex;
}
When the user hovers over the button, I want the background-color to be a little darker. I have tried changing opacity, which didn't work, and currently am doing it this way:
.Button:hover {
transition: 0.2s ease-in;
background-color: #ALittleDarkerHex;
}
While this process works, it is really tedious because I have to manually look for a darker version of the color I am working with. I was wondering if there was an easier way to darken the background-color of a button using CSS.
Add a dark layer on the top of it using background-image. This method keeps your text visible in the same color while changing only the background.
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background-color: red;
}
.button:hover {
background-image: linear-gradient(rgb(0 0 0/40%) 0 0);
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
To have a transition:
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background: linear-gradient(#0000, rgb(0 0 0/40%)) top/100% 800%;
background-color: red;
transition: 0.5s;
}
.button:hover {
background-position: bottom;
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
Another idea with mix-blend-mode:
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background-color: red;
background-image: linear-gradient(rgb(0 0 0/40%) 0 0);
background-blend-mode: lighten;
}
.button:hover {
background-blend-mode: darken;
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
You can also consider a big inset box-shadow and you will also have the ability to add transition:
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background-color: red;
box-shadow: 0 0 0 100vmax inset rgb(0 0 0/var(--o,0%));
transition: .4s;
}
.button:hover {
--o: 40%;
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
This is one way you can do it
.button {
background-color: red;
}
.button:hover {
filter: brightness(60%);
}
<button class="button">Button</button>
Anything above brightness(100%) will increase the brightness and anything less will make it darker.
Using HSL color values may meet your needs. The HSL color model is more human-readable than Hex (#FF334E).
HSL color values are specified with: hsl(hue, saturation, lightness).
div {
width: auto;
display: inline-flex;
justify-content: center;
align-items: center;
margin: 0.5rem 0;
padding: 1rem 2rem;
color: white;
}
.Button {
--hue: 712;
--saturation: 100%;
--lightness: 60%;
background-color: hsl(var(--hue), var(--saturation), var(--lightness));
}
.Button.dark:hover {
transition: 0.2s ease-in;
--lightness: 40%;
/* 20% dark */
}
.Button.light:hover {
transition: 0.2s ease-in;
--lightness: 80%;
/* 20% light */
}
<div class='Button dark'>some text</div>
<div class='Button light'>some text</div>
Put pseudo element behind button content and modify its opacity on hover
const colors = ['#052F5F','#005377','#06A77D','#D5C67A','#F1A208'];
const btn = document.querySelector('.Button');
btn.addEventListener('click', (e) => {
e.preventDefault();
btn.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
});
.Button {
background-color: #F1A208;
color:#fff;
border: 0;
border-radius: 20px;
padding: 10px 22px;
cursor:pointer;
position: relative;
}
.Button:before {
content: '';
position: absolute;
z-index:0;
border-radius: 20px;
top:0;
left:0;
right:0;
bottom:0;
background-color: rgba(0,0,0,0);
transition: .2s ease;
}
.Button span {
position: relative;
z-index:1;
}
.Button:hover:before {
background-color: rgba(0,0,0,.3);
}
<button class="Button"><span>hover me</span></button>
I have the following CSS for a button:
.Button {
background-color: #somehex;
}
When the user hovers over the button, I want the background-color to be a little darker. I have tried changing opacity, which didn't work, and currently am doing it this way:
.Button:hover {
transition: 0.2s ease-in;
background-color: #ALittleDarkerHex;
}
While this process works, it is really tedious because I have to manually look for a darker version of the color I am working with. I was wondering if there was an easier way to darken the background-color of a button using CSS.
Add a dark layer on the top of it using background-image. This method keeps your text visible in the same color while changing only the background.
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background-color: red;
}
.button:hover {
background-image: linear-gradient(rgb(0 0 0/40%) 0 0);
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
To have a transition:
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background: linear-gradient(#0000, rgb(0 0 0/40%)) top/100% 800%;
background-color: red;
transition: 0.5s;
}
.button:hover {
background-position: bottom;
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
Another idea with mix-blend-mode:
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background-color: red;
background-image: linear-gradient(rgb(0 0 0/40%) 0 0);
background-blend-mode: lighten;
}
.button:hover {
background-blend-mode: darken;
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
You can also consider a big inset box-shadow and you will also have the ability to add transition:
.button {
display: inline-block;
color: #fff;
padding: 10px 20px;
font-size: 20px;
background-color: red;
box-shadow: 0 0 0 100vmax inset rgb(0 0 0/var(--o,0%));
transition: .4s;
}
.button:hover {
--o: 40%;
}
<div class="button"> some text </div>
<div class="button" style="background-color:lightblue;"> some text </div>
<div class="button" style="background-color:green;"> some text </div>
<div class="button" style="background-color:grey;"> some text </div>
This is one way you can do it
.button {
background-color: red;
}
.button:hover {
filter: brightness(60%);
}
<button class="button">Button</button>
Anything above brightness(100%) will increase the brightness and anything less will make it darker.
Using HSL color values may meet your needs. The HSL color model is more human-readable than Hex (#FF334E).
HSL color values are specified with: hsl(hue, saturation, lightness).
div {
width: auto;
display: inline-flex;
justify-content: center;
align-items: center;
margin: 0.5rem 0;
padding: 1rem 2rem;
color: white;
}
.Button {
--hue: 712;
--saturation: 100%;
--lightness: 60%;
background-color: hsl(var(--hue), var(--saturation), var(--lightness));
}
.Button.dark:hover {
transition: 0.2s ease-in;
--lightness: 40%;
/* 20% dark */
}
.Button.light:hover {
transition: 0.2s ease-in;
--lightness: 80%;
/* 20% light */
}
<div class='Button dark'>some text</div>
<div class='Button light'>some text</div>
Put pseudo element behind button content and modify its opacity on hover
const colors = ['#052F5F','#005377','#06A77D','#D5C67A','#F1A208'];
const btn = document.querySelector('.Button');
btn.addEventListener('click', (e) => {
e.preventDefault();
btn.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
});
.Button {
background-color: #F1A208;
color:#fff;
border: 0;
border-radius: 20px;
padding: 10px 22px;
cursor:pointer;
position: relative;
}
.Button:before {
content: '';
position: absolute;
z-index:0;
border-radius: 20px;
top:0;
left:0;
right:0;
bottom:0;
background-color: rgba(0,0,0,0);
transition: .2s ease;
}
.Button span {
position: relative;
z-index:1;
}
.Button:hover:before {
background-color: rgba(0,0,0,.3);
}
<button class="Button"><span>hover me</span></button>
I have a blog element which has 2 children: .blog-header (contains background image) and .blog-body.. When hovering the mouse on .blog-header, i expect the image to be scaled perfectly. But here's the problem: the image takes the space where .blog-body should lay on
Here's my code:
.blog {
background: white;
margin-top: 20px;
border-top: 3px primary solid;
border-bottom 3px solid #eee;
}
.blog .blog-header {
overflow: hidden;
z-index 90;
}
.blog .blog-header .blog-bg-header {
height: 275px;
background-position: center;
background-size: cover;
transition: 0.25s ease-in-out;
}
.blog .blog-header .blog-bg-header:hover {
cursor: pointer;
transform: scale(1.3);
}
.blog-body {
margin: -60px 20px 0 20px;
padding: 20px 20px 10px 20px;
background: white;
z-index 100;
}
<article class="blog">
<header class="blog-header">
<div class="blog-bg-header" style="background-image: url('http://placehold.it/1350x750')"></div>
</header>
<div class="blog-body">
<time class="blog-date">24 Jan</time>
<a href="example.com">
<h2>Title</h2>
<p>Content</p>
</a>
</div>
</article>
The external link to see the issue http://jsfiddle.net/a49evb1q/
Is there any solution to overcome the issue?
Your z-index on .blog-body will have no effect because you aren't giving it a position.
.blog-body {
margin: -60px 20px 0 20px;
padding: 20px 20px 10px 20px;
background: white;
z-index 100;
position: relative; <!-- ADD THIS
}
Example...
.blog {
background: white;
margin-top: 20px;
border-top: 3px primary solid;
border-bottom 3px solid #eee;
}
.blog .blog-header {
overflow: hidden;
z-index 90;
}
.blog .blog-header .blog-bg-header {
height: 275px;
background-position: center;
background-size: cover;
transition: 0.25s ease-in-out;
}
.blog .blog-header .blog-bg-header:hover {
cursor: pointer;
transform: scale(1.3);
}
.blog-body {
margin: -60px 20px 0 20px;
padding: 20px 20px 10px 20px;
background: white;
z-index 100;
position:relative;
}
<article class="blog">
<header class="blog-header">
<div class="blog-bg-header" style="background-image: url('http://placehold.it/1350x750')"></div>
</header>
<div class="blog-body">
<time class="blog-date">24 Jan</time>
<a href="example.com">
<h2>Title</h2>
<p>Content</p>
</a>
</div>
</article>
EDIT
Actually, you can remove the z-index values from your code altogether. A position: relative will do the trick on it's own
Updated example...
.blog {
background: white;
margin-top: 20px;
border-top: 3px primary solid;
border-bottom 3px solid #eee;
}
.blog .blog-header {
overflow: hidden;
}
.blog .blog-header .blog-bg-header {
height: 275px;
background-position: center;
background-size: cover;
transition: 0.25s ease-in-out;
}
.blog .blog-header .blog-bg-header:hover {
cursor: pointer;
transform: scale(1.3);
}
.blog-body {
margin: -60px 20px 0 20px;
padding: 20px 20px 10px 20px;
background: white;
position:relative;
}
<article class="blog">
<header class="blog-header">
<div class="blog-bg-header" style="background-image: url('http://placehold.it/1350x750')"></div>
</header>
<div class="blog-body">
<time class="blog-date">24 Jan</time>
<a href="example.com">
<h2>Title</h2>
<p>Content</p>
</a>
</div>
</article>
I'm attempting to make a ribbon for a navbar using bootstrap and my own CSS work. I have the majority of what I need finished, however I cannot seem to make the right side of the ribbon align with the navbar.
(colors purposefully bad to make the example obvious)
Here's an example of my situation: JSBin example
CSS:
nav.navbar {
border-radius: 0px;
border-left: none;
border-right: none;
box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.15), 0 1px 5px -5px rgba(0, 0, 0, 0.075);
box-shadow: none;
}
div.ribbon-left {
left: -13px;
float: left;
width: 13px;
border-right: none;
}
div.ribbon-right {
width: 13px;
float: right;
right: -13px;
border-left: none;
}
div.ribbon-left, div.ribbon-right {
position: relative;
/*background: linear-gradient(to bottom, #fff 0, #f8f8f8 100%) repeat-x;*/
background: white;
height: 100%;
min-height: 52px;
border: 1px solid transparent;
}
div.ribbon-top-back {
z-index: -10;
border-color: transparent transparent #f0f0f0 transparent;
border-style: solid;
border-width: 13px;
height: 0px;
width: 0px;
position: relative;
left: -1px;
top: -27px;
}
div.ribbon-right > div.ribbon-top-back {
left: -14px;
}
/* Temporary coloring to make things obvious */
body {
background-color: blueviolet;
}
.container {
background-color: #c0a16b;
}
html, body, div.container {
height: 100%;
}
A general idea of the ribbon layout:
<div class="row">
<div class="ribbon">
<div class="ribbon-left">
<div class="ribbon-top-back"></div>
</div>
<div class="ribbon-content">
<!-- bootstrap navbar -->
</div>
<div class="ribbon-right">
<div class="ribbon-top-back"></div>
</div>
</div>
</div>
How can I make the element align correctly?
So after some testing, it became apparent that if I wanted the element to be in-line, I would need to declare it before the navbar (seeing as it's relative positioning but float: right):
<div class="row">
<div class="ribbon">
<div class="ribbon-left">
<div class="ribbon-top-back"></div>
</div>
<div class="ribbon-right">
<div class="ribbon-top-back"></div>
</div>
<div class="ribbon-content">
<!-- bootstrap navbar -->
</div>
</div>
</div>
I am using the Semantic UI.
and here is my HTML JSFiddle
:
<div class="ui items" id="test">
<div class="item">
<div class="content">
<div class="meta">two days ago</div>
<div class="name">hello</div>
<div class="extra">ten pages</div>
<p class="description">I am a pythoner</p>
</div>
</div>
</div>
And the CSS:
#test{
height:100px;
}
But it seems that CSS does't work. I can't change the height.
where did these go wrong?
You SemanticUI.css contains some base theming which determines the height of the .item class.
.ui.items>.row>.item, .ui.items>.item {
display: block;
float: left;
position: relative;
top: 0;
width: 316px;
min-height: 375px; /* here */
margin: 0 .5em 2.5em;
padding: 0;
background-color: #FFF;
line-height: 1.2;
font-size: 1em;
-webkit-box-shadow: 0 0 0 1px rgba(0,0,0,.1);
box-shadow: 0 0 0 1px rgba(0,0,0,.1);
border-bottom: .2em solid rgba(0,0,0,.2);
border-radius: .33em;
-webkit-transition: -webkit-box-shadow .2s ease;
transition: box-shadow .2s ease;
padding: .5em;
}
You will need to change or delete that property.