Transition on Material icon - css

I am interested in using a transition in the icon on a Material Design card.
Example 1.
Example 2.
Here is what I've got so far: Codepen.
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css">
<div class="container">
<div class="card hoverable">
<div class="card-image">
<img alt="Kirito" src="https://azure.microsoft.com/svghandler/cdn/?width=600&height=315">
<h2 class="card-title"><a class="white-text" href="#!">Card Title 1</a></h2><a class="btn-floating btn-large halfway-fab waves-effect waves-light red"><i class="material-icons">arrow_forward</i><i class="material-icons">arrow_forward</i></a>
</div>
<div class="card-content">
<div class="chip teal">
<a class="white-text" href="#!">Tags</a>
</div>
<div class="chip teal">
<a class="white-text" href="#!">Tags 2</a>
</div>
<p>I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively.</p>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script>
Problem. If i add both icons and some overflow: hidden; to the container of the icon, the problem is the icons move down. And I upset to set the CSS transition for the icon.

It is possible to recreate the first screen capture as follows.
Ensure that icons within the button are on the same line.
This can be done using white-space: nowrap; on the button.
Transition the left margin of the first icon to move it out of view when the card is being hovered. This will automatically move the second icon into view, as it comes right after.
I demonstrate this below. To not do this automatically for all cards, I have restricted the styles to cards with class two-icons. I have added that class to your HTML, it is otherwise unchanged.
.card {
max-width: 250px; /* only for display purposes on Stack Overflow */
}
.two-icons .btn-floating {
white-space: nowrap;
}
.two-icons .btn-floating .material-icons:first-child {
transition: margin-left .4s;
}
.two-icons:hover .btn-floating .material-icons:first-child {
margin-left: -56px;
}
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css">
<div class="container">
<div class="card hoverable two-icons">
<div class="card-image">
<img alt="Kirito" src="https://azure.microsoft.com/svghandler/cdn/?width=600&height=315">
<h2 class="card-title"><a class="white-text" href="#!">Card Title 1</a></h2><a class="btn-floating btn-large halfway-fab waves-effect waves-light red"><i class="material-icons">feedback</i><i class="material-icons">arrow_forward</i></a>
</div>
<div class="card-content">
<div class="chip teal">
<a class="white-text" href="#!">Tags</a>
</div>
<div class="chip teal">
<a class="white-text" href="#!">Tags 2</a>
</div>
<p>I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively.</p>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script>

Related

CSS Flexbox - Align the contents on top and align the button to bottom

I'm trying to modify an existing component which inherits the Flexbox concept.
Currently it looks like this:
Now what I'm trying to achieve is regardless of content size inside the box:
The box will have the same height - aligned to each other
The button will stay at the bottom even if the top contents are long.
Here is the existing structure that I'm trying to fix:
<section class="container counsellor-list">
<div class="row">
<div class="col-12 col-sm-12 col-lg-6 col-xl-4 mb-30 counsellor-list-item">
<div class="state_chosen">
<img class="img-fluid" src="https://st.depositphotos.com/1771835/1477/i/950/depositphotos_14779771-stock-photo-portrait-of-confident-young-doctor.jpg" />
<div class="bg-blue20 p-30 counsellor-list-item-content">
<div class="text-coral subtitle-small text-bold text-uppercase mb-24 d-flex flex-wrap">
<span class="">
Wien
</span>
<span class="ml-16">
St. Polten
</span>
<span class="ml-auto language">
<span>
DE
<span> | </span>
EN
</span>
</span>
</div>
<h2 class="mb-24">Jan Faustio</h2>
<div class="">
<a class="btn btn-coral" href="#"> Button </a>
</div>
</div>
</div>
</div>
...
</section>
Codepen link
I tried a lot of stuff but didn't work as I'm expecting it to be/result.
Check this, I hope I understood what you want to achieve https://codepen.io/IvanBisultanov/pen/PoQmXqX
I also added .btn-wrap classname, and wrapped all HTML above in div
.counsellor-list-item-content {
flex-grow: 1;
display: flex;
flex-direction: column;
}
.btn-wrap {
margin-top: auto;
}

Bootstrap CSS: Maintain card button position when browser dimensions change

