What is the reason for the color transition effect only functioning in CSS when set to "

Is there a way to make the text color change faster than everything else in the transition? It seems that on the first transition, the color won't work but works fine going back. Can anyone explain why this is happening?

#home-section button {
  margin: 50px auto;
  width: auto;
  border: none;
  border-radius: 0px;
  background-color: #eee8e8;
  padding: 2px 2px;
  font-size: 0.9rem;
  font-weight: bold;
}

#home-section article {
  width: 0;
  height: 0;
  overflow: hidden;
  color: transparent;
  -webkit-transition: all 3s, color 1s;
  transition: all 3s, color 1s;
}

#home-section button:focus + article {
  width: 670px;
  height: 500px;
  line-height: 180%;
  letter-spacing: 1px;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: #797879 #252625;
  background: #625b6b;
  color: white;
  padding: 10px;
}

#home-section button:focus {
  background-color: #252625;
  color: #eee8e8;
}
this html code snippet corresponds to a react component.

import React from 'react';
import './styles/Home.css';

function Main() {
    return (
        <section id="home-section">
            <h1>Hi,</h1>
            <h2>My Name is Elmahdi,</h2>
            <h2>And I'm a Front-End Web Developer.</h2>
            <button>Read My story</button>
            <article>
                texttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf texttexttextextefgzehgozsfzenf text
            </article>
        </section>
    )
}

export default Main

Answer №1

Initially, the color transition appears to take 3 seconds due to the background transition creating an illusion. However, setting the initial background color to #625b6b reveals that the actual color transition only lasts 1 second.

Consider the following example where the default background color is #625b6b:

#main-container button {
  margin: 10px auto;
  width: auto;
  border: none;
  border-radius: 4px;
  background-color: #f0f0f0;
  padding: 5px 10px;
  font-size: 1rem;
}

#main-container section {
  background: #625b6b;
  width: 100%;
  height: 0;
  overflow: hidden;
  color: transparent;
  -webkit-transition: all 2s, color 1s;
  transition: all 2s, color 1s;
}

#main-container button:focus+section {
  width: 80%;
  height: 300px;
  line-height: 150%;
  letter-spacing: 1px;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: #333333 #cccccc;
  background: #625b6b;
  color: white;
  padding: 20px;
}

#main-container button:focus {
  background-color: #333333;
  color: #ffffff;
}
<div id="main-container">
  <button>Click Me</button>
  <section>
    This is a test. This is a test. This is a test.
  </section>
</div>

Answer №2

Here is the solution I came up with to achieve my desired outcome

