I have a message space with the response field nice and small at the bottom. When the user clicks in, it expands. However, when focused, if I then go to click my button, it looses focus - as expected, but the button isn't triggered, I have to click it again. How can I best resolve this?
.wrap {
align-items: center;
display: flex;
justify-content: flex-end;
}
textarea {
height: 40px;
width: 100%;
transition: height .2s ease;
}
textarea:focus {
height: 150px;
}
.fancy-button {
background-color: red;
cursor: pointer;
margin-left: 20px;
height: 30px;
width: 30px;
}
<div class="wrap">
<textarea></textarea>
<div class="fancy-button" onclick="alert('click');">
</div>
I think the issue is that when you click, the button is not technically in this place but only visually. If you add a wrapper that cover all the space you may be able to catch the click from the first time.
While you are having the fast transition the browser is calculating and updating the position of the button; thus your click is outside the area of the button.
You may also notice in this solution that if you click below the button the alert may not be triggered because of the same reasons. The wrapper is having its height decreasing rapidly and the click may be outside.
.wrap {
display: flex;
}
textarea {
height: 40px;
width: 100%;
transition: height .2s ease;
}
textarea:focus {
height: 150px;
}
.wrap > div {
display: flex;
align-items:center;
}
.fancy-button {
background-color: red;
cursor: pointer;
margin-left: 20px;
height: 30px;
width: 30px;
}
<div class="wrap">
<textarea></textarea>
<div onclick="alert('click');">
<div class="fancy-button" >
</div>
</div>
</div>
And if you only decrease the transition time you may also be able to catch the click the first time:
.wrap {
display: flex;
align-items: center;
}
textarea {
height: 40px;
width: 100%;
transition: height 2s ease;
}
textarea:focus {
height: 150px;
}
.fancy-button {
background-color: red;
cursor: pointer;
margin-left: 20px;
height: 30px;
width: 30px;
}
<div class="wrap">
<textarea></textarea>
<div onclick="alert('click');" class="fancy-button">
</div>
</div>
You can also keep the duration and add a delay:
.wrap {
display: flex;
align-items: center;
}
textarea {
height: 40px;
width: 100%;
transition: height .2s ease;
transition-delay:0.1s;
}
textarea:focus {
height: 150px;
transition-delay:0s;
}
.fancy-button {
background-color: red;
cursor: pointer;
margin-left: 20px;
height: 30px;
width: 30px;
}
<div class="wrap">
<textarea></textarea>
<div onclick="alert('click');" class="fancy-button">
</div>
</div>
I don't know if this for you can works, because I don't know your needs, but if you use hover instead of focus the button is free to be clicked
.wrap {
align-items: center;
display: flex;
justify-content: flex-end;
}
textarea {
height: 40px;
width: 100%;
transition: height .2s ease;
}
textarea:hover {
height: 150px;
}
.fancy-button {
background-color: red;
cursor: pointer;
margin-left: 20px;
height: 30px;
width: 30px;
}
<div class="wrap">
<textarea></textarea>
<a class="fancy-button" onclick="alert('click');"><a/>
</div>
Related
I created a custom 'searchbox'. The 'searchbox' actually built by a div and input text inside it.
Later on I will add a 'search' icon on the left and 'clear' button on the right.
The issue is, the input inside the div already sized based on it's container and when I'm focusing the input text, I couldn't find a way to expand the parent div (instead of the input itself). It's important the div will expand so the icons and buttons I will later add - will expand with the input.
Couldn't find a way doing it with CSS only (without JS).
Will appreciate your assistance!
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
.App {
width: 100%;
height: 200px;
background-color: tan;
}
.fieldcontainer {
display: flex;
padding-left: 8px;
background-color: #CCCCCC;
border-color: grey;
width: 300px;
min-height: 35px;
align-items: center;
justify-content: space-between;
border-radius: 8px;
cursor: default;
transition: 'background-color' 0.4s;
}
.fieldcontainer:hover {
background-color: #C3C3C3;
}
.searchfield {
background-color: inherit;
font-size: 1em;
border: 0;
flex-grow: 8;
transition: all 0.4s linear;
}
.searchfield:focus {
outline: none;
width: 100%;
}
</style>
</head>
<body>
<div class="App">
<div class="fieldcontainer">
<input class="searchfield" type="text" placeholder="search" />
</div>
</div>
</body>
</html>
Use focus-within (https://developer.mozilla.org/fr/docs/Web/CSS/:focus-within)
* {
box-sizing: border-box;
}
.App {
height: 200px;
background-color: tan;
}
.fieldcontainer {
display: flex;
padding-left: 8px;
background-color: #CCCCCC;
border-color: grey;
width: 300px;
min-height: 35px;
align-items: center;
justify-content: space-between;
border-radius: 8px;
cursor: default;
transition: 0.4s;
}
.fieldcontainer:hover {
background-color: #C3C3C3;
}
.searchfield {
background-color: inherit;
font-size: 1em;
border: 0;
flex-grow: 8;
transition: all 0.4s linear;
outline:none;
}
.fieldcontainer:focus-within {
width: 100%;
}
<div class="App">
<div class="fieldcontainer">
<input class="searchfield" type="text" placeholder="search" />
</div>
</div>
I have a block called case-card which consists of a child div called case-card__wrapper that houses text.
On case-card hover, I want the case-card__wrapper to move up slightly. Not in one action, but as transition.
I feel like I have the general idea, but unsure on how to get the transition to work? At the moment, it just phases from one spot to another:
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
position: absolute;
transition: 0.5s;
/*top: 0; Don't want to add this because I want the text to be centered in the div and rather not define a number since the div heights may vary */
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
top: 150px;
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>
I'm trying to do this just via CSS. Any ideas?
If you cannot set initial value simply use transfrom. You can also remove position:absolute
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
transition: 0.5s;
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
transform:translateY(-100%);
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>
The problem
I am trying to create a box that can expand with an icon an text inside of it. I want the icon to be always visible and not move and the to pop in the bow when hovering over it. However when I load in the text it messes up the layout of the icon. See Fiddle.
It would be best if the icon could stay in place without moving at all. How can I best achieve this?
Here is the code:
.box {
width: 60px;
height: 36px;
background-color: #96ffd1;
}
.box:hover {
width: 300px;
-webkit-transition: width 0.5s;
/* For Safari 3.1 to 6.0 */
transition: width 0.5s;
}
.box>i {
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
}
span {
height: 36px;
vertical-align: middle;
position: relative;
display: none;
}
.box:hover span {
display: table-cell;
white-space: nowrap;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class='box'>
<i class="glyphicon glyphicon-remove"></i>
<span>Display when expanded</span>
</div>
line-height = height of icon. (To center the icon)
padding-left equal to width of icon.
.box {
width: 60px;
height: 36px;
background-color: #96ffd1;
}
.box:hover {
width: 300px;
-webkit-transition: width 0.5s;
/* For Safari 3.1 to 6.0 */
transition: width 0.5s;
}
.box>i {
position: absolute;
line-height: 36px;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
}
span {
height: 36px;
padding-left: 60px;
vertical-align: middle;
position: relative;
display: none;
}
.box:hover span {
display: table-cell;
white-space: nowrap;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class='box'>
<i class="glyphicon glyphicon-remove"></i>
<span>Display when expanded</span>
</div>
I am very new to CSS as I just started learning it. I've been trying to develop a website as creating a product is the best way for me to learn.
I've created a button that works okay but when hovered the icon pops under the button for a second and then comes back up. I would like to fix that but I'm not sure how.
I've written this;
.sidebar-wrapper {
height: 83%;
width: 110px;
position: absolute;
}
.sidebar-btn {
background-color: rgb(33, 33, 33, 0.5);
height: 8%;
margin-bottom: 35%;
animation: 1s ease-out 0s 1 slideInFromLeft;
width: 110px;
transition: width 0.5s ease;
}
.sidebar-btn img {
float: left;
margin-left: 25px;
margin-top: 8px;
width: 50px;
}
.sidebar-btn label {
font-family: 'Monoton', cursive;
text-align: center;
color: white;
line-height: 60px;
display: none;
font-size: 19;
}
.sidebar-btn:hover {
width: 250px;
}
.sidebar-btn:hover label {
display: inline;
}
.sidebar-clr {
width: 7px;
height: 100%;
float: right;
}
<div class="sidebar-wrapper">
<div class="sidebar-btn">
<label> Profile </label>
<div class="sidebar-clr bg-blue"></div>
<img class="sidebar-img" src="http://via.placeholder.com/50x50/ff0000" />
</div>
</div>
Move your label to after your image, as all the inline styling and scaling means that as it display the label, the image gets pushed out of the way (because it is after your label) and then things snap again when they recalculate themselves the next draw frame. But I think in general there should be better ways to do this, but I am unsure what you are trying to accomplish - the label doesn't actually display in your snippet, it just turns itself to display as block, but the area remains empty, so... Pretty sure a mix of absolute and relative positioning or flexbox, or background-size transition woudl probably work better for your purpose, but I can't say.
.sidebar-wrapper {
height: 83%;
width: 110px;
position: absolute;
}
.sidebar-btn {
background-color: rgb(33, 33, 33, 0.5);
height: 8%;
margin-bottom: 35%;
animation: 1s ease-out 0s 1 slideInFromLeft;
width: 110px;
transition: width 0.5s ease;
}
.sidebar-btn img {
float: left;
margin-left: 25px;
margin-top: 8px;
width: 50px;
}
.sidebar-btn label {
font-family: 'Monoton', cursive;
text-align: center;
color: white;
line-height: 60px;
display: none;
font-size: 19;
}
.sidebar-btn:hover {
width: 250px;
}
.sidebar-btn:hover label {
display: inline;
}
.sidebar-clr {
width: 7px;
height: 100%;
float: right;
}
<div class="sidebar-wrapper">
<div class="sidebar-btn">
<img class="sidebar-img" src="http://via.placeholder.com/50x50/ff0000" />
<label> Profile </label>
<div class="sidebar-clr bg-blue"></div>
</div>
</div>
I have the following CSS and HTML:
body { background-color: #c0c0c0; }
.title-bar, { background-color: #999; color: white; float: left; overflow: hidden; }
.title-bar {
border-bottom: 1px solid white;
height: 128px;
width: 100%;
}
.logo, .user-info { box-sizing: content-box; height: 100%; width: 128px; }
.logo{
align-items: center;
background-color: #369;
border-right: 1px solid white;
display: flex;
float: left;
font-size: 2em;
font-kerning: none;
justify-content: center;
}
.user-info {
align-items: center;
border-left: 1px solid white;
display: flex;
float: right;
justify-content: space-between;
flex-flow: column nowrap;
}
.user-info .circle {
border: 2px solid #369;
border-radius: 50%;
display: inline-block;
flex: 0 0 auto;
height: 32px;
margin: 8px 8px;
overflow: hidden;
transition: border 0.15s ease-out;
width: 32px;
}
.user-info .circle:hover { border-width: 4px; }
.user-info .container {
border-top: 1px solid white;
display: flex;
justify-content: center;
margin-top: 6px;width: 100%;
}
.hor-nav { background-color: #404040; }
.option { display: inline-block; position: relative; }
.hor-nav .option:hover {background-color: #369; }
.option a {
color: white;
display: inline-block;
font-size: 1em;
padding: 14px;
text-align: center;
transition: background-color 0.15s ease-out;
}
.option .dropdown { display: none; position: absolute; }
.option:hover .dropdown{ display: block; }
.dropdown a {
display: block;
text-align: left;
width: 100%;
}
<div class="title-bar">
<a class="logo" href="#">
</a>
<div class="user-info">
<span>User name</span>
<div class="container">
</div>
</div>
<div class="hor-nav">
<div class="option">
OPTION 1
<div class="dropdown">
ITEM 1
</div>
</div>
</div>
</div>
as you can see, the hor-nav bar's color spills onto the user-info area.
I have researched this and found that if I set overflow-x: hidden; it will not do this (see this article).
I have tried that and it is true - the nav bar does not spill into the user-info but, when you hover over one of the nav bar options, the dropdown does not come down but instead the vert-nav gives you a scroll bar (see this jsfiddle).
Additionally, if you do overflow-y: hidden; there is no scroll bar at all.
I am trying to get it so that the background-color of the hor-nav does not spill into other div's, but also allows the dropdown to be activated and work
thank you.
The easiest way to to this with least code change is to just give the user-info area a background color. Since the hor-nav section is lower on the z-index this will give the visual affect you want although the bar will still be under the user-info section it won't appear to be and the drop down will funtion as it does now.
Per your inquiry, you could do this another way by using percentage based widths for all 3 elements so they don't overlap eachother. Please see this fiddle for code change (note I change the markup order slightly, widths, and added box sizing css property)
The way I see it, you have 3 options
You can try adding margin-left/right to the hor-nav.
.hor-nav {
margin: auto 128px;
}
Another option is to set a certain width to the .hor-nav. Or practically cut the width of it.
.hor-nav {
width: calc(100% - 128px);
}
And third, is to add a background color to the .user-info