I'm trying to create cards that maintain the position of its button when the user's browser dimensions change.
Desktop full-screen:
When the browser is resized:
I'm trying to keep the card button in the same position when the browser is resized. But in my example the "Upvote" button is moved beneath the text, instead of remaining on the right side. To be more specific, have a look at this picture:
The green space should be reserved for the button, and red space should be the position of the button:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>
<div class="row justify-content-center">
<div>
<div class="container">
<div class="card m-2">
<div class="card-body">
<div class="container p-1">
<img
src="https://1iq2pi1r3dw63rcvw63p8mfb-wpengine.netdna-ssl.com/wp-content/uploads/2017/08/kion-bar-box-600x600.jpg"
class="float-left mr-1"
alt=""
width="60px"
heigth="60px"
/>
<div class="row">
<div class="col-md-11 pr-5">
<h5 class="card-title">Kion Bar 2 - Best energy bar there is no</h5>
<p class="card-text">Best energy bar there is, no other like this that can even..</p>
</div>
<div class="col-md-1 ml-md-auto align-self-center">
<a href="#" class="btn btn-outline-secondary float-right">
Upvote
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<div class="media align-items-center">
<img width="10%" class="align-self-center mr-3" src="https://1iq2pi1r3dw63rcvw63p8mfb-wpengine.netdna-ssl.com/wp-content/uploads/2017/08/kion-bar-box-600x600.jpg" alt="Generic placeholder image">
<div class="media-body">
<div class="row align-items-center">
<div class="col-md-9 col-9">
<h5 class="mt-0">Kion Bar 2 - Best energy bar there is no</h5>
<p>Best energy bar there is, no other like this that can even..</p>
</div>
<div class="col-md-3 col-3">
<a href="#" class="btn btn-outline-secondary float-right">
Upvote
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
It'd be better if you use media, it'll make your work easier. Also .container should use only once within a section.
Containers provide a means to center and horizontally pad your site’s
contents. Use .container for a responsive pixel width or
.container-fluid for width: 100% across all viewport and device
sizes.
Rows are wrappers for columns. Each column has horizontal padding
(called a gutter) for controlling the space between them. This
padding is then counteracted on the rows with negative margins. This
way, all the content in your columns is visually aligned down the
left side.
In a grid layout, content must be placed within columns and only
columns may be immediate children of rows.
You can check the below links for reference
Grid System of Bootstrap
Media
First of all, you are making many mistakes in your markup. You should take the time to learn how to correctly write your markup.
Secondly, learn how to work with images. DO use width and height attributes for your images, but DO NOT specify them in pixels. What you are doing is setting an aspect ratio, not the actual dimensions. The .img-fluid class makes your image responsive. The attributes maintains its aspect ratio. Specifying the aspect ratio will prevent the browser from moving content down the page while it waits to download the image and figure out how to draw it on the canvas.
I believe the following is what you are trying to do.
See it on Bootply
<div class="container-fluid">
<div class="card my-2">
<div class="card-body">
<div class="row">
<div class="col-1">
<img src="https://1iq2pi1r3dw63rcvw63p8mfb-wpengine.netdna-ssl.com/wp-content/uploads/2017/08/kion-bar-box-600x600.jpg" class="img-fluid" alt="" width="600" heigth="600">
</div>
<div class="col-9">
<h5 class="card-title">Kion Bar 2 - Best energy bar there is no</h5>
<p class="card-text">Best energy bar there is, no other like this that can even..</p>
</div>
<div class="col-2">
<a href="#" class="btn btn-outline-secondary btn-block">
Upvote
</a>
</div>
</div>
</div>
</div>
</div>
Remember, you can set different col spans for different viewports.

CSS :hover and bootstrap 3

I'm making a navbar in bootstrap 3 and I found something weird.
<nav className="navbar navbar-inverse">
<div className="container-fluid">
<div className="container">
<div className="row">
<div className="col-sm-3">
<a href="#">
Home
</a>
</div>
<div className="col-sm-3">
<a href="#">
About us
</a>
</div>
<div className="col-sm-3">
<a href="#">
Surveys
</a>
</div>
<div className="col-sm-3">
<a href="#">
Statistics
</a>
</div>
</div>
</div>
</div>
This is structure of this component and here is CSS, where I try to make <a> attribute larger on :hover
a:hover {
text-decoration: none;
color: inherit;
transform: scale(1.1);
}
And I can't help wondering why despite others attributes working, transform shows no effect. Not sure if it changes anything, but maybe I'll add that I use React for this application.
Only elements positioned by the box model can be transformed. As a rule of thumb, an element is positioned by the box model if it has display: block. Source
You can also use display: inline-block;.

why padding not working in cards

