This question already has answers here:
What elements can be contained within a <a> tag?
(6 answers)
Closed 3 years ago.
I'm trying to create a card for a website I'm pulling together. On hover, some text slides into view (I've used :hover combined with max-height). To make the whole card clickable, I tried to change a <div> to <a>, I added display:block.
I'm surprised that the behaviour is different - I expected them to be the same.
Two questions:
How do I get the right behaviour - simply making the card clickable without JavaScript.
What is the underlying issue that I've missed?
This version has the <div>:
.card {
background: yellow;
border-radius: .5em;
height: 15em;
position: relative;
overflow: hidden;
transition: all 1s ease-in-out;
}
.card:hover img {
transform: scale(1.1);
}
.card:hover .card-slider {
max-height: 7em;
}
.card-content {
position: absolute;
bottom: 0;
display: block;
}
.card-slider {
transition: all 1s ease-in-out;
max-height: 0;
overflow: hidden;
}
.card h1 {
background: rgba(0, 0, 0, 0.1);
color: white;
}
.card img {
transition: all 1s ease-in-out;
position: relative;
width: 100%;
height: 100%;
object-fit: cover;
}
.card .meta-cat {
position: absolute;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.1);
text-transform: uppercase;
}
.card .meta {
display: flex;
margin: 0;
padding: 0;
justify-content: space-between;
}
.meta-author, .meta-date {
list-style: none;
}
<article class="card">
<img src="http://via.placeholder.com/350x200" alt="">
<header class="meta-cat">Lorem.</header>
<div href="#" class="card-content">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure, velit.</h1>
<section class="card-slider">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias dignissimos dolor ex in iusto magnam
molestias odit quaerat rem rerum, similique sit sunt totam veritatis vitae voluptate, voluptatum? Amet,
maxime.</p>
<ul class="meta">
<li class="meta-author">WO J Wright</li>
<li class="meta-date">Posted 5 days ago</li>
</ul>
</section>
</div>
</article>
This version changes the <div> to a <a>.
.card {
background: yellow;
border-radius: .5em;
height: 15em;
position: relative;
overflow: hidden;
transition: all 1s ease-in-out;
}
.card:hover img {
transform: scale(1.1);
}
.card:hover .card-slider {
max-height: 7em;
}
.card-content {
position: absolute;
bottom: 0;
display: block;
}
.card-slider {
transition: all 1s ease-in-out;
max-height: 0;
overflow: hidden;
}
.card h1 {
background: rgba(0, 0, 0, 0.1);
color: white;
}
.card img {
transition: all 1s ease-in-out;
position: relative;
width: 100%;
height: 100%;
object-fit: cover;
}
.card .meta-cat {
position: absolute;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.1);
text-transform: uppercase;
}
.card .meta {
display: flex;
margin: 0;
padding: 0;
justify-content: space-between;
}
.meta-author, .meta-date {
list-style: none;
}
<article class="card">
<img src="http://via.placeholder.com/350x200" alt="">
<header class="meta-cat">Lorem.</header>
<a href="#" class="card-content">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure, velit.</h1>
<section class="card-slider">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias dignissimos dolor ex in iusto magnam
molestias odit quaerat rem rerum, similique sit sunt totam veritatis vitae voluptate, voluptatum? Amet,
maxime.</p>
<ul class="meta">
<li class="meta-author">WO J Wright</li>
<li class="meta-date">Posted 5 days ago</li>
</ul>
</section>
</a>
</article>
Actually you can have block elements inside <a> tag, as you already said, just replacing the nested <a> tag inside .meta-author with a span, makes your last snipped works.
.card {
background: yellow;
border-radius: .5em;
height: 15em;
position: relative;
overflow: hidden;
transition: all 1s ease-in-out;
}
.card:hover img {
transform: scale(1.1);
}
.card:hover .card-slider {
max-height: 7em;
}
.card-content {
position: absolute;
bottom: 0;
display: block;
}
.card-slider {
transition: all 1s ease-in-out;
max-height: 0;
overflow: hidden;
}
.card h1 {
background: rgba(0, 0, 0, 0.1);
color: white;
}
.card img {
transition: all 1s ease-in-out;
position: relative;
width: 100%;
height: 100%;
object-fit: cover;
}
.card .meta-cat {
position: absolute;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.1);
text-transform: uppercase;
}
.card .meta {
display: flex;
margin: 0;
padding: 0;
justify-content: space-between;
}
.meta-author, .meta-date {
list-style: none;
}
<article class="card">
<img src="http://via.placeholder.com/350x200" alt="">
<header class="meta-cat">Lorem.</header>
<a href="#" class="card-content">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure, velit.</h1>
<section class="card-slider">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias dignissimos dolor ex in iusto magnam
molestias odit quaerat rem rerum, similique sit sunt totam veritatis vitae voluptate, voluptatum? Amet,
maxime.</p>
<ul class="meta">
<li class="meta-author"><span>WO J Wright</span></li>
<li class="meta-date">Posted 5 days ago</li>
</ul>
</section>
</a>
</article>
Related
I want to customise HTML summary's marker, and animate it when the details element opens.
The transition animation works on all browsers except Safari both on desktop and mobile.
details {
width: 50%;
margin: 0 auto;
background: #FDF4E3;;
margin-bottom: .5rem;
border-radius: 5px;
color: black;
outline: 0;
}
summary {
padding: 1rem;
display: block;
padding-left: 2.2rem;
position: relative;
cursor: pointer;
}
summary:before {
content: '';
border-width: .4rem;
border-style: solid;
border-color: transparent transparent transparent #fff;
position: absolute;
top: 1.3rem;
left: 1rem;
transform: rotate(0);
transform-origin: .2rem 50%;
transition: 1s transform ease;
}
details[open] summary {
background: #F9D478;
}
details[open]>summary:before {
transform: rotate(90deg);
}
details summary::-webkit-details-marker {
display: none;
}
details p {
padding: 1rem;
}
<details>
<summary>Summary</summary>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Itaque porro odit nulla quis voluptas quod similique sunt, nostrum, ea maxime repellendus quisquam harum tempore illum sed, dolore qui aperiam impedit!
</p>
</details>
I have used the following transition that did not work.
-webkit-transition: 1s transform ease;
-webkit-transition: 1s all ease;
details[open]>summary:before {
transform: rotate(90deg);
transition: 1s transform ease;
}
How to fix issue?
These answers did not help.
css transitions not working in safari
CSS transform and transition not working in Safari
CSS transition is not working in Safari
Transitions not working on iOS safari - tried all the different suffix
Animations and Transitions is not supported on pseudo elements for Safari browser. MDN
You could use a real HTML element for icon then animate that element.
Here is an example with using svg element:
details {
width: 50%;
margin: 0 auto;
background: #282828;
margin-bottom: 0.5rem;
box-shadow: 0 0.1rem 1rem -0.5rem rgba(0, 0, 0, 0.4);
border-radius: 5px;
color: white;
}
summary {
padding: 1rem;
display: block;
background: #333;
padding-left: 2.2rem;
position: relative;
cursor: pointer;
}
svg {
width: 1.2rem;
height: 1.2rem;
vertical-align: bottom;
transition: all 0.3s;
}
details[open]>summary>svg {
transform: rotate(90deg);
}
details summary::-webkit-details-marker {
display: none;
}
details p {
padding: 1rem;
}
<details>
<summary>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
</svg>
Summary
</summary>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Itaque porro odit nulla quis voluptas quod similique sunt, nostrum, ea maxime repellendus quisquam harum tempore illum sed, dolore qui aperiam impedit!
</p>
</details>
This seems to be a known bug: Bug 213349 - transitions not when is opened:
Expected behaviour:
As soon as I click the <summary> element, the transition from > to ⌄ should start, and vice versa.
Actual behaviour:
The transition doesn't start when the <summary> element is clicked. The exact conditions that are triggering the transition are somewhat unclear to me. It seems to start only after giving another element focus or moving the cursor outside of the parent element.
While the descriptions does not exactly match the behaviour you encounter, it is likely that those are closely related.
You could solve it with JavaScript, but that is annoying as toggle, does not bubble:
var details = document.querySelector("details")
details.addEventListener("toggle", function(evt) {
details.classList.toggle('open', evt.target.open)
})
details {
width: 50%;
margin: 0 auto;
background: #282828;
margin-bottom: .5rem;
box-shadow: 0 .1rem 1rem -.5rem rgba(0, 0, 0, .4);
border-radius: 5px;
color: white;
}
summary {
padding: 1rem;
display: block;
background: #333;
padding-left: 2.2rem;
position: relative;
cursor: pointer;
}
summary:before {
content: '';
border-width: .4rem;
border-style: solid;
border-color: transparent transparent transparent #fff;
position: absolute;
top: 1.3rem;
left: 1rem;
transform: rotate(0);
transform-origin: .2rem 50%;
transition: 1s transform ease;
}
/*details[open]>summary:before {
transform: rotate(90deg);
}*/
details.open>summary:before {
transform: rotate(90deg);
}
details summary::-webkit-details-marker {
display: none;
}
details p {
padding: 1rem;
}
<details>
<summary>Summary</summary>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Itaque porro odit nulla quis voluptas quod similique sunt, nostrum, ea maxime repellendus quisquam harum tempore illum sed, dolore qui aperiam impedit!
</p>
</details>
I wouldn't use the JS solution. I actually just would wait until the bug is fixed, as it is just an eye-candy animation for the open/close marker.
There's some awkward vertical line glitch apparently due to filter property(applied on image's hover state) while hovering on a image in chrome(It works fine in mozilla firefox). I have searched on the web but all I could find are kind of similar glitches/bugs or whatever while using backdrop-filter property. So a specific explanation or workaround to these glitch/bug/rendering problem due to this filter property in css would be really nice.
Here's my html code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Lato';
font-weight: 400;
line-height: 1.7;
padding: 3rem;
color: #777;
}
.header-tertiary {
font-size: 1.6rem;
font-weight: 700;
text-transform: uppercase;
}
.row {
max-width: 114rem;
margin: 0 auto;
}
.story {
width: 75%;
margin: 0 auto;
background-color: #fff;
border-radius: 3px;
box-shadow: 0 3rem 6rem rgba(0, 0, 0, 0.1);
padding: 6rem;
padding-left: 9rem;
font-size: 1.6rem;
transform: skewX(-12deg);
}
.story__shape {
width: 15rem;
height: 15rem;
float: left;
shape-outside: circle(50% at 50% 50%);
clip-path: circle(50% at 50% 50%);
transform: translateX(-3rem) skewX(12deg);
position: relative;
}
.story__img {
height: 100%;
transform: translateX(-3rem) scale(1.4);
transition: all .5s;
}
.story-text {
transform: skewX(12deg);
}
.story__caption {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, 30%);
color: #fff;
text-align: center;
opacity: 0;
transition: all .5s ease;
}
.story:hover .story__caption {
opacity: 1;
transform: translate(-50%, -50%);
}
.story:hover .story__img {
filter: blur(2px) brightness(80%);
-webkit-filter: blur(2px) brightness(80%);
transform: translateX(-3rem) scale(1);
}
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="row">
<div class="story">
<figure class="story__shape">
<img class="story__img" src="https://images.unsplash.com/photo-1612306055306-e72bd105ad3d?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1225&q=80" alt="story image">
<figcaption class="story__caption">
Mary Smith
</figcaption>
</figure>
<div class="story-text">
<h3 class="header-tertiary u-margin-bottom-small">
I had the best week ever with my family
</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorem doloribus voluptatem nisi vel hic suscipit repellendus eum, sed earum placeat quaerat, laboriosam dolores atque ratione odio quidem reprehenderit ea ab. Dolor provident tempora nobis quaerat
consequatur sequi alias illum veritatis.
</p>
</div>
</div>
</div>
</body>
</html>
Note: I have not made my code responsive so please view on full page.
How can I make an image fill the full height in a flexbox item? The image should be stretched to fill the height while keeping the aspect ratio.
body {
background: #20262E;
padding: 20px;
font-family: Arial;
}
.banner-message {
background: #eee;
border-radius: 20px;
padding: 0px;
overflow: hidden;
width: 500px;
display: flex;
align-items: stretch;
}
.banner-message .banner-message-media {
flex: 1;
}
.banner-message .banner-message-content {
padding: 20px;
flex: 2;
}
<div class="banner-message">
<div class="banner-message-media">
<img src="https://picsum.photos/id/1068/250/150" />
</div>
<div class="banner-message-content">
<h3>Content Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae delectus, quod veniam necessitatibus saepe error dicta voluptatem vitae incidunt nulla fugit! Quasi minus libero reiciendis similique cupiditate eum veniam tenetur.</p>
</div>
</div>
Add height:100%; and width:fit-content;
img {
height: 100%;
width: fit-content;
}
SCCS:
body {
background: #20262E;
padding: 20px;
font-family: Arial;
}
.banner-message {
background: #eee;
border-radius: 20px;
padding: 0px;
overflow: hidden;
width: 500px;
display: flex;
align-items: stretch;
.banner-message-media {
border-radius: 10px;
flex: 1;
img {
height:100%;
width:fit-content;
}
}
.banner-message-content {
padding: 20px;
flex: 2;
}
}
body {
background: #20262e;
padding: 20px;
font-family: Arial;
}
.banner-message {
background: #eee;
border-radius: 20px;
padding: 0px;
overflow: hidden;
width: 500px;
display: flex;
align-items: stretch;
}
.banner-message .banner-message-media {
border-radius: 10px;
flex-grow: 1;
}
.banner-message .banner-message-content {
padding: 20px;
flex-grow: 2;
}
img {
height: 100%;
width: fit-content;
}
<div class="banner-message">
<div class="banner-message-media">
<img src="https://picsum.photos/id/1068/250/150" />
</div>
<div class="banner-message-content">
<h3>Content Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae delectus, quod veniam necessitatibus saepe error dicta voluptatem vitae incidunt nulla fugit! Quasi minus libero reiciendis similique cupiditate eum veniam tenetur.</p>
</div>
</div>
Use object-fit property in your .banner-message-media css class. Like this
object-fit: fill or object-fit: cover.
I have got my footer to stay at the bottom of the page however it is overlapping the content and i cant stop it.
I have looked all over the internet for a solution and none works. I have a feeling that i need to move divs around etc but i could be wrong.
Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css?family=Concert+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Eczar" rel="stylesheet">
<link rel="stylesheet" href="style/stylesheet.css">
<title>Layout</title>
</head>
<body>
<div id="header">
<img src="img/top-bar/bar.png" height="10px" class="top">
<ul id="menu-bar">
<li>Home</li>
<li>Page 1</li>
<li class="dropdown">
Page 2
<div class="dropdown-content">
Drop 1
Drop 2
</div>
</li>
<li>Page 3</li>
<li>Login</li>
</ul>
<img src="img/archery-1839284.jpg" class="cover">
</div>
<div id="wrapper">
<div id="content">
<div id="first" class="item">
<p class="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime distinctio sed officia, nam iure quam necessitatibus nobis non, aut quaerat autem. Quam mollitia, fugiat amet veritatis, voluptate earum quidem et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci ex earum impedit ipsum consequatur dolor doloremque eum. Sed fugit dolor maiores pariatur nesciunt iste cupiditate consequuntur, dolore alias numquam voluptatum!
</p>
</div>
<div id="img-span">
<img src="img/board-911636.jpg" class="wide">
</div>
<div class="item" style="background-color: red;">
<p class="para">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem sit non ipsam aut perferendis neque magnam deleniti, officia necessitatibus porro odio ipsum est eum aliquam nulla placeat, deserunt? Atque, nisi.
</p>
</div>
</div>
<div id="footer">
<img src="img/top-bar/bar.png" height="10px" class="bottom">
</div>
</div>
</body>
</html>
CSS:
body {
background-color: grey;
margin: 0;
padding: 0;
font-family: 'Eczar', serif;
scroll-behavior: smooth;
}
#header {
position: relative;
text-align: center;
}
.top {
position: fixed;
width: 100%;
z-index: 3000;
left: 0;
top: 0;
}
.bottom {
width: 100%;
position: absolute;
bottom: 0;
left: 0;
}
#wrapper {
padding: 0;
margin: 0;
position: absolute;
width: 100%;
margin-top: 100%;
}
.cover {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
max-width: 100%;
background-image: url(../img/archery-1839284.jpg);
overflow: hidden;
}
#content {
width: 100%;
top: 100%;
height: 100%;
position: relative;
background-color: blue;
text-align: center;
}
.item {
padding-left: 20%;
padding-right: 20%;
padding-top: 4px;
padding-bottom: 4px;
overflow: hidden;
margin: 0;
position: relative;
}
.item p {
font-size: 18px;
}
.img-span {
padding: 0;
margin: 0;
width: 100%;
position: relative
}
.wide {
width: 100%;
height: 100%;
opacity: 1;
overflow: hidden;
display: block;
}
#footer {
width: 100%;
height: 70px;
background-color: greenyellow;
z-index: 3000;
bottom: 0;
left: 0;
position: absolute;
clear: both;
}
Just set the #footer to position: relative; will fix the overlapping issue.
#footer {
width: 100%;
height: 70px;
background-color: greenyellow;
position: relative;
clear: both; }
But you should have a look at the following website which explains how to create a footer that will always stick on the bottom of the page, with large or with small contents. This would be a much better way.
http://www.cssstickyfooter.com/using-sticky-footer-code.html
I don't think that the way you go at it is the best but what would work in your case is to change your wrapper class adding a padding bottom equal to your footer height like:
#wrapper {
padding: 0 0 10px 0;
margin: 0;
position: absolute;
width: 100%;
margin-top: 100%;
}
#footer {
height:10px;
}
As per your problem you want stick your footer to the bottom of your page right ? so, that you have to put following css code to
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom:70px;
}
I'm relatively new at coding and I'm trying to make it so one image fades to a different image and that image has text over it.
I'm using Tumblr, so PHP-5-only MVC I'm pretty sure.
And here's what I have so far:
<style>
#imagefade {
background-image: url('http://i65.tinypic.com/107kqbq.jpg');
position: absolute;
}
#imagefade img {
-webkit-transition: all ease 1.5s;
-moz-transition: all ease 1.5s;
-o-transition: all ease 1.5s;
-ms-transition: all ease 1.5s;
transition: all ease 1.5s;
}
#imagefade img:hover {
opacity: 0;
}
#text {
position: center;
}
.image {
position: relative;
}
p {
position: absolute;
top: 200px;
left: 38px;
width: 100%;
font-family: arial;
font-size: 12px;
color: white;
}
</style>
<div id="imagefade">
<img src="http://i68.tinypic.com/2i9s4eb.jpg" />
<p>text heading here</p>
</div>
If I got it correct from what you want, the easiest way to do this is use position: absolute; and opacity on :hover to achieve this. The positioning will set the layers on top of each other and not next to each other (as in your example).
See my example below.
.container {
background: lightblue;
position: relative;
width: 500px;
height: 300px;
}
.box {
background-image: url('https://i.imgur.com/AzeiaRY.jpg');
background-position: center;
position: absolute; /* Setting the boxes on top of each other */
top: 0;
left: 0;
right: 0;
bottom: 0;
display: block;
transition: opacity .4s ease-in-out; /* Transition the opacity for the :hover */
}
.image-2 {
background-position: bottom right;
opacity: 0;
}
.image-1:hover .image-2 {
opacity: 1;
}
/* Pure for styling below */
.box-text {
position: absolute;
top: 0;
left: 0;
color: #fff;
padding: 10px;
background: rgba(0, 0, 0, .8);
width: 40%;
height: 100%;
box-sizing: border-box;
}
<div class="container">
<div class="box image-1">
<div class="box image-2">
<div class="box-text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias, mollitia. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim ipsa maxime modi velit similique maiores, porro voluptate? Molestias ratione natus consequatur libero eaque
pariatur optio quisquam minima. Nemo quis, odit.
</p>
</div>
</div>
</div>
</div>