logo

Box texte hover avec background

VERSION 1

 

HTML wordpress :

<div class="container">
    <div class="columns is-multiline is-centered photos">
      <?php if (have_posts()): while (have_posts()) : the_post(); ?>
          <article class="column is-half-tablet is-one-quarter-desktop anime16">
              <figure>
                <?php if (has_post_thumbnail() ) {
                  the_post_thumbnail('thumbnail'); 
                  } else {
                  $curdir=getcwd(); chdir(get_template_directory() . "/css/img/random/");
                  $files=glob("*.{gif,png,jpg,gif}", GLOB_BRACE);
                  chdir($curdir);
                  $file=$files[array_rand($files)];
                ?>
                  <img src="<?php echo(get_bloginfo('template_url')."/css/img/random/$file"); ?>" alt="<?php bloginfo( 'name' ); ?>" />
                <?php } ?>
                  <figcaption>
                      <a href="<?= the_permalink() ?>">
                        <h2 class="has-text-white"><?= the_title() ?></h2>
                        <p><?= the_excerpt() ?></p>
                      </a>
                  </figcaption>     
              </figure>
          </article><!-- /column -->
      <?php endwhile; ?>
      <?php else: ?>
      <div>
        <h2>
          <?php _e( 'Sorry, nothing to display.', 'emandarine' ); ?>
        </h2>
      </div>
      <?php endif; ?>
    </div><!-- /columns -->
  </div><!-- /container -->

CSS :

.anime16 figure {
  color: #fff;
  position: relative;
  overflow: hidden;
  background: #000000;
  text-align: left;
  padding: 10px;
}
.anime16 figure figcaption {
  position: absolute;
  display: flex;
  flex-flow: column nowrap;
  justify-content: end;
  bottom: 0;
  left: 0;
  padding-top: 30px 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0);
  opacity: 0.9; 
}
.anime16 figure a {
  padding: 0 10px;
}
.anime16 figure h2,
  .anime16 figure p {
    margin: 0!important;
    padding: 10px 5px;
    background-color: rgb(0 0 0 / 70%);
}
.anime16 figure p {
  margin-bottom: 15px!important;
  color: white;
}
@media screen and (min-width:768px) {
  .anime16 figure a {
    padding: 0 ;
  }
  .anime16 figure h2,
  .anime16 figure p {
    background-color: unset;
}
  .anime16 figure * {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }
  .anime16 figure img {
    max-width: 100%;
    opacity: 1;
    width: 100%;
    -webkit-transition: opacity 0.35s;
    transition: opacity 0.35s;
  }
  .anime16 figure figcaption {
    display: block;
    position: absolute;
    bottom: 0;
    left: 0;
    padding: 30px 3em;
    width: 100%;
    height: 100%;
  }
  .anime16 figure figcaption::before {
    position: absolute;
    top: 30px;
    right: 30px;
    bottom: 30px;
    left: 100%;
    border-left: 4px solid rgba(255, 255, 255, 0.8);
    content: '';
    opacity: 0;
    background-color: rgba(255, 255, 255, 0.5);
    -webkit-transition: all 0.5s;
    transition: all 0.5s;
    -webkit-transition-delay: 0.6s;
    transition-delay: 0.6s;
  }
  .anime16 figure h2,
  .anime16 figure p {
    margin: 0 0 5px;
    opacity: 0;
    -webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
    transition: opacity 0.35s,-webkit-transform 0.35s,-moz-transform 0.35s,-o-transform 0.35s,transform 0.35s;
  }
  .anime16 figure h2 {
    word-spacing: -0.15em;
    font-weight: 300;
    text-transform: uppercase;
    -webkit-transform: translate3d(30%, 0%, 0);
    transform: translate3d(30%, 0%, 0);
    -webkit-transition-delay: 0.3s;
    transition-delay: 0.3s;
  }
  .anime16 figure p {
    font-weight: 200;
    -webkit-transform: translate3d(0%, 30%, 0);
    transform: translate3d(0%, 30%, 0);
    -webkit-transition-delay: 0s;
    transition-delay: 0s;
    /* couper le texte s'il est trop long */
    max-height: 40%;
    overflow: hidden;
  }
  .anime16 figure a {
    top: 0;
    color: #ffffff;
    overflow: hidden;
  }
  .anime16 figure:hover img {
    opacity: 0.3;
  }
  .anime16 figure:hover figcaption h2 {
    opacity: 1;
    -webkit-transform: translate3d(0%, 0%, 0);
    transform: translate3d(0%, 0%, 0);
    -webkit-transition-delay: 0.4s;
    transition-delay: 0.4s;
  }
  .anime16 figure:hover figcaption p {
    opacity: 0.9;
    -webkit-transform: translate3d(0%, 0%, 0);
    transform: translate3d(0%, 0%, 0);
    -webkit-transition-delay: 0.6s;
    transition-delay: 0.6s;
  }
  .anime16 figure:hover figcaption::before {
    background: rgba(255, 255, 255, 0);
    left: 30px;
    opacity: 1;
    -webkit-transition-delay: 0s;
    transition-delay: 0s;
  }
}

 