i am newbie to web development and i am working on materialize cards.It is working correctly in laptop but when i try to run it in iPad the cards are getting overlap.
.container-fluid {
margin-top: 500px;
/*
padding-left: 100px;
padding-right: 100px;
*/
}
.card-reveal {
color: #ffffff;
background-color: rgba(0, 0, 0, 0.7) !important;
}
div.card-reveal span.card-title {
color: #ffffff !important;
}
.card {
width: 280px;
height: 360px;
z-index: 5 background-color: blue;
}
#card-img {
height: 200px;
}
.card-content {
margin-top: -17px;
color: black;
}
.card-action {
margin-top: 38px;
}
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection" />
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/stackcss.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col m3">
<div class="card hover-reveal sticky-action z-depth-2">
<div class="card-image waves-effect waves-block waves-light">
<img id="card-img" class="activator z-depth-5" src="http://images.media-allrecipes.com/userphotos/720x405/1889670.jpg">
</div>
<div id="thumbnail" class="z-depth-5"></div>
<div class="card-content">
<p>Card Title<i class="material-icons right">more_vert</i></p>
<!--<span class="card-title activator grey-text text-darken-4 ">THis is a link</span>-->
</div>
<div class="card-action">
VIEW
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">Card Title<i class="material-icons right">close</i></span>
<p>Here is some more information about this product that is only revealed once clicked on.</p>
</div>
</div>
</div>
<div class="col m3">
<div class="card hover-reveal sticky-action z-depth-2">
<div class="card-image waves-effect waves-block waves-light">
<img id="card-img" class="activator z-depth-5" src="http://images.media-allrecipes.com/userphotos/720x405/1889670.jpg">
</div>
<div id="thumbnail" class="z-depth-5"></div>
<div class="card-content">
<p>Card Title<i class="material-icons right">more_vert</i></p>
<!--<span class="card-title activator grey-text text-darken-4 ">THis is a link</span>-->
</div>
<div class="card-action">
VIEW
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">Card Title<i class="material-icons right">close</i></span>
<p>Here is some more information about this product that is only revealed once clicked on.</p>
</div>
</div>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script src="js/matjs.js"></script>
</body>
</html>
You are trying to have four cards in a line, each of the cards is 280px wide, and that makes it 1120px of total width. In addition, you have 50px of left and right margins (.container-fluid), which will add a 100px to the total width. Eventually you are going to have some space between those cards, so add another hundred. 1320px of total width for this section is a minimum that will allow you to have four of these cards in a line. According to the Materialize documentation the .m3 class that you’ve assigned to your cards will keep all these cards in a .row in a single line up until your screen resolution greater than 600px wide, otherwise all cards will be rearranged to fill multiple lines.
Basic on what materialize is offering you can change .m3 classes to .xl3 and thereby buy another 600px. But your 1320px section is still be wider than 1200px for .xl class, so you may consider to reduce .container-fluid’s left and right margins and/or reduce card’s width.

Vertical align Bootstrap 4 .close icon inside Alert

I'm using the Bootstrap 4 Close icon inside an Alert.
<div class="alert alert-info p-2">
<a class="close" data-dismiss="alert" href="#">×</a>The CVC card code is required.
</div>
https://www.codeply.com/go/4ImkAPOKug
The problem is that the close icon is not vertically centered within the anchor element. I would like to move it up a few pixels. When inspecting the .close CSS, I see that line-height:1 controls the height of the anchor, so adjusting line-height shrinks the height of the anchor, but I prefer to keep it as is for consistency.
Other than changing the line-height, is there a way to vertically position the icon within the line-box of the anchor? I've tried display:inline-block, vertical-align:middle, bottom margin, etc... but nothing seems to work. I don't want to vertical center within the alert.
Not the best way, but you can apply a margin-top of -0.15rem
.close {
margin-top:-0.15rem;
}
/* To illustrate */
.alert {
position:relative;
}
.alert:after {
content:"";
position:absolute;
top:26px;
left:0;
width:100%;
border-bottom:1px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row py-3">
<div class="col-8">
<div class="alert alert-info p-2">
<a class="close" data-dismiss="alert" href="#">×</a>The CVC card code is required.
</div>
</div>
</div>
</div>
<div class="container">
<div class="row py-3">
<div class="col-3">
<div class="alert alert-info p-2">
<a class="close" data-dismiss="alert" href="#">×</a>The CVC card code is required.
</div>
</div>
</div>
</div>
You can use baseline to align the items by their baseline in a combination:
.alert{
display: flex;
align-items: baseline;
}
.alert:after {
content:"";
position:absolute;
top:31px;
left:0;
width:100%;
border-bottom:1px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row py-3">
<div class="col-6">
<div class="alert alert-info p-2">
<p>The CVC card code is required</p>
<a class="close" data-dismiss="alert" href="#">
×
</a>
</div>
</div>
<div class="col-6">
<div class="alert alert-info p-2">
<p>The × aligns toward the bottom of the anchor's line-box?</p>
<a class="close align-top d-table-cell align-top" data-dismiss="alert" href="#">
<span class="border border-danger">×</span>
</a>
</div>
</div>
</div>
</div>
I wasn't able to get the standard close to align to the top properly. A workaround is to use align-text-top small to shrink the font and height of the close element.
<div class="alert alert-info p-2">
<a class="close" data-dismiss="alert" href="#">
<span class="align-text-top small">×</span>
</a>
The CVC card code is required
</div>
https://codeply.com/go/gr21OObdyV
Use flexbox to align the close-button vertically:
<div class="alert alert-success fade show d-flex justify-content-center align-items-center">
<i class="fa-duotone fa-circle-exclamation fa-lg me-auto"></i>
<span class="me-auto px-3">This is a success alert ...</span>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>

Resources