section {
      background: #625b6b;
      width: 20px;
      height: 20px;
      overflow: hidden;
      color: transparent;
      visibility: hidden;
      transition: all 1s, color 0.5s ease 0ms;
    }
    
    button:focus + section {
      visibility: visible;
      width: 670px;
      height: 500px;
      line-height: 180%;
      letter-spacing: 1px;
      overflow-y: scroll;
      scrollbar-width: thin;
      scrollbar-color: #797879 #252625;
      background: #625b6b;
      color: white;
      padding: 10px;
      transition: all 1.5s, color 0.85s ease-out 500ms;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method for freezing an HTML element in relation to a container using either CSS or JavaScript?

I've been diligently researching this topic up until the final day, but unfortunately, I have yet to find a solution. I am in dire need of assistance with my project. Could someone please help me out? One of my related searches led me to Can I positi ...

Unusual characteristics found in a select list controlled by Angular

The article titled "How to set the initial selected value of a select element using Angular.JS ng-options & track by" by @Meligy served as my guide while working on implementing a select list (ng-options). Despite achieving the desired basic functional ...

Update the font style of the navigation bar

Hey there! I recently downloaded a template from this website: . However, I'm facing an issue with the nav bar displaying strange fonts when using Vietnamese letters. For example, "Nước" shows up as all uppercase and the letters "uo" are shortened. ...

How can I create a dynamic height for a scrollable div?

How can I build a section with a defined height that contains a sticky header (with a dynamic height) and a scrollable body? I want the body to be scrollable, but due to the header's changing height, I'm unable to set an exact height. What should ...

Error accessing property 'offsetwidth' of null in Google Maps JavaScript API

I am currently utilizing the Google Maps JS API to showcase a map on my website. However, I am encountering an issue where the website is displaying an empty card and upon inspecting the elements, I came across the error message: Cannot read property &apos ...

Leveraging JavaScript code repeatedly

Apologies if this question has been asked before, as I couldn't find it. I have an HTML table with images used as buttons: <td> <button class="trigger"> <img src="D:\Elly Research\ CO2858\Presentation\Calypso ...

I'm noticing that my CSS is behaving differently than expected. Despite setting position: absolute, the output is displaying as inline-block instead of block. Why is this happening

div { width:200px; height:200px; position: absolute; } .first-container { background-color: #9AD0EC; } .second-container { background-color: red; left: 200px; } .third-container { background-color: blue; left:400px; } Despite setting th ...

Tips on vertically aligning a div using Bootstrap

I'm looking to vertically align a card in the center <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorig ...

Is there a way to expand this embedded video so that it spans the entire width of the screen

I have a code snippet with one row and two columns. I would like to embed a video from Vimeo in the first column so that it fills the entire column without any padding. Additionally, I want the two columns to be right next to each other with no space betwe ...

What is the process for converting x and y coordinates to align with a fixed display?

When I make an API call, I am receiving X and Y coordinates in the following format: x: "-0.0120956897735595703" y: "0.147876381874084473" To display these coordinates on my minimap images, I have set their display to be absolute. The "left" and "top" pr ...

Works well with Bootstrap but not compatible with other frameworks

Looking for assistance with a code within Bootstrap (HTML and CSS). I have been trying to create a dropdown menu (burger menu) following the Bootstrap Documentation, but I am unable to expand the burger menu (Dropdown). I have tested it on both Firefox an ...

Combine three images and position them in the center of a flexible container

Looking for assistance with overlapping 3 images and centering them within a twitter bootstrap row-fluid div. Here is an example of the desired outcome: The solution can incorporate javascript, however it is preferred to avoid it. It is also important tha ...

Conflict between Angular's ng-repeat directive and Sass styling

Currently, I am working on a project and encountering an issue that is causing some difficulty: In order to create a navigation bar with equally distributed list elements based on the number of items, I am utilizing ng-repeat for data binding and Sass for ...

Does border-padding actually exist in web design?

Looking for some assistance with styling two SVG icons. I've applied padding and now want to round the edges using border-radius, but it seems that no matter what padding amount I use, the SVGs get cut off. Here's an example of the issue with 10 ...

Tips for making a reusable function that utilizes alternating if statements

After hours of experimenting, I finally achieved a smooth scrolling effect with a bounce at the top and bottom. Now, my challenge lies in creating reusable and clean code for this implementation. Perhaps implementing an algorithm could solve this issue? T ...

What's the best way to adjust the card column for mobile view resizing?

I am trying to modify the card view for mobile devices to display as a 2-column layout. I have adjusted the flex length and grid size in my code, but I still can't achieve the desired result. Can someone guide me on how to make this change? Current d ...

How can the styles of Google Fonts be affected when the style name is appended to the font family?

When I try to use the Black style for the Montserrat font using this format: font-family: 'Montserrat-Black'; It doesn't work as expected. Instead, I have to use the following: font-family: 'Montserrat'; font-weight: 900; Why i ...

Customize Material-Table: Adjusting Detail Panel Icon Rotation upon Row Expansion

I've made a modification to the layout of the detail panel icon (mui ChevronLeft) so that it now appears on the right side of the table by using the options={{detailPanelColumnAlignment: "right"}} property. TableIcons : DetailPanel: for ...

Is it feasible to generate a vertical bar or horizontal graph using Chart.JS?

Is there a way to manipulate Chart.JS to create a horizontal bar chart with percentages displayed along the bottom, similar to this example created using xlsxwriter? View Example UPDATE I marked a certain answer as correct based on the jsfiddle provided ...

Is it possible for an SVG to derive its dimensions from the containing element?

I am currently in the process of transitioning a Vue/Vuetify application from using web fonts for Material Design Icons to utilizing SVG icons instead. With the web font, an example of a heading that includes an icon looks like this: <template> &l ...