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.
Related
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.
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>
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>
I have an info box but I want it to slide in from left to right. But the css animation begins with a very high div because of the p tag inside it. Is there a way to fix this ?
JsFiddle : https://jsfiddle.net/scj5vc3b/
Html :
<div class="info-box info">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore ipsam fugit vero, autem asperiores accusamus ea unde magni distinctio excepturi minus amet repudiandae, debitis nulla voluptatem earum deleniti error reiciendis!</p>
</div>
SCSS :
.info-box {
margin: 10px 0;
border-left: 3px solid black;
overflow: hidden;
display: inline-block;
-webkit-animation: slideIn 1s linear;
position: relative;
p {
display: block;
padding: 10px 20px 10px 10px;
margin-bottom: 0;
}
}
#keyframes slideIn {
0% {max-width: 0px;}
100% {max-width: 1000px;}
}
.info-box.info {
background-color: lighten(blue, 24);
}
Use a transform on the paragraph instead:
.info-box {
margin: 10px 0;
border-left: 3px solid black;
-webkit-animation: slideIn 1s linear;
position: relative;
display: inline-block;
overflow: hidden;
}
p {
padding: 10px 20px 10px 10px;
margin-bottom: 0;
transform: translateX(-100%);
-webkit-animation: slideIn 1s linear forwards;
}
i {
padding-right: 15px;
}
#keyframes slideIn {
to {
transform: translateX(0%);
}
}
.info-box {
background-color: lightblue;
}
<div class="info-box info">
<p><i class="fa fa-info"></i>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore ipsam fugit vero, autem asperiores accusamus ea unde magni distinctio excepturi minus amet repudiandae, debitis nulla voluptatem earum deleniti error reiciendis!</p>
</div>
I would like to imitate the effect and output that I have on my #boxLeft, but when I do so, and add a css3 transition, it fails. I had to use fix it with a -100px margin-top value to hide it. Could anyone help?
HTML and CSS:
body {
padding: 0;
margin: 0;
}
p, h1, h2, h3, h4, h5, h6 {
padding: 0;
margin: 0;
}
#box {
width: 100%;
height: 100px;
background-color: #636363;
}
.boxLeft,
.boxRight {
width: 50%;
height: 100px;
/* display: inline-block; */
float: left;
padding: 10px;
box-sizing: border-box;
z-index: 1;
overflow: hidden;
}
.boxLeft {
background-color: red;
}
.blHeader {
text-align: right;
}
.boxLeft:hover {
background-color: orange;
width: 100%;
transition: .5s;
}
.boxLeft:hover ~.boxRight {
display: none;
}
.boxLeft:hover > .blHeader {
text-align: left;
}
.boxLeft:hover > .blCon {
display: block;
}
.blCon,
.brCon {
display: none;
}
.boxRight {
background-color: blue;
}
.boxRight:hover {
background-color: green;
width: 100%;
transition: .5s;
margin-top: -100px;
}
.boxRight:hover~.boxLeft {
display: none;
}
.boxRight:hover > .brHeader {
text-align: left;
}
.boxRight:hover > .brCon {
display: block;
transition: .5s;
}
<div id="box">
<div class="boxLeft">
<h2 class="blHeader">Left Header</h2>
<p class="blCon">Left content Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa harum recusandae perferendis animi, assumenda iste, repudiandae temporibus. Magni earum dicta perspiciatis tempore consequatur necessitatibus ullam recusandae dolore reiciendis,
repudiandae cumque!</p>
</div>
<div class="boxRight">
<h2 class="brHeader">RIght Header</h2>
<p class="brCon">Right content Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa harum recusandae perferendis animi, assumenda iste, repudiandae temporibus. Magni earum dicta perspiciatis tempore consequatur necessitatibus ullam recusandae dolore reiciendis,
repudiandae cumque!</p>
</div>
</div>
I'm sure I'm just missing out on something, but I've had a crack at it for hours. Thanks in advance. Here's a pen link: http://goo.gl/l2eqG0
The selector .boxRight:hover ~ .boxLeft isn't working as expected because the general sibling combinator, ~, only selects following sibling elements. Since the element .boxLeft precedes the element .boxRight, nothing is selected and the element .boxLeft isn't hidden when hovering over the element .boxRight.
To work around this, one option is to hide the first element when hovering over the parent #box element.
#box:hover .boxLeft {
display: none;
}
Then you can override this when actually hovering over the first element:
#box .boxLeft:hover {
display: block;
}
This works because there are only two elements. If you're not hovering over the first element, you can assume that you are otherwise hovering over the second element (which means that imitate the general sibling combinator since you can style the first element when hovering over the parent).
Updated Snippet:
body {
padding: 0;
margin: 0;
}
p, h1, h2, h3, h4, h5, h6 {
padding: 0;
margin: 0;
}
#box {
width: 100%;
height: 100px;
background-color: #636363;
}
.boxLeft,
.boxRight {
width: 50%;
height: 100px;
/* display: inline-block; */
float: left;
padding: 10px;
box-sizing: border-box;
z-index: 1;
overflow: hidden;
}
.boxLeft {
background-color: red;
}
.blHeader {
text-align: right;
}
.boxLeft:hover {
background-color: orange;
width: 100%;
transition: .5s;
}
.boxLeft:hover ~.boxRight {
display: none;
}
.boxLeft:hover > .blHeader {
text-align: left;
}
.boxLeft:hover > .blCon {
display: block;
}
.blCon,
.brCon {
display: none;
}
.boxRight {
background-color: blue;
float: right;
}
.boxRight:hover {
background-color: green;
width: 100%;
transition: .5s;
}
#box:hover .boxLeft {
display: none;
}
#box .boxLeft:hover {
display: block;
}
.boxRight:hover > .brHeader {
text-align: left;
}
.boxRight:hover > .brCon {
display: block;
transition: .5s;
}
<div id="box">
<div class="boxLeft">
<h2 class="blHeader">Left Header</h2>
<p class="blCon">Left content Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa harum recusandae perferendis animi, assumenda iste, repudiandae temporibus. Magni earum dicta perspiciatis tempore consequatur necessitatibus ullam recusandae dolore reiciendis,
repudiandae cumque!</p>
</div>
<div class="boxRight">
<h2 class="brHeader">RIght Header</h2>
<p class="brCon">Right content Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa harum recusandae perferendis animi, assumenda iste, repudiandae temporibus. Magni earum dicta perspiciatis tempore consequatur necessitatibus ullam recusandae dolore reiciendis,
repudiandae cumque!</p>
</div>
</div>
However, a more flexible option would be to remove the elements .boxLeft and .boxRight from the normal flow by absolutely position them. In doing so, you can avoid hiding the corresponding sibling elements on hover:
Updated Snippet:
body {
padding: 0;
margin: 0;
}
p, h1, h2, h3, h4, h5, h6 {
padding: 0;
margin: 0;
}
#box {
width: 100%;
height: 100px;
background-color: #636363;
}
.boxLeft,
.boxRight {
width: 50%;
height: 100px;
position: absolute;
top: 0;
padding: 10px;
box-sizing: border-box;
z-index: 1;
overflow: hidden;
}
.boxLeft {
background-color: red;
}
.blHeader {
text-align: right;
}
.boxLeft:hover {
background-color: orange;
width: 100%;
transition: .5s;
}
.boxLeft:hover ~ .boxRight {
z-index: auto;
}
.boxLeft:hover > .blHeader {
text-align: left;
}
.boxLeft:hover > .blCon {
display: block;
}
.blCon,
.brCon {
display: none;
}
.boxRight {
background-color: blue;
right: 0;
}
.boxRight:hover {
background-color: green;
width: 100%;
transition: .5s;
}
.boxRight:hover > .brHeader {
text-align: left;
}
.boxRight:hover > .brCon {
display: block;
transition: .5s;
}
<div id="box">
<div class="boxLeft">
<h2 class="blHeader">Left Header</h2>
<p class="blCon">Left content Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa harum recusandae perferendis animi, assumenda iste, repudiandae temporibus. Magni earum dicta perspiciatis tempore consequatur necessitatibus ullam recusandae dolore reiciendis,
repudiandae cumque!</p>
</div>
<div class="boxRight">
<h2 class="brHeader">RIght Header</h2>
<p class="brCon">Right content Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa harum recusandae perferendis animi, assumenda iste, repudiandae temporibus. Magni earum dicta perspiciatis tempore consequatur necessitatibus ullam recusandae dolore reiciendis,
repudiandae cumque!</p>
</div>
</div>