Search input field like TripAdvisor functionality - html

I am trying to achieve a similar search form like tripadvisors (at least UI and Front Design speaking) but i have till now a few issues.
On the first photo is how is my search bar with the class name for testing purposes "asdf".
so in the second picture we have the issue, the expandable part of the form being a bit wider than the input search field.
In the third pict if with have the issue if i try to assign the same width of the rest of the form with the input["text"] field of the search form.
Below my basic html and css code.
HTML
<div class="aboutUs">
<div class="textFlexContainer">
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">City</span>
<span class="heading-primary-sub">is where summer happens</span>
</h1>
<form class="search-box" action="/search">
<input class="asdf" type="search" placeholder="Explore City">
<div class="search-page">
<h3>Explore City</h3>
<ul class="search-menu-list">
<li>Our Daily Suggestions</li>
<li>Shopping</li>
<li>City Tours</li>
<li>Restaurants</li>
<li>Events</li>
<li>Things to do</li>
</ul>
<h3>Recently Reviewed</h3>
</div>
</form>
</div>
</div>
</div>
And CSS
.search-box{
display: block;
position: relative;
overflow: hidden;
z-index:15;
padding:2rem;
}
.asdf {
width: 80%;
padding:2rem;
border: none;
outline: none;
border-bottom:2px solid white;
margin-top:2.5rem;
font-size: inherit;
background-color: green;
color: #fff;
}
h3{
color:#fff;
margin-top:2rem;
}
.search-page {
height: fit-content;
background-color:green;
text-align: center;
padding:4rem 0;
transition: all 300ms ease-in-out;
display: none;
}
.search-page.visible {
display: block;
transition: all 300ms ease-in-out;
}
.search-page .search-menu-list{
display:flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.search-page .search-menu-list li{
list-style: none;
}
.search-page .search-menu-list li a:hover{
transform: translateY(-1rem);
}
.search-page .search-menu-list li a{
display: inline-block;
color:#fff;
padding:5px;
list-style: none;
text-decoration: none;
margin-right: 2.5rem;
transition: all 300ms ease-in-out;
border: solid 2px white;
border-radius: 1rem;
padding: 11px 13px 11px 14px;
margin: 10px;
}
.aboutUs{
display: grid;
background-image: linear-gradient(to right bottom, rgba(53, 170, 120, 0.8), rgba(20, 139, 102, 0.8)) ,url(../img/ch4.jpg);
background-size: cover;
background-position: center;
grid-column-start: 1;
grid-column-end: 13;
grid-row-start: 2;
grid-row-end: 3;
}
.textFlexContainer{
display:flex;
align-self: center;
}
.heading-primary {
color:#fff;
text-transform: uppercase;
}
.heading-primary-main{
display: block;
font-size: 6rem;
font-weight: 400;
letter-spacing: 3.5rem;
}
.heading-primary-sub {
display: block;
font-size: 2rem;
font-weight: 400;
letter-spacing: 1.8rem;
}
.text-box {
display: inline-block;
/* This content should just be in the normal flow of the page */
/*
position: absolute
top:30%;
left:50%;
transform: translate(-50% ,-50%);
*/
text-align: center;
/* Because we're using flexbox, we can center the content both horizontally and vertically
* using this declaration
*/
margin: auto;
}
Additionaly i would love if when i click on the search bar field and the form is expanding to not have the letters above the search bar to getting squeezed on the top.

Not entirely sure what you need here but here's a fix for image 3. Adding 2 lines of code to your .search-page fixes the alignment issue.
.search-page{
height: fit-content;
background-color:green;
width:80%;
text-align: center;
padding:4rem 0;
transition: all 300ms ease-in-out;
display: all;
}
The width sets it to line up with the size of the text input of the form. The margin: 0 auto; is a good way to quickly center elements in css.

I can't see the expandable part when I tested your code but have you tried changing the width to become small and then do a margin-left to move de expandable part and align it with the search?

Related

How can I block a buttons size, independently of its texts size?

so I am trying to do make my buttons like this.
I have tried creating containers for each button group and setting their padding to 50px 60px per say, but that did not work and they still stretch.
I have this:
Here is the code:
.container5 {
background-image: url("servicos.svg");
width: 100vw;
height: 100vh;
background-size: contain;
max-width: 100%;
left: 0;
}
.container5 .underline {
padding-top: 20px;
padding-bottom: 10px;
text-decoration: none;
border-bottom: 5px solid rgb(220,52,52);
}
.container5 h1 {
margin: auto;
line-height: 30px;
vertical-align: middle;
margin-left: 10vh;
weight: 950;
padding-top: 10vh;
font-family: 'Source Sans Pro', sans-serif;
font-size: 50px;
color: #000;
}
.container5 .btn-group {
left: 0;
margin-left: 5vw;
}
.container5 .btn-group button {
color: white;
background-color: #05031b;
font-family: Helvetica, Arial, Sans-Serif;
font-size: 15px;
text-decoration: none;
position: relative;
padding: 40px 35px;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
margin: 0 10px 0 0;
}
.container5 .btn-group .btn-group-ls {
font-size: 10px;
}
.container5 .btn-group2 {
left: 0;
margin-top: 3vh;
padding: 40px 30px;
}
.container5 .btn-group2 button {
color: white;
background-color: #05031b;
font-family: Helvetica, Arial, Sans-Serif;
font-size: 15px;
text-decoration: none;
position: relative;
margin: 0 10px 0 0;
left: 0;
}
.container5 .btn-group3 {
margin-top: 3vh;
}
.container5 .btn-group3 button {
color: white;
background-color: #05031b;
font-family: Helvetica, Arial, Sans-Serif;
font-size: 15px;
text-decoration: none;
position: relative;
padding: 40px 30px;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
margin: 0 10px 0 0;
}
<section class="container5" id="servicos">
<h1><u class="underline">Ser</u>viços </h1>
<div class="btn-group">
<button>VIDEO AULAS</button>
<button>
LIVES DIARIAS
<br>
<div class="btn-group-ls">
(ANALISE DO MERCADO)
</div>
</button>
<button>SALA DE SINAIS</button>
<div>
<div class="btn-group2">
<button>
LIVES SEMANAIS
<br>
<div class="btn-group-ls">
(RESTROSPECTIVA DO MERCADO)
</div>
</button>
<button>
LIVES SEMANAIS
<br>
<div class="btn-group-ls">
(PARA DUVIDAS)
<!-- Edit by tacoshy: Missing a div closing tag here -->
</button>
<button>MATERIAIS DIDATICOS</button>
<div>
<div class="btn-group3">
<button>FERRAMENTAS DE AUXILIO</button>
<button>
PREMIAÇÃO POR
<br>
DESEMPENHO (MENSAL)
</button>
<button>PROGRAMA DE TALENTOS</button>
<div>
<!-- Edit by tacoshy: as you see missing a lot closing tags -->
</section>
How do I make the buttons like those ones from the 1st image? Mine's sizes aren't stable and will change if the sentences are too big. Any ideas guys?
Thank you.
EDIT
I managed to align all of the buttons, however, any guess on how to level the buttons? Those who have more text are a few pixels lower than the rest.
You can apply width and height settings to them. To make them all the same height (regardless of the different text amount in them), also add a min-height setting that's at least as high as the highest button.
To center-align the texts in side them properly you can use display:flex; justify-content: center; align-items: center; on the buttons themselves.`

Header Responsiveness issue

I am trying to make the header for a site but i have a issue when it comes to responsiveness on height.
And something i am not sure that it can be resolved with media queries breakpoints as you can see from the photo below.
and here is how it looks on full window
Html
<body>
<header class="header">
<div class="logo-box"></div>
<img src="/img/logo-white.png" class="logo">
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">City</span>
<span class="heading-primary-sub">is where life happens</span>
</h1>
Discover our City
Discover our Tours
</div>
</header>
</body>
CSS
*{
margin:0;
padding:0;
box-sizing: border-box;
}
body{
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #777;
}
.header{
height:65vh;
background-image: linear-gradient(to right bottom, rgba(132,248,198 , 0.8), rgba(26,187,137,0.8)),url(../img/ch4.jpg);
background-size: cover;
background-position: top;
background-color:#4FD1A9;
}
.logo-box{
position: absolute;
top:40px;
left:40px;
}
.logo{
height:35px;
}
.heading-primary {
color:#fff;
text-transform: uppercase;
}
.heading-primary-main{
display: block;
font-size: 60px;
font-weight: 400;
letter-spacing: 35px;
}
.heading-primary-sub {
display: block;
font-size: 20px;
font-weight: 700;
letter-spacing: 15px;
margin-bottom: 60px;
}
.text-box {
display: inline-block;
position: absolute;
top:30%;
left:50%;
transform: translate(-50% ,-50%);
text-align: center;
}
.btn:link,
.btn:visited {
text-transform: uppercase;
text-decoration: none;
padding:15px 40px;
display: inline-block;
border-radius: 100px;
transition: all .2s;
margin: 5px;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 5px 10px rgb(0,0,0,.2);
}
.btn:active {
transform: translateY(-1px) ;
}
.btn-white {
background-color: #fff;
color:#777;
}
Should i make the entire header with CSS grid Layout breaking it its own parts?
My solution is somewhat opinionated, but I think that's unavoidable for this kind of question as there's so many different ways that it could be done.
I take the view that the height of elements should be determined only by their contents. If it was the case that users were comfortable scrolling horizontally as well as vertically through a website, then responsive design would be a complete non-issue. Responsive Design only becomes necessary because we prevent horizontal scrolling. We should not therefore concern ourselves with the height of content, only with the width.
Accordingly, I've removed the fixed height from the header as well as the absolute positioning from some of the elements and allowed the content to be laid out according to the natural flow. For desktop, I think this works fine.
A slightly different approach is required for narrower screens since on these you do begin to have issues with the width of the content. My solution here is to introduce a break-point at around the point when the content starts to get too wide for the viewport. Then I set all dimensions - font-sizes, margins, padding etc - to be a proportion of the current viewport width. A little math is required here to calculate the correct values, and I've also used CSS Custom Properties to make things a bit DRYer. In fact, there's only one declaration within the media query, and that's to set the base-unit from which all other values are calculated.
I've made notes in the CSS giving the reasoning for some of the changes I've made.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #777;
}
.header {
--unit: 1px;
/* removing this since the height of an element should be determined by content */
/* height:65vh;*/
background-image: linear-gradient(to right bottom, rgba(132, 248, 198, 0.8), rgba(26, 187, 137, 0.8)), url(https://s.abcnews.com/images/Business/gty_detroit_mi_130718_4x3_992.jpg);
background-size: cover;
background-position: center;
background-color: #4FD1A9;
/*
* flexbox is the best way to layout content along a single axis
* for various practical and performance reasons
*/
display: flex;
}
.text-box {
--padding-v: calc(var(--unit) * 50);
--padding-h: calc(var(--unit) * 10);
display: inline-block;
padding: var(--padding-v) var(--padding-h);
/* This content should just be in the normal flow of the page */
/*
position: absolute
top:30%;
left:50%;
transform: translate(-50% ,-50%);
*/
text-align: center;
/* Because we're using flexbox, we can center the content both horizontally and vertically
* using this declaration
*/
margin: auto;
}
.heading-primary {
color: #fff;
text-transform: uppercase;
}
.heading-primary-main {
--font-size: calc(var(--unit) * 60);
--letter-spacing: calc(var(--unit) * 35);
display: block;
font-size: var(--font-size);
font-weight: 400;
letter-spacing: var(--letter-spacing);
}
.heading-primary-sub {
--font-size: calc(var(--unit) * 20);
--letter-spacing: calc(var(--unit) * 15);
--margin-bottom: calc(var(--unit) * 60);
display: block;
font-size: var(--font-size);
font-weight: 700;
letter-spacing: var(--letter-spacing);
margin-bottom: var(--margin-bottom);
}
.btn {
--padding-v: calc(var(--unit) * 15);
--padding-h: calc(var(--unit) * 40);
--border-radius: calc(var(--unit) * 100);
--margin: calc(var(--unit) * 5);
--font-size: calc(var(--unit) * 16);
font-size: var(--font-size);
text-transform: uppercase;
text-decoration: none;
padding: var(--padding-v) var(--padding-h);
display: inline-block;
border-radius: var(--border-radius);
transition: all .2s;
margin: var(--margin);
background-color: #fff;
color: #777;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 5px 10px rgb(0, 0, 0, .2);
}
.btn:active {
transform: translateY(-1px);
}
/*
* This is around the point at which the text starts to wrap
*
* We take a fundamentally different approach to layout here. Now we want dimensions to
* scale with the width of the viewport so that it will look good at all sizes
*/
#media only screen and (max-width: 550px) {
.header {
--unit: calc(100vw / 550);
}
}
<html>
<head>
<link href="./header.css" rel="stylesheet" />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<header class="header">
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">City</span>
<span class="heading-primary-sub">is where life happens</span>
</h1>
Discover our City
Discover our Tours
</div>
</header>
</body>
</html>
Use media-quires to adjust your layout.
Problem occurs due to position:absolute
Reference
*{
margin:0;
padding:0;
box-sizing: border-box;
}
body{
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #777;
}
.header{
height:65vh;
background-image: linear-gradient(to right bottom, rgba(132,248,198 , 0.8), rgba(26,187,137,0.8)),url(../img/ch4.jpg);
background-size: cover;
background-position: top;
background-color:#4FD1A9;
}
.logo-box{
position: absolute;
top:40px;
left:40px;
}
.logo{
height:35px;
}
.heading-primary {
color:#fff;
text-transform: uppercase;
}
.heading-primary-main{
display: block;
font-size: 60px;
font-weight: 400;
letter-spacing: 35px;
}
.heading-primary-sub {
display: block;
font-size: 20px;
font-weight: 700;
letter-spacing: 15px;
margin-bottom: 60px;
}
.text-box {
display: inline-block;
position: absolute;
top:30%;
left:50%;
transform: translate(-50% ,-50%);
text-align: center;
}
.btn:link,
.btn:visited {
text-transform: uppercase;
text-decoration: none;
padding:15px 40px;
display: inline-block;
border-radius: 100px;
transition: all .2s;
margin: 5px;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 5px 10px rgb(0,0,0,.2);
}
.btn:active {
transform: translateY(-1px) ;
}
.btn-white {
background-color: #fff;
color:#777;
}
#media only screen and (max-width: 767px) {
.header {
height: 100vh;//adjust as per your req
}
.text-box {
display: block;
position: relative;
top: 0;
left: 0;
transform: none;
text-align: center;
height: 100%;
}
}
<body>
<header class="header">
<div class="logo-box"></div>
<img src="/img/logo-white.png" class="logo">
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">City</span>
<span class="heading-primary-sub">is where life happens</span>
</h1>
Discover our City
Discover our Tours
</div>
</header>
</body>

When screen is smaller, background for my flex boxes doesnt follow them when they go vertical row

Okay so, my issue is, do you see when its maximized, how it has the background behind the flexboxes? Now if you minimize the screen, since it's responsive, it will put it in 2 rows, but the background for the flexboxes is only in the 1st row its not on the 2nd/3rd and so, it's not behind every box, and thats my issue, would appreciate if someone could fix and explain, FIDDLE: https://jsfiddle.net/vu4eaw2t/ CODE(CHECK FIDDLE THO CODE IS JUST HERE SO THAT I CAN MAKE THIS POST):
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/design.js"></script>
</head>
<body style="margin: 0;">
<div class="navmenu">
<ul style="list-style: none;" class="nav">
<li>Home</li>
<li>Purchase</li>
</ul>
<ul style="list-style: none;" class="navb">
<li><a>Account</a></li>
</ul>
</div>
<div class="features">
<div class="featuresbox"><p class="FeatureTitle">Lorem Ipsum</p><p class="FeatureDescription">Lorem ipsum</p></div>
<div class="featuresbox"></div>
<div class="featuresbox"></div>
<div class="featuresbox"></div>
</div>
</body>
</html>
CSS ( AGAIN CHECK FIDDLE DON'T USE THIS FIDDLE WILL EXLPAIN YOU MY PROBLEM BUT MAKE SURE TO READ WHAT I SAID ABOVE ):
body {
font-family: 'Arial Narrow Bold', sans-serif;
background-color: rgba(84, 111, 219, 0.959);;
margin-bottom: 15px;
}
.navmenu {
width: 100%;
display: flex;
background-color: rgb(28, 109, 231);
justify-content: space-between;
}
.navb {
margin-right: 24px;
}
.navmenu > ul > li {
float: left;
color: rgb(255,255,255);
font-size: 18px;
margin-right: 50px;
}
.navmenu > ul > li:hover {
transform: scale(1.03);
color: rgb(119, 151, 240);
transition: 0.4s;
}
.navmenu > ul > li:not(:hover) {
transform: scale(1);
color: rgb(255,255,255);
transition: 0.4s;
}
.features {
width: 100%;
height: fit-content;
margin-top: 50px;
background-color: rgba(75, 105, 221, 0.651);
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.featuresbox {
height: 250px;
width: 270px;
border-radius: 4px;
background-color: rgba(45, 81, 224, 0.651);
float: left;
margin: 25px;
color: rgb(255,255,255);
}
.FeatureTitle {
font-size: 25px;
text-align: center;
}
.FeatureDescription {
text-align: center;
margin-left: 6px;
margin-right: 6px;
}
#media screen and (max-width: 950px) {
.navmenu > ul > li {
font-size: 15px;
margin-right: 33px;
}
.features {
height: 300px;
}
}
There is a tiny mistake there, where you just limited features div height with this media query:
#media screen and (max-width: 950px) {
.features {
height: 300px;
}
}
So whenever the screen reaches 950px or lowers the features div height will be 300px so it won't cover all the boxes there.
All you have to do, to fix it, is to remove the above media query style then you will be fine.

background-color doesn't work when using flexbox

I started using flexbox for my footers and now on all of my pages with forms the background-color is now the default white. Here is an example of one of my pages:
login.php
body {
background-color: #211e1e;
display: flex;
flex-direction: column;
height: 95vh;
}
h1 {
color: #99cc00;
text-align: center;
}
.content {
flex: 1 0 auto;
}
footer {
text-align: center;
font-weight: lighter;
color: #99cc00;
font-size: 10px;
flex-shrink: 0;
}
h3 {
position: absolute;
font-weight: bold;
color: #99cc00;
font-size: 15px;
width: 100%;
top: 91.5%;
}
.button {
background-color: #211e1e;
color: white;
font-size: 24px;
/*padding: 15px 50px;*/
transition-duration: .4s;
border: greenyellow;
width: 250px;
/* width of button */
height: 50px;
/* height of button */
}
.buttonColor:hover {
color: black;
background-color: greenyellow;
}
h1 {
text-align: center;
bottom: 25%;
}
content {
align-items: center;
justify-content: center;
}
.signin {
color: #99cc00;
margin: auto;
font-size: 24px;
}
.loginInput {
font-size: 24px;
}
.loginButton {
background-color: #211e1e;
color: white;
font-size: 24px;
padding: 10px 50px;
transition-duration: .4s;
border: greenyellow;
}
.loginButtonColor:hover {
color: black;
background-color: greenyellow;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="../../favicon.ico">
<meta charset="UTF-8">
<title>TapLovers</title>
<link rel="stylesheet" href="../background.css">
<link rel="stylesheet" href="login.css">
</head>
<body>
<div class=content>
<h1><img src="../../36x36-icon.png">apLovers</h1>
<form class="signin">
<input type="text" email="email" placeholder="Email" class="loginInput"><br>
<input type="text" password="password" placeholder="Password" class="loginInput"><br>
<input type="submit" name="submit" id="login" class="loginButton loginButtonColor" value="Login To TapLovers!" /><br><br>
<a href="../register/register.php">
<font color="#99cc00">Create a FREE TapLovers Account!</font>
</a>
</form>
</div>
<footer>
<h3><img src="../../favicon.ico">apLovers</h3><br>&copy 2018 TapLovers, All Rights Reserved
</footer>
</body>
</html>
Also I was trying to center my forms and my title using flexbox as well and I haven't gotten that working either. I'm not really sure what other details would be useful for this particular problem. If you need any more details just reply below and I'll answer them as they come out.
EDIT: The snippet that compiles on stack overflow shows my background just fine. What's more is if I use ctrl+shift+i on my page then the background works but if I just reload on my page then the background will turn white.
I did not see the issue with background fluctuations. I think it is a delay in the page load. I have added comments to help with the flexbox centering of items.
/*CSS reset of browser agent. Removes the horizontal scroll currently happening in page.*/
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: #211e1e;
display: flex;
flex-direction: column;
/* No need to restrict the height.
height: 95vh;*/
}
h1 {
color: #99cc00;
text-align: center;
}
.content {
flex: 1 0 auto;
/*make the content div flex so that the form can take the center alignment from flexbox properties. Add the centering here and avoid the margin: auto property */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
footer {
text-align: center;
font-weight: lighter;
color: #99cc00;
font-size: 10px;
flex-shrink: 0;
}
h3 {
position: absolute;
font-weight: bold;
color: #99cc00;
font-size: 15px;
width: 100%;
top: 91.5%;
}
.button {
background-color: #211e1e;
color: white;
font-size: 24px;
/*padding: 15px 50px;*/
transition-duration: .4s;
border: greenyellow;
width: 250px;
/* width of button */
height: 50px;
/* height of button */
}
.buttonColor:hover {
color: black;
background-color: greenyellow;
}
h1 {
text-align: center;
bottom: 25%;
}
/*Add flexbox style the inputs as blocks and remove <br> from HTML*/
.signin {
color: #99cc00;
font-size: 24px;
display: flex;
flex-direction: column;
}
.signin>* {
margin: 5px 0;
}
.loginInput {
font-size: 24px;
}
.loginButton {
background-color: #211e1e;
color: white;
font-size: 24px;
padding: 10px 50px;
/*Please check your animation ??
transition-duration: .4s;*/
/*add border size and transparency 1px solid*/
border: 1px solid greenyellow;
}
.loginButtonColor:hover {
color: black;
background-color: greenyellow;
}
<div class="content">
<h1><img src="../../36x36-icon.png">apLovers</h1>
<form class="signin">
<input class="loginInput" placeholder="Email" type="text"> <input class="loginInput" placeholder="Password" type="text"> <input class="loginButton loginButtonColor" id="login" name="submit" type="submit" value="Login To TapLovers!"> <font color="#99CC00">Create a FREE TapLovers Account!</font>
</form>
</div>
<footer>
<h3><img src="../../favicon.ico">apLovers</h3>
<p>© 2018 TapLovers, All Rights Reserved</p>
</footer>

Change size of button

I have tried everything, but I cannot manage to make the button smaller in the width and height.
.c--anim-btn span {
color: white;
text-decoration: none;
text-align: center;
display: block;
}
.c--anim-btn,
.c-anim-btn {
transition: 0.3s;
}
.c--anim-btn {
height: 64px;
font: normal normal 700 1em/4em Arial, sans-serif;
overflow: hidden;
width: 200px;
background-color: #3b5998;
}
.c-anim-btn {
margin-top: 0em;
}
.c--anim-btn:hover .c-anim-btn {
margin-top: -4em;
}
<!-- HINT: hover over button -->
<div class="c--anim-btn">
<span class="c-anim-btn">
First Text
</span>
<span>
Second Text
</span>
</div>
If someone please can tell me a solution, I would be very grateful.
Change the CSS property of c--anim-btn class
.c--anim-btn span {
color: white;
text-decoration: none;
text-align: center;
display: block;
}
.c--anim-btn,
.c-anim-btn {
transition: 0.3s;
}
.c--anim-btn {
height: 24px; /* change height */
font: normal normal 700 1em/1.6em Arial, sans-serif;
overflow: hidden;
width: 100px; /* change width */
background-color: #3b5998;
}
.c-anim-btn {
margin-top: 0em;
}
.c--anim-btn:hover .c-anim-btn {
margin-top: -1.6em;
}
<!-- HINT: hover over button -->
<div class="c--anim-btn">
<span class="c-anim-btn">
First Text
</span>
<span>
Second Text
</span>
</div>
you need to adjust line height and margin top after change height because of text seen. Comment out onn css please take a look .c--anim-btn and .c--anim-btn:hover
.c--anim-btn span {
color: white;
text-decoration: none;
text-align: center;
display: block;
}
.c--anim-btn, .c-anim-btn {
transition: 0.3s;
}
.c--anim-btn {
height: 128px;
font: normal normal 700 1em/8em Arial,sans-serif; /* 1em/8em means font-size/ line-height */
overflow: hidden;
width: 500px;
background-color: #3b5998;
}
.c-anim-btn{
margin-top: 0em;
}
.c--anim-btn:hover .c-anim-btn{
margin-top: -8em; /*Here you need to adjust after line-height change */
}
<!-- HINT: hover over button -->
<div class="c--anim-btn">
<span class="c-anim-btn">
First Text
</span>
<span>
Second Text
</span>
</div>