Transition background-image to grey












0















Trying to make background-image smoothly fade out into transparent, with the text opacity unchanged, however I only managed a on/off transition.
Transition with opacity does not work here, since I need the text to stay opaque. Any thoughts how this could be done?



Here's my code:




.grid {
margin: 0;
padding: 0;
width: 500px;
height: 250px;
}

.flexbox {
display: flex;
flex-wrap: wrap;
flex-direction: row;
overflow: hidden;
}

#one {
width: 250px;
height: 250px;
background-color: red;
background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
background-repeat: no-repeat;
background-position: 40%;
}

#one:hover {
background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
background-repeat: no-repeat;
background-position: 40%;
height: 250px;
}

<div class="grid">
<div class="flexbox">
<div id="one">
<div id="textbox">
I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
</div>
</div>
</div>
</div>












share|improve this question



























    0















    Trying to make background-image smoothly fade out into transparent, with the text opacity unchanged, however I only managed a on/off transition.
    Transition with opacity does not work here, since I need the text to stay opaque. Any thoughts how this could be done?



    Here's my code:




    .grid {
    margin: 0;
    padding: 0;
    width: 500px;
    height: 250px;
    }

    .flexbox {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    overflow: hidden;
    }

    #one {
    width: 250px;
    height: 250px;
    background-color: red;
    background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
    background-repeat: no-repeat;
    background-position: 40%;
    }

    #one:hover {
    background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
    background-repeat: no-repeat;
    background-position: 40%;
    height: 250px;
    }

    <div class="grid">
    <div class="flexbox">
    <div id="one">
    <div id="textbox">
    I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
    </div>
    </div>
    </div>
    </div>












    share|improve this question

























      0












      0








      0








      Trying to make background-image smoothly fade out into transparent, with the text opacity unchanged, however I only managed a on/off transition.
      Transition with opacity does not work here, since I need the text to stay opaque. Any thoughts how this could be done?



      Here's my code:




      .grid {
      margin: 0;
      padding: 0;
      width: 500px;
      height: 250px;
      }

      .flexbox {
      display: flex;
      flex-wrap: wrap;
      flex-direction: row;
      overflow: hidden;
      }

      #one {
      width: 250px;
      height: 250px;
      background-color: red;
      background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      }

      #one:hover {
      background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      height: 250px;
      }

      <div class="grid">
      <div class="flexbox">
      <div id="one">
      <div id="textbox">
      I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
      </div>
      </div>
      </div>
      </div>












      share|improve this question














      Trying to make background-image smoothly fade out into transparent, with the text opacity unchanged, however I only managed a on/off transition.
      Transition with opacity does not work here, since I need the text to stay opaque. Any thoughts how this could be done?



      Here's my code:




      .grid {
      margin: 0;
      padding: 0;
      width: 500px;
      height: 250px;
      }

      .flexbox {
      display: flex;
      flex-wrap: wrap;
      flex-direction: row;
      overflow: hidden;
      }

      #one {
      width: 250px;
      height: 250px;
      background-color: red;
      background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      }

      #one:hover {
      background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      height: 250px;
      }

      <div class="grid">
      <div class="flexbox">
      <div id="one">
      <div id="textbox">
      I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
      </div>
      </div>
      </div>
      </div>








      .grid {
      margin: 0;
      padding: 0;
      width: 500px;
      height: 250px;
      }

      .flexbox {
      display: flex;
      flex-wrap: wrap;
      flex-direction: row;
      overflow: hidden;
      }

      #one {
      width: 250px;
      height: 250px;
      background-color: red;
      background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      }

      #one:hover {
      background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      height: 250px;
      }

      <div class="grid">
      <div class="flexbox">
      <div id="one">
      <div id="textbox">
      I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
      </div>
      </div>
      </div>
      </div>





      .grid {
      margin: 0;
      padding: 0;
      width: 500px;
      height: 250px;
      }

      .flexbox {
      display: flex;
      flex-wrap: wrap;
      flex-direction: row;
      overflow: hidden;
      }

      #one {
      width: 250px;
      height: 250px;
      background-color: red;
      background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      }

      #one:hover {
      background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
      background-repeat: no-repeat;
      background-position: 40%;
      height: 250px;
      }

      <div class="grid">
      <div class="flexbox">
      <div id="one">
      <div id="textbox">
      I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
      </div>
      </div>
      </div>
      </div>






      html css background-image transition






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 20:22









      B IB I

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can try to use the :: after tag, which will help you do what you expect.



          You must remember about content = "", without which the picture will not appear.
          Also remember to correctly set the z-index which is responsible for the location of the layer.



          And here's the solution for your example:






          .grid {
          margin: 0;
          padding: 0;
          width: 500px;
          height: 250px;
          }

          .flexbox {
          display: flex;
          flex-wrap: wrap;
          flex-direction: row;
          overflow: hidden;
          }

          #one {
          width: 250px;
          height: 250px;
          position: relative;
          }

          #one::after {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
          background-repeat: no-repeat;
          background-position: 40%;
          left: 0;
          top: 0;
          content: "";
          transition: opacity 0.3s, visibility 0.3s;
          }

          #textbox {
          z-index: 2;
          position: relative;
          }

          #one:hover::after {
          opacity: 0;
          transition: opacity 0.3s, visibility 0.3s;
          }

          <div class="grid">
          <div class="flexbox">
          <div id="one">
          <div id="textbox">
          I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
          </div>
          </div>
          </div>
          </div>








          share|improve this answer


























          • Thank you, it worked! While your code does exactly what I asked to help with - smooth transition to gray on :hover - it would be be just best if it also added an ease-out backwards animation. Anyway you helped me a lot, tx!

            – B I
            Nov 26 '18 at 6:47











          • @BI You are welcome. Look at it right now. Esse-out animation should work fine!

            – Maciej Wojtasik
            Nov 26 '18 at 7:01











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452555%2ftransition-background-image-to-grey%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can try to use the :: after tag, which will help you do what you expect.



          You must remember about content = "", without which the picture will not appear.
          Also remember to correctly set the z-index which is responsible for the location of the layer.



          And here's the solution for your example:






          .grid {
          margin: 0;
          padding: 0;
          width: 500px;
          height: 250px;
          }

          .flexbox {
          display: flex;
          flex-wrap: wrap;
          flex-direction: row;
          overflow: hidden;
          }

          #one {
          width: 250px;
          height: 250px;
          position: relative;
          }

          #one::after {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
          background-repeat: no-repeat;
          background-position: 40%;
          left: 0;
          top: 0;
          content: "";
          transition: opacity 0.3s, visibility 0.3s;
          }

          #textbox {
          z-index: 2;
          position: relative;
          }

          #one:hover::after {
          opacity: 0;
          transition: opacity 0.3s, visibility 0.3s;
          }

          <div class="grid">
          <div class="flexbox">
          <div id="one">
          <div id="textbox">
          I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
          </div>
          </div>
          </div>
          </div>








          share|improve this answer


























          • Thank you, it worked! While your code does exactly what I asked to help with - smooth transition to gray on :hover - it would be be just best if it also added an ease-out backwards animation. Anyway you helped me a lot, tx!

            – B I
            Nov 26 '18 at 6:47











          • @BI You are welcome. Look at it right now. Esse-out animation should work fine!

            – Maciej Wojtasik
            Nov 26 '18 at 7:01
















          0














          You can try to use the :: after tag, which will help you do what you expect.



          You must remember about content = "", without which the picture will not appear.
          Also remember to correctly set the z-index which is responsible for the location of the layer.



          And here's the solution for your example:






          .grid {
          margin: 0;
          padding: 0;
          width: 500px;
          height: 250px;
          }

          .flexbox {
          display: flex;
          flex-wrap: wrap;
          flex-direction: row;
          overflow: hidden;
          }

          #one {
          width: 250px;
          height: 250px;
          position: relative;
          }

          #one::after {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
          background-repeat: no-repeat;
          background-position: 40%;
          left: 0;
          top: 0;
          content: "";
          transition: opacity 0.3s, visibility 0.3s;
          }

          #textbox {
          z-index: 2;
          position: relative;
          }

          #one:hover::after {
          opacity: 0;
          transition: opacity 0.3s, visibility 0.3s;
          }

          <div class="grid">
          <div class="flexbox">
          <div id="one">
          <div id="textbox">
          I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
          </div>
          </div>
          </div>
          </div>








          share|improve this answer


























          • Thank you, it worked! While your code does exactly what I asked to help with - smooth transition to gray on :hover - it would be be just best if it also added an ease-out backwards animation. Anyway you helped me a lot, tx!

            – B I
            Nov 26 '18 at 6:47











          • @BI You are welcome. Look at it right now. Esse-out animation should work fine!

            – Maciej Wojtasik
            Nov 26 '18 at 7:01














          0












          0








          0







          You can try to use the :: after tag, which will help you do what you expect.



          You must remember about content = "", without which the picture will not appear.
          Also remember to correctly set the z-index which is responsible for the location of the layer.



          And here's the solution for your example:






          .grid {
          margin: 0;
          padding: 0;
          width: 500px;
          height: 250px;
          }

          .flexbox {
          display: flex;
          flex-wrap: wrap;
          flex-direction: row;
          overflow: hidden;
          }

          #one {
          width: 250px;
          height: 250px;
          position: relative;
          }

          #one::after {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
          background-repeat: no-repeat;
          background-position: 40%;
          left: 0;
          top: 0;
          content: "";
          transition: opacity 0.3s, visibility 0.3s;
          }

          #textbox {
          z-index: 2;
          position: relative;
          }

          #one:hover::after {
          opacity: 0;
          transition: opacity 0.3s, visibility 0.3s;
          }

          <div class="grid">
          <div class="flexbox">
          <div id="one">
          <div id="textbox">
          I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
          </div>
          </div>
          </div>
          </div>








          share|improve this answer















          You can try to use the :: after tag, which will help you do what you expect.



          You must remember about content = "", without which the picture will not appear.
          Also remember to correctly set the z-index which is responsible for the location of the layer.



          And here's the solution for your example:






          .grid {
          margin: 0;
          padding: 0;
          width: 500px;
          height: 250px;
          }

          .flexbox {
          display: flex;
          flex-wrap: wrap;
          flex-direction: row;
          overflow: hidden;
          }

          #one {
          width: 250px;
          height: 250px;
          position: relative;
          }

          #one::after {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
          background-repeat: no-repeat;
          background-position: 40%;
          left: 0;
          top: 0;
          content: "";
          transition: opacity 0.3s, visibility 0.3s;
          }

          #textbox {
          z-index: 2;
          position: relative;
          }

          #one:hover::after {
          opacity: 0;
          transition: opacity 0.3s, visibility 0.3s;
          }

          <div class="grid">
          <div class="flexbox">
          <div id="one">
          <div id="textbox">
          I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
          </div>
          </div>
          </div>
          </div>








          .grid {
          margin: 0;
          padding: 0;
          width: 500px;
          height: 250px;
          }

          .flexbox {
          display: flex;
          flex-wrap: wrap;
          flex-direction: row;
          overflow: hidden;
          }

          #one {
          width: 250px;
          height: 250px;
          position: relative;
          }

          #one::after {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
          background-repeat: no-repeat;
          background-position: 40%;
          left: 0;
          top: 0;
          content: "";
          transition: opacity 0.3s, visibility 0.3s;
          }

          #textbox {
          z-index: 2;
          position: relative;
          }

          #one:hover::after {
          opacity: 0;
          transition: opacity 0.3s, visibility 0.3s;
          }

          <div class="grid">
          <div class="flexbox">
          <div id="one">
          <div id="textbox">
          I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
          </div>
          </div>
          </div>
          </div>





          .grid {
          margin: 0;
          padding: 0;
          width: 500px;
          height: 250px;
          }

          .flexbox {
          display: flex;
          flex-wrap: wrap;
          flex-direction: row;
          overflow: hidden;
          }

          #one {
          width: 250px;
          height: 250px;
          position: relative;
          }

          #one::after {
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 100%;
          background: url('https://doorcountypulse.com/wp-content/uploads/2018/03/1-PP-3-9-18-Raccoon-at-cracked-corn-660x440.jpg');
          background-repeat: no-repeat;
          background-position: 40%;
          left: 0;
          top: 0;
          content: "";
          transition: opacity 0.3s, visibility 0.3s;
          }

          #textbox {
          z-index: 2;
          position: relative;
          }

          #one:hover::after {
          opacity: 0;
          transition: opacity 0.3s, visibility 0.3s;
          }

          <div class="grid">
          <div class="flexbox">
          <div id="one">
          <div id="textbox">
          I need this picture to smoothly fade into transparent (grey) and this text to stay opaque.
          </div>
          </div>
          </div>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 6:56

























          answered Nov 23 '18 at 20:41









          Maciej WojtasikMaciej Wojtasik

          4315




          4315













          • Thank you, it worked! While your code does exactly what I asked to help with - smooth transition to gray on :hover - it would be be just best if it also added an ease-out backwards animation. Anyway you helped me a lot, tx!

            – B I
            Nov 26 '18 at 6:47











          • @BI You are welcome. Look at it right now. Esse-out animation should work fine!

            – Maciej Wojtasik
            Nov 26 '18 at 7:01



















          • Thank you, it worked! While your code does exactly what I asked to help with - smooth transition to gray on :hover - it would be be just best if it also added an ease-out backwards animation. Anyway you helped me a lot, tx!

            – B I
            Nov 26 '18 at 6:47











          • @BI You are welcome. Look at it right now. Esse-out animation should work fine!

            – Maciej Wojtasik
            Nov 26 '18 at 7:01

















          Thank you, it worked! While your code does exactly what I asked to help with - smooth transition to gray on :hover - it would be be just best if it also added an ease-out backwards animation. Anyway you helped me a lot, tx!

          – B I
          Nov 26 '18 at 6:47





          Thank you, it worked! While your code does exactly what I asked to help with - smooth transition to gray on :hover - it would be be just best if it also added an ease-out backwards animation. Anyway you helped me a lot, tx!

          – B I
          Nov 26 '18 at 6:47













          @BI You are welcome. Look at it right now. Esse-out animation should work fine!

          – Maciej Wojtasik
          Nov 26 '18 at 7:01





          @BI You are welcome. Look at it right now. Esse-out animation should work fine!

          – Maciej Wojtasik
          Nov 26 '18 at 7:01




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452555%2ftransition-background-image-to-grey%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'