VESRION 2 :

HTML wordpress :

<?php get_header(); ?>

<!-- Blog -->
<main class="section blog">
<div class="container">
<div class="columns is-multiline is-centered">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="column is-half-tablet is-one-quarter-desktop is-full-mobile actu" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<figure class="hovcap is-centered">
<?php if (has_post_thumbnail()) {
the_post_thumbnail('thumbnail');
} else {
$curdir = getcwd();
chdir(get_template_directory() . "/css/img/random/");
$files = glob("*.{gif,png,jpg,gif}", GLOB_BRACE);
chdir($curdir);
$file = $files[array_rand($files)];
?>
<img class="image" src="<?php echo (get_bloginfo('template_url') . "/css/img/random/$file"); ?>" alt="<?php bloginfo('name'); ?>" />
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<figcaption class="column is-multiline is-vcentered">
<h2 class="subtitle3 mgt-0 column is-full"><?php the_title(); ?></h2>
<p class="content column is-full"><?php the_excerpt(); ?></p>
</a>
</figcaption>
<?php } ?>
</figure>
</article>
<?php endwhile; ?>
</div><!-- /column-->
</div><!-- /container -->
<?php else : ?>
<div>
<h2>
<?php _e('Sorry, nothing to display.', 'emandarine'); ?>
</h2>
</div>
<?php endif; ?>

<!-- Pagination -->

<nav class="pagination is-centered" aria-label="pagination">
<?php echo bulma_pagination(); ?>
</nav>

</main>

<?php get_footer(); ?>

 

CSS :

figure.hovcap {
margin: 0 auto;
color: var(--white);
position: relative;
overflow: hidden;
width: 100%;
background: var(--black);
text-align: center;
}
figure.hovcap * {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
figure.hovcap img {
opacity: 1;
width: 100%;
-webkit-transition: opacity 0.35s;
transition: opacity 0.35s;
}
figure.hovcap figcaption {
background-color: #0000009a;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 50%;
}

figure.hovcap h2,
figure.hovcap p {
padding: 0.5em;
margin: 0 0 5px;
}
figure.hovcap h2 {
color: var(--white);
word-spacing: -0.15em;
font-weight: 300;
text-transform: uppercase;
}
figure.hovcap h2 span {
font-weight: 800;
}
figure.hovcap p {
font-weight: 200 ;
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
figure.hovcap a {
color: var(--white);
}

@media screen and (min-width: 768px) {
figure.hovcap figcaption {
background-color: transparent;
height: 100%;
}
figure.hovcap figcaption::before {
position: absolute;
top: 50%;
right: 15px;
bottom: 50%;
left: 15px;
border-top: 1px solid rgba(255, 255, 255, 0.8);
border-bottom: 1px solid rgba(255, 255, 255, 0.8);
content: '';
opacity: 0;
background-color: var(--white);
-webkit-transition: all 0.4s;
transition: all 0.4s;
-webkit-transition-delay: 0.6s;
transition-delay: 0.6s;
}
figure.hovcap h2,
figure.hovcap p {
padding: 1em;
margin: 0 0 5px;
opacity: 0;
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s,-webkit-transform 0.35s,-moz-transform 0.35s,-o-transform 0.35s,transform 0.35s;
}
figure.hovcap h2 {
-webkit-transform: translate3d(0%, 50%, 0);
transform: translate3d(0%, 50%, 0);
-webkit-transition-delay: 0.3s;
transition-delay: 0.3s;
}
figure.hovcap:hover img {
opacity: 0.35;
}
figure.hovcap:hover figcaption h2 {
opacity: 1;
-webkit-transform: translate3d(0%, 0%, 0);
transform: translate3d(0%, 0%, 0);
-webkit-transition-delay: 0.3s;
transition-delay: 0.3s;
}
figure.hovcap:hover figcaption p {
opacity: 0.9;
-webkit-transition-delay: 0.6s;
transition-delay: 0.6s;
}
figure.hovcap:hover figcaption::before {
background: rgba(255, 255, 255, 0);
top: 15px;
bottom: 15px;
opacity: 1;
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
}