I have been trying to create a button in CSS that appears to look "pushed down" on :active, to do this, I added 2px to padding-top and subtracted 2px from padding-bottom. However, this seems to add a margin to other elements, though I cannot figure out why.
I'm sure the solution is a simple one to experienced CSS-users.
http://jsfiddle.net/hTTWq/
You are using inline-block on the buttons who's default alignment is 'baseline`.
Try changing this by adding this to your buttton CSS
vertical-align: top; /* or middle or bottom */
JSfiddle Demo
Many ways to do this, but to move the whole button (and not just the text), you could do something like this, which alters margin-top rather than padding:
*:active, *:focus {
outline: none;
}
button {
display: inline-block;
margin: 0;
border: 0;
padding: 8px 16px;
border-radius: 4px;
background-color: #a9a9a9;
color: #fff;
overflow: hidden;
transition: padding-top 100ms linear, padding-bottom 100ms linear, box-shadow 100ms linear, -webkit-filter 100ms linear;
vertical-align: top;
}
button.suggested {
background-color: #0074d9;
}
button:active {
-webkit-filter: brightness(0.5);
margin-top: 2px;
box-shadow: 0 2px rgba(0, 0, 0, 0.5) inset;
vertical-align: bottom;
}
Related
I would like inner div to fill the outer div. I was told to use a negative padding on the child, which sounds logical but doesn't work in my case. I believe this is due to the transitions that I am using on the parent and child divs.
I have the child to go from transparent to not transparent on a hover. I have the child's background image transitioning from the parent's background image. I want to add padding to the parent so that I can customize the height of the div, however when I do, the child doesn't fill the parent. When I add a negative margin to the child, there is no effect.
.outer{
font-size: 2em;
border: 2px solid #898080;
margin-bottom: 40px;
border-radius: 20px;
text-shadow: 5px 5px 5px #000000;
position: relative;
display: inline-block;
transition: all 1s ease-in-out;
background-color: black;
padding: 30px 0px 30px 0px;
}
/* Scale up the box */
.outer:hover {
color: white;
border: 2px solid #d8e6ee;
transform: scale(1.1, 1.1);
transition: background .5 ease;
opacity: 1;
}
#inner{
zoom: 1.0;
border-radius: 17px;
text-shadow: 5px 5px 5px #000000;
background-color: red;
opacity: 0;
-webkit-transition: opacity 1s linear;
-moz-transition: opacity 1s linear;
transition: opacity 1s linear;
}
#inner:hover{
opacity: 1;
}
<div class="outer">
<div id="inner">Hello World</div>
</div>
Ok, so you are trying to set the dimensions of an element trough the use of padding, but you want the content of that element to ignore the padding. I guess, if you put it that way it becomes quite obvious that padding is not the right tool here. All you have to do is set the dimensions of the child, and by definition the parent will follow.
In code that would mean, move the padding from the .outer to the #inner.
EDIT: Hoping someone will see this one. I'm stuck and have tried several things since posting it, but to no avail.
I'm trying to display a textarea with a border shadow. For some weird reason, while other regular text input boxes on the page are displaying their inner shadows correctly, textareas do not show any inner shadows at all. How do I force textarea to display the shadow as the other input boxes do?
Here is the HTML I'm using.
<textarea class="form-control upladfieldset notes-field" rows="6"></textarea>
Note that when I remove the entire class attribute of
class="form-control upladfieldset notes-field"
the inner border shadow appears, but then of course all my other styling is gone which is not ideal. So I also tried commenting out individual lines of CSS in those classes to see which line is causing a conflict, but the only thing that gets the inner shadow to appear is if I remove the class attribute declaration altogether.
Here is the CSS I'm using.
.form-control
{
color: #34495e;
border-color: transparent;
border: none !important;
border-bottom-width: 0px;
border-bottom: none;
font-size: 16px;
line-height: 1.467;
padding: 8px 12px 8px 66px;
height: 54px;
-webkit-appearance: none;
-webkit-box-shadow: none;
box-shadow: none;
-webkit-transition: border .25s linear, color .25s linear, background-color .25s linear;
transition: border .25s linear, color .25s linear, background-color .25s linear;
background-repeat: no-repeat;
}
.uploadfieldset
{
border: none;
border-radius: 0;
padding: 0;
}
.notes-field
{
background-clip: border-box;
background-size: contain
border-radius:0;
height: 54px;
width: 680px;
font-family: 'gotham_htfbook';
font-size: 18px;
color: #000000;
text-transform: none;
text-align: left;
font-weight: normal;
}
input[type=text], textarea
{
-webkit-appearance: none;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
box-shadow: 0 0 5px rgba(89, 89, 89, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgba(204, 204, 204, 1);
}
input[type=text]:focus, textarea:focus
{
box-shadow: 0 0 5px rgba(89, 89, 89, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgba(204, 204, 204, 1);
}
Well... you have a lot of things going on here, but I believe I may have achieved your desired result (I'm not 100% sure I understand what you want, but I'm operating under the assumption that you want your textarea to include a border and box-shadow identical to your input field). I believe the main problem here is mainly to do with hierarchy fundamentals. Because of that, I feel like there's a few things that should be said before we tackle our actual code here. In principle, you should have more general rules towards the top of your stylesheet and more specific ones as you go down. Resets (the raw elements like textarea, input, etc.) should be at the top--or at the very least, above the classes you wish to apply to those elements.
Also, I strongly encourage you to avoid using !imporant. If you find yourself needing to use !imporant, that generally means that your real problem lies elsewhere. It shows that you're now trying to work against the natural flow of CSS to force it to cover up something else. And what happens when you need to override that rule? You're going to have to write an even more specific rule, and the whole thing can very quickly turn into a mess.
So with that said, for the sake of familiarity, I have taken your code and commented out the problematic lines and have included explanations as to why they're preventing you from achieving what you want.
.form-control
{
color: #34495e;
/*border-color: transparent; Because of this, even if you had a border, you wouldn't be able to see it (assuming you didn't override it later). */
/*border: none !important; 1. Use of !important. 2. Your border isn't showing because this is explicitly telling it not to. */
/*border-bottom-width: 0px; You're getting rid of the bottom border. */
/*border-bottom: none; You're getting rid of the bottom border. */
font-size: 16px;
line-height: 1.467;
padding: 8px 12px 8px 66px;
height: 54px;
-webkit-appearance: none;
/*-webkit-box-shadow: none; Explicitly telling it not to have a box-shadow */
/* box-shadow: none; Explicitly telling it not to have a box-shadow */
-webkit-transition: border .25s linear, color .25s linear, background-color .25s linear;
transition: border .25s linear, color .25s linear, background-color .25s linear;
background-repeat: no-repeat;
}
.uploadfieldset
{
/*border: none; Explicitly telling it not to have a border */
border-radius: 0;
padding: 0;
}
.notes-field
{
background-clip: border-box;
background-size: contain
border-radius:0;
height: 54px;
width: 680px;
font-family: 'gotham_htfbook';
font-size: 18px;
color: #000000;
text-transform: none;
text-align: left;
font-weight: normal;
}
input[type=text], textarea
{
-webkit-appearance: none;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
box-shadow: 0 0 5px rgba(89, 89, 89, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgba(204, 204, 204, 1);
}
input[type=text]:focus, textarea:focus
{
box-shadow: 0 0 5px rgba(89, 89, 89, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgba(204, 204, 204, 1);
}
However, here, I have re-ordered some of your lines in order to implement some of the principles I mentioned earlier. Because I don't know what you're going to use this for, I tried not to tamper with things when it was not directly necessary. I also did not delete any of your lines. Instead, I simply commented them out so you can follow along and see what I actually did. You can delete them yourself if you so wish to.
input[type=text], textarea /* Moved to the top of your stylesheet */
{
-webkit-appearance: none;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
box-shadow: 0 0 5px rgba(89, 89, 89, 1); /* Reminder: You're defining your box-shadow here */
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgba(204, 204, 204, 1); /* Reminder: You're defining your border here */
}
input[type=text]:focus, textarea:focus /* Moved to the top of your stylesheet */
{
/*box-shadow: 0 0 5px rgba(89, 89, 89, 1); No need to redefine in :focus. It will be in inherited. */
padding: 3px 0px 3px 3px; /* See: padding in .uploadfieldset (below) */
/*margin: 5px 1px 3px 0px; No need to redefine in :focus. It will be in inherited. */
/*border: 1px solid rgba(204, 204, 204, 1); No need to redefine in :focus. It will be in inherited. */
}
.form-control
{
color: #34495e;
/*border-color: transparent; This will hide previously defined border. */
/*border: none !important; This will override previously defined border. Remember, don't use !important.*/
/*border-bottom-width: 0px; This will get rid of the bottom border. */
/*border-bottom: none; This will get rid of the bottom border. */
font-size: 16px;
line-height: 1.467;
padding: 8px 12px 8px 66px;
height: 54px;
-webkit-appearance: none;
/*-webkit-box-shadow: none; This will override previously defined box-shadows. */
/* box-shadow: none; This will override previously defined box-shadows. */
-webkit-transition: border .25s linear, color .25s linear, background-color .25s linear;
transition: border .25s linear, color .25s linear, background-color .25s linear;
background-repeat: no-repeat;
}
.uploadfieldset
{
/*border: none; This will override previously defined borders. */
border-radius: 0;
padding: 0; /* This tells your text field to not have any padding. However, when you click on your textarea, the padding set by textarea:focus will override THIS. */
}
.notes-field
{
background-clip: border-box;
background-size: contain
border-radius:0;
height: 54px;
width: 680px;
font-family: 'gotham_htfbook';
font-size: 18px;
color: #000000;
text-transform: none;
text-align: left;
font-weight: normal;
}
If you try either of those with this markup:
<textarea class="form-control upladfieldset notes-field" rows="6"></textarea>
<input type="text">
You can see that both fields are stylized likewise. I hope this helps.
I'm trying to do a simple animation using only css. The idea is that when I hover a social icon it will seem like it's lifting up. I managed to do that but now i want to use "border" to seem like it's the icon's shadow. I reduced the thickness of the border on hover but I wanted to make it seem more realistic and somehow reduce the width of the border when hovering over. Any ideas?
Here is my fiddle: http://jsfiddle.net/Iulius90/sck4Lzz9/
html
<div>
<img src="http://fc05.deviantart.net/fs70/f/2012/204/7/b/logo_skype_by_jackal807-d58ctxc.png">
</div>
css
div {
width:200px;
height:200px;
background-color:tomato;
}
img {
width: 100px;
height:100px;
margin: 50px;
border-bottom: 3px solid #222;
transition: all 0.35s ease;
}
div img:hover {
margin-top: 22px;
padding-bottom:28px;
border-bottom: 1px solid #222;
transition: all 0.35s ease;
cursor: pointer;
}
You can simply use a solid linear gradient as a background image, and manipulate its dimensions upon hover. Note: You might want to use vendor prefixes to generate CSS gradients that are cross browser compatible.
img {
background-image: linear-gradient(to top, rgba(0,0,0,.5) 0%, rgba(0,0,0,.5) 100%);
background-position: center bottom;
background-repeat: no-repeat;
background-size: 100% 3px;
width: 100px;
height:100px;
margin: 50px;
transition: all 0.35s ease;
}
div img:hover {
background-size: 50% 1px;
margin-top: 22px;
padding-bottom:28px;
transition: all 0.35s ease;
cursor: pointer;
}
http://jsfiddle.net/teddyrised/sck4Lzz9/26/
This question already has answers here:
Transitions on the CSS display property
(37 answers)
Closed 6 years ago.
I have been trying to use css to show a Hidden Div fade in whenever I hover its parent element.
So far all I have managed to do was to get the hidden div to show, but there are no easing transitions what so ever.
Here is my Code on JSfiddle http://jsfiddle.net/9dsGP/
Here is my Code:
HTML:
<div id="header">
<div id="button">This is a Button
<div class="content">
This is the Hidden Div
</div>
</div>
</div>
CSS:
#header #button {width:200px; background:#eee}
#header #button:hover > .content {display:block; opacity:1;}
#header #button .content:hover { display:block;}
#header #button .content {
-webkit-transition: all .3s ease .15s;
-moz-transition: all .3s ease .15s;
-o-transition: all .3s ease .15s;
-ms-transition: all .3s ease .15s;
transition: all .3s ease .15s;
opacity:0;
clear: both;
display: none;
top: -1px;
left:-160px;
padding: 8px;
min-height: 150px;
border-top: 1px solid #EEEEEE;
border-left: 1px solid #EEEEEE;
border-right: 1px solid #EEEEEE;
border-bottom: 1px solid #EEEEEE;
-webkit-border-radius: 0px 7px 7px 7px;
-moz-border-radius: 0px 7px 7px 7px;
-khtml-border-radius: 0px 7px 7px 7px;
border-radius: 0px 7px 7px 7px;
-webkit-box-shadow: 0px 2px 2px #DDDDDD;
-moz-box-shadow: 0px 2px 2px #DDDDDD;
box-shadow: 0px 2px 2px #DDDDDD;
background: #FFF;
}
Any clue as to what Im doing wrong? Just trying to get a smooth effect for the hidden content when I hover over the button. Thanks in advance!
display:none; removes a block from the page as if it were never there.
A block cannot be partially displayed; it’s either there or it’s not.
The same is true for visibility; you can’t expect a block to be half
hidden which, by definition, would be visible! Fortunately, you can
use opacity for fading effects instead.
- reference
As an alternatiive CSS solution, you could play with opacity, height and padding properties to achieve the desirable effect:
#header #button:hover > .content {
opacity:1;
height: 150px;
padding: 8px;
}
#header #button .content {
opacity:0;
height: 0;
padding: 0 8px;
overflow: hidden;
transition: all .3s ease .15s;
}
(Vendor prefixes omitted due to brevity.)
Here is a working demo. Also here is a similar topic on SO.
#header #button {
width:200px;
background:#ddd;
transition: border-radius .3s ease .15s;
}
#header #button:hover, #header #button > .content {
border-radius: 0px 0px 7px 7px;
}
#header #button:hover > .content {
opacity: 1;
height: 150px;
padding: 8px;
}
#header #button > .content {
opacity:0;
clear: both;
height: 0;
padding: 0 8px;
overflow: hidden;
-webkit-transition: all .3s ease .15s;
-moz-transition: all .3s ease .15s;
-o-transition: all .3s ease .15s;
-ms-transition: all .3s ease .15s;
transition: all .3s ease .15s;
border: 1px solid #ddd;
-webkit-box-shadow: 0px 2px 2px #ddd;
-moz-box-shadow: 0px 2px 2px #ddd;
box-shadow: 0px 2px 2px #ddd;
background: #FFF;
}
#button > span { display: inline-block; padding: .5em 1em }
<div id="header">
<div id="button"> <span>This is a Button</span>
<div class="content">
This is the Hidden Div
</div>
</div>
</div>
You cannot use height: 0 and height: auto to transition the height. auto is always relative and cannot be transitioned towards. You could however use max-height: 0 and transition that to max-height: 9999px for example.
Sorry I couldn't comment, my rep isn't high enough...
I found a solution while tinkering around.
People who directly wanna see the results:
With click: https://jsfiddle.net/dt52jazg/
With Hover: https://jsfiddle.net/7gkufLsh/1/
Below is the code:
HTML
<ul class="list">
<li>Hey</li>
<li>This</li>
<li>is</li>
<li>just</li>
<li>a</li>
<li>test</li>
</ul>
<button class="click-me">
Click me
</button>
CSS
.list li {
min-height: 0;
max-height: 0;
opacity: 0;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.active li {
min-height: 20px;
opacity: 1;
}
JS
(function() {
$('.click-me').on('click', function() {
$('.list').toggleClass('active');
});
})();
Please let me know whether there is any problem with this solution 'coz I feel there would be no restriction of max-height with this solution.
I faced the problem with display:none
I have several horizontal bars with transition effects but I wanted to show only part of that container and fold the rest while maintaining the effects. I reproduced a small demo here
The obvious was to wrap those hidden animated bars in a div then toggle that element's height and opacity
.hide{
opacity: 0;
height: 0;
}
.bars-wrapper.expanded > .hide{
opacity: 1;
height: auto;
}
The animation works well but the issue was that these hidden bars were still consuming space on my page and overlapping other elements
so adding display:none to the hidden wrapper .hide solves the margin issue but not the transition, neither applying display:none or height:0;opacity:0 works on the children elements.
So my final workaround was to give those hidden bars a negative and absolute position and it worked well with CSS transitions.
Jsfiddle
Made some changes, but I think I got the effect you want using visibility. http://jsfiddle.net/9dsGP/49/
I also made these changes:
position: absolute; /* so it doesn't expand the button background */
top: calc(1em + 8px); /* so it's under the "button" */
left:8px; /* so it's shifted by padding-left */
width: 182px; /* so it fits nicely under the button, width - padding-left - padding-right - border-left-width - border-right-width, 200 - 8 - 8 - 1 - 1 = 182 */
Alternatively, you could put .content as a sibling of .button, but I didn't make an example for this.
max-height
.PrimaryNav-container {
...
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
...
}
.PrimaryNav.PrimaryNav--isOpen .PrimaryNav-container {
max-height: 300px;
}
https://www.codehive.io/boards/bUoLvRg
When you need to toggle an element away, and you don't need to animate the margin property. You could try margin-top: -999999em. Just don't transition all.
I styled a link so that when you hover it, there will appear a border on the top; and when you hover off the border will disappear with a transition. The border slides in instead of fading in when you hover over it and off. I want the border to fade in instead of slide. How can I do this? Here is a JsFiddle
HTML
<div>Text</div>
CSS
div {
line-height: 50px;
width: 100px;
text-align: center;
cursor: pointer;
transition: border .2s ease-in-out;
-webkit-transition: border .2s ease-in-out;
-moz-transition: border .2s ease-in-out;
}
div:hover {
border-top: 3px solid #000;
}
html, body {
margin: 0;
padding: 0;
}
If you want to animate the color, animate the color, not the entire border. You're now also animating it from 0 pixels to 3 pixels, so of course it slides in. You should just give it a default transparent border instead.
div {
line-height: 50px;
width: 100px;
text-align: center;
cursor: pointer;
transition: border-color .5s ease-in-out;
border-top: 3px solid transparent;
}
div:hover {
border-top-color: #000;
}
Sample on JSfiddle
As a sidenote: -moz-transition is obsolete nowadays, since FF17 or so Mozilla supports the CSS Transitions module without prefix.
Update dec 2014: as I noticed this answer is still being viewed and upvoted frequently, please note that transition is no longer prefixed in any current or recently superseded browsers.
In this case - you are going to need to have a border to begin with as well. Make it transparent in the first state. This way it will not "grow" into place... and the color will just fade as it changes.
http://jsfiddle.net/kLnQL/11/
div {
border: 3px solid transparent;
}
div:hover {
border: 3px solid #f06;
}