Overlaying text over image links with ACF Gallery images - php

I'm creating a gallery with ACF and want every image in my gallery to have an effect where the image goes semi transparent and there is a text overlay in the center of each image with the caption. I've tried this which doesn't seem to work:
<?php
$images = get_field('gallery_image');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
for ($i=0; $i<count($images); $i++) {
$images[$i]['custom_image_link'] = get_field('custom_image_link', $images[$i]['id']);
}
if( $images ): ?>
<div>
<?php foreach( $images as $image ): ?>
<div class="gallery-container">
<a href="<?php echo $image['custom_image_link']; ?>">
<img class="gallery-img" src="<?php echo $image['url']; ?>" />
<div class="gallery-overlay">
<div class="gallery-text"><?php echo $image['caption']; ?></div>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
and my css is:
.gallery-container {
position: relative;
max-width: 100%;
}
.gallery-img {
display: block;
width: 100%;
height: auto;
}
.gallery-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #fff;
}
.gallery-container:hover .gallery-overlay {
opacity: 1;
}
.gallery-text p {
color: black;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
Anyone have any idea what I'm doing wrong here?

Make following changes in your CSS code.
.gallery-container {
position: relative;
}
.gallery-img {
display: block;
width: 100%;
height: auto;
}
.gallery-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
transition: .5s ease;
background-color: rgba(255,255,255,0.5);
display: flex;
align-items: center;
justify-content: center;
font-size: 50px;
}
.gallery-container:hover .gallery-overlay {
opacity: 1;
}
<div class="gallery-container">
<a href="#">
<img class="gallery-img" src="http://via.placeholder.com/400x400" />
<div class="gallery-overlay">
<div class="gallery-text">text</div>
</div>
</a>
</div>

Related

Creating slider image and text in a pure css from array output (WordPress PHP)

WordPress PHP
The problem I am facing is that it breaks the images instead of putting them on each other. The images are not well aligned as it places them below each other. I am looping through the array to get the images and texts. More also, I am planning to create a pagination with dotted lines to show the represent each image and text in the slider
<?php
$args = array(
'post_type' => 'home_page', // slug
'posts_per_page' => 3,
);
$my_query = new WP_Query( $args );
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post();
// echo get_the_ID(); using the get_the_id to have the sense if a post exists
// print_r(get_field('slider')) ;
echo '<div id="captioned-gallery"><figure class="slider">';
$slider_array = get_field('slider');
foreach($slider_array as $sub_array) {
// print_r($sub_array['slider_text']);
echo '<figure>';
echo '<img src="'.$sub_array['slider_image'].'" />';
echo '<figcaption>'.$sub_array['slider_text'].'</figcaption>';
echo '</figure>';
}
echo ' </figure></div>';
echo '<div class="sidebar"><p>'. get_field('side_bar').'</p></div>';
}
}
// Reset the `$post` data to the current post in main query.
wp_reset_postdata();
wp_reset_query();
?>
CSS File
#keyframes slide {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}
* {
box-sizing: border-box;
}
div#captioned-gallery {
width: 100%; overflow: hidden;
}
figure.slider {
position: relative; width: 500%;
font-size: 0;
animation: 30s slide infinite;
}
figure.slider figure {
width: 100%; height: auto;
display: inline-block; position: inherit;
}
figure.slider img { width: 100%; height: auto; }
figure.slider figure figcaption {
position: absolute; bottom: 0;
background: rgba(0,0,0,0.4);
color: #fff; width: 100%;
font-size: 2rem; padding: .6rem;
}
The problem is when you are using a percentage unit (like your code: width: 500%), the child's full width (width: 100%) is the same with a parent width. seams like all of them have width: 500%.
For what are you doing this, you can use vw instead of %, I created a snippet from your code and solved your problem. Note: I think it's needed some max-height that I added in some classes.
#keyframes slide {
0% { left: 0vw; }
20% { left: 0vw; }
25% { left: -100vw; }
45% { left: -100vw; }
50% { left: -200vw; }
70% { left: -200vw; }
75% { left: -300vw; }
95% { left: -300vw; }
100% { left: -400vw; }
}
* {
box-sizing: border-box;
}
div#captioned-gallery {
width: 100vw;
max-height: 100vh;
overflow: hidden;
}
figure{
margin: 0px;
padding: 0px;
}
figure.slider {
position: relative;
width: 500vw;
max-height: 100vh;
font-size: 0;
animation: 30s slide infinite;
white-space: nowrap;
}
figure.slider figure {
width: 100vw;
height: auto;
max-height: 100vh;
display: inline-block;
position: inherit;
}
figure.slider img {
width: 100%;
height: auto;
max-height: 100vh;
}
figure.slider figure figcaption {
position: absolute;
bottom: 0;
background: rgba(0,0,0,0.4);
color: #fff;
width: 100%;
font-size: 2rem;
padding: .6rem;
}
<div id="captioned-gallery">
<figure class="slider">
<figure>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/500px-Google_2015_logo.svg.png" />
<figcaption>Google</figcaption>
</figure>
<figure>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/160px-Apple_logo_black.svg.png" />
<figcaption>Apple</figcaption>
</figure>
<figure>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Microsoft_logo_%282012%29.svg/440px-Microsoft_logo_%282012%29.svg.png" />
<figcaption>Microsoft</figcaption>
</figure>
<figure>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Facebook_Logo_%282015%29_light.svg/500px-Facebook_Logo_%282015%29_light.svg.png" />
<figcaption>Facebook</figcaption>
</figure>
<figure>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/IBM_logo.svg/400px-IBM_logo.svg.png" />
<figcaption>IBM</figcaption>
</figure>
</figure>
</div>

Dynamic donut chart not correctly calculating sizes of strips

I'm trying to make a dynamic donut chart with data coming from custom fields in Wordpress.
At the moment it's not calculating the strips in the chart correctly - here's my fiddle https://jsfiddle.net/sq6mh5wp/. Just as an example I've set the four strips to be a quarter but it's only showing 3 strips, where am I going wrong?
Here's the actual template:
<div class="container">
<div class="donut-chart-block block">
<div class="donut-chart">
<?php if( have_rows( 'pie_chart' ) ):
$counter = 1; ?>
<?php while( have_rows( 'pie_chart' ) ): the_row(); ?>
<div class="clip clip-<?php echo $counter; ?>" style="transform: rotate(<?php echo the_sub_field( 'number' ); ?>deg);">
<div class="item item-<?php echo $counter; ?>" data-rel="<?php echo the_sub_field( 'number' ); ?>" style="transform: rotate(<?php echo the_sub_field( 'number' ); ?>deg);"></div>
</div>
<?php $counter++;
endwhile; ?>
<?php endif; ?>
<div class="center"></div>
</div>
</div>
</div>
Here's the CSS:
.donut-chart-block {
overflow: hidden;
}
.donut-chart {
position: relative;
width: 200px;
height: 200px;
margin: 0px;
border-radius: 100%;
margin-left: auto;
margin-right: auto;
}
.donut-chart .center {
background: white;
position: absolute;
top: 50px;
left: 50px;
height: 100px;
width: 100px;
border-radius: 70px;
}
.clip {
border-radius: 50%;
clip: rect(0px, 200px, 200px, 100px);
height: 100%;
position: absolute;
width: 100%;
}
.item {
border-radius: 50%;
clip: rect(0px, 100px, 200px, 0px);
height: 100%;
position: absolute;
width: 100%;
font-family: monospace;
font-size: 1.5rem;
}
.donut-chart .item-1 {
background-color: #178c8e;
}
.donut-chart .item-2 {
background-color: #1e5eaa;
}
.donut-chart .item-3 {
background-color: #eac947;
}
.donut-chart .item-4 {
background-color: #143753;
}
.donut-chart .item-5 {
background-color: #0faeb1;
}
Your first clip is set to 0deg rotation. However, 0 degrees on a pie chart has 0 width. Zero = Zero so you will want to change the first clip to a positive number. Then you will need to adjust the rest accordingly.
You made mistakes in calculations. You must rotate correctly.
.donut-chart-block {
overflow: hidden;
}
.donut-chart {
position: relative;
width: 200px;
height: 200px;
margin: 0px;
border-radius: 100%;
margin-left: auto;
margin-right: auto;
}
.donut-chart .center {
background: white;
position: absolute;
top: 50px;
left: 50px;
height: 100px;
width: 100px;
border-radius: 70px;
}
.clip {
border-radius: 50%;
clip: rect(0px, 200px, 200px, 100px);
height: 100%;
position: absolute;
width: 100%;
}
.item {
border-radius: 50%;
clip: rect(0px, 100px, 200px, 0px);
height: 100%;
position: absolute;
width: 100%;
font-family: monospace;
font-size: 1.5rem;
}
.donut-chart .item-1 {
background-color: #178c8e;
}
.donut-chart .item-2 {
background-color: #1e5eaa;
}
.donut-chart .item-3 {
background-color: #eac947;
}
.donut-chart .item-4 {
background-color: #143753;
}
.donut-chart .item-5 {
background-color: #0faeb1;
}
<div class="container">
<div class="donut-chart-block block">
<div class="donut-chart">
<div class="clip clip-1" style="transform: rotate(0deg);">
<div class="item item-1" data-rel="90" style="transform: rotate(90deg);"></div>
</div>
<div class="clip clip-2" style="transform: rotate(90deg);">
<div class="item item-2" data-rel="180" style="transform: rotate(90deg);"></div>
</div>
<div class="clip clip-3" style="transform: rotate(270deg);">
<div class="item item-3" data-rel="270" style="transform: rotate(90deg);"></div>
</div>
<div class="clip clip-4" style="transform: rotate(180deg);">
<div class="item item-4" data-rel="360" style="transform: rotate(90deg);"></div>
</div>
<div class="center"></div>
</div>
</div>
</div>
<!-- begin snippet: js hide: false console: true babel: false -->

How to make good view with bootstrap and html?

I have a little problem.I'm still, learn to program and I don't have very good knowledge.
I'm trying to make view like this:
In this view items are located very evenly.
In my view items are not looking good:
Why i have to repair in my code to look like this online shop view?
My code is here:
<?php foreach($posts as $post) : ?>
<div class="col-xs-12 col-sm-6 col-md-4">
<h3><?php echo $post['title']; ?></h3>
<?php if($this->session->userdata('logged_in')) :?>
<small class="post-date">Posted on: <?php echo $post['created_at']; ?> in <strong><?php echo $post['name']; ?></strong></small>
<?php endif ?>
<div class="zoom-in">
<img class="post-thumb" src="<?php echo site_url(); ?>assets/images/posts/<?php echo $post['post_image']; ?>">
</div>
<?php echo word_limiter($post['body'],10); ?>
<b></b>
<input type="button" class="btn btn-danger addcart" productid="<?php echo $post['id'] ?>" value="Добави в количката">
<p><a class="btn btn-link" href="<?php echo site_url('/posts/'.$post['slug']); ?>">Read more</a></p>
</div>
<?php endforeach; } ?>
Thank you in advance!
resize Image Like this
html, body {
color: #333;
font-size: 16px;
line-height: 20px;
}
body {
margin: 20px;
}
h1 {
line-height: 1.2;
margin-bottom: 35px;
text-align: center;
}
h2 {
text-align: center;
}
img {
height: auto;
max-width: 100%;
}
.image-grid {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin: 0 auto 35px;
max-width: 920px;
}
.svg-image-grid {
clear: both;
margin: 0 auto 35px;
max-width: 920px;
overflow: hidden;
position: relative;
}
/** Screen readers only class from Bootstrap */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0,0,0,0);
white-space: nowrap;
clip-path: inset(50%);
border: 0;
}
/** Actual code examples */
/** Background */
.image-bg {
background-position: center center;
background-size: cover;
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
margin: 5px;
width: calc(25% - 10px);
}
.image-bg-placeholder {
height: 100%;
visibility: hidden;
width: 100%;
}
/** Object-fit */
.image-fit {
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
margin: 5px;
position: relative;
width: calc(25% - 10px);
}
.image-fit-placeholder {
height: 100%;
visibility: hidden;
width: 100%;
}
.image-fit-img {
bottom: 0;
height: 100%;
left: 0;
object-fit: cover;
object-position: center;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
/** Absolute positioning */
.image {
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
margin: 5px;
overflow: hidden;
position: relative;
width: calc(25% - 10px);
}
.image-placeholder {
height: 100%;
visibility: hidden;
width: 100%;
}
.image-img {
left: 50%;
max-height: 150%;
max-width: 177%;
position: absolute;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
/** SVG */
.image-svg {
float: left;
margin: 5px;
padding-bottom: calc(25% - 10px);
position: relative;
width: calc(25% - 10px);
}
.image-svg svg {
bottom: 0;
display: block;
height: 100%;
left: 0;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
/** Responsive grid */
#media (max-width: 480px) {
.image,
.image-fit,
.image-bg,
.image-svg {
width: calc(50% - 10px);
}
.image-svg {
padding-bottom: calc(50% - 10px);
}
}
<h1>Techniques to crop and resize images with CSS</h1>
<h2>Image as a background</h2>
<div class="image-grid">
<a href="https://www.flickr.com/photos/teroauralinna/33704491300" class="image-bg" style="background-image:url(https://farm3.staticflickr.com/2809/33704491300_1df01dd919_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm3.staticflickr.com/2809/33704491300_1df01dd919_z_d.jpg" alt="Cropped image as a background example" />
</a>
<a href="https://www.flickr.com/photos/teroauralinna/33704488370" class="image-bg" style="background-image:url(https://farm3.staticflickr.com/2848/33704488370_9572b9d270_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm3.staticflickr.com/2848/33704488370_9572b9d270_z_d.jpg" alt="Cropped image as a background example" />
</a>
<a href="https://www.flickr.com/photos/teroauralinna/34088934825" class="image-bg" style="background-image:url(https://farm4.staticflickr.com/3947/34088934825_0acfe80a04_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm4.staticflickr.com/3947/34088934825_0acfe80a04_z_d.jpg" alt="Cropped image as a background example" />
</a>
<a href="https://www.flickr.com/photos/teroauralinna/34088930595" class="image-bg" style="background-image:url(https://farm4.staticflickr.com/3956/34088930595_2b84cec168_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm4.staticflickr.com/3956/34088930595_2b84cec168_z_d.jpg" alt="Cropped image as a background example" />
</a>
</div>

CSS popup doesn't carry PHP variable

I'm building a website with a CSS popup inside a loop that increments by 1, but the variable $i does not carry on the popup.
CSS
#cover {
position: fixed;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 5;
width: 100%;
height: 100%;
display: none;
}
#score {
height: 380px;
min-width: 280px;
max-width: 380px;
margin: 0 auto;
position: relative;
z-index: 10;
display: none;
background: url(login.png) no-repeat;
border: 5px solid #cccccc;
border-radius: 10px;
}
#score:target,
#score:target + #cover {
display: block;
opacity: 2;
}
.cancel {
display: block;
position: absolute;
top: 3px;
right: 2px;
background: rgb(245, 245, 245);
color: black;
height: 30px;
width: 35px;
font-size: 30px;
text-decoration: none;
text-align: center;
font-weight: bold;
}
.popup {
position: fixed;
left: 50%;
top: 20%;
}
.popup .wrapper {
position: relative;
left: -50%;
}
PHP
<?php $loopvalue = 3; $i=1; while ($i <= $loopvalue) {?>
<li>open popup <?php echo $i;?></li>
<div class="popup">
<div class="wrapper">
<div id="score" style="background-color:#FFF;">
popup # <?php echo $i;?>
×
</div>
<div id="cover" >
</div>
</div>
</div>
The popup number $i never changes. It freezes on 1. I'm not sure what's the problem. I don't see any, but I can't make the popup number change.
In your codes you have repeated the score div with same id. it need to have different ids for different divs
(This will only create proper html. for popup effect it needs to use some java script/JQuery codes)
Try this
<?php $loopvalue = 3; $i=1; while ($i <= $loopvalue) {?>
<li>open popup <?php echo $i;?></li>
<div class="popup">
<div class="wrapper">
<div id="score<?php echo $i;?>" style="background-color:#FFF;">
popup # <?php echo $i;?>
×
</div>
<div id="cover" > </div>
</div>
</div>
<?php $i++;}?>

Why are the columns stacked up?

I am making a small shop and I have a page where I display my products. The code of this page looks like this:
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
if(isset($_GET['action']) && $_GET['action']=="add"){
$id=($_GET['id']);
if(isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id]['quantity']++;
}else{
$sql_s="SELECT * FROM products
WHERE productCode='{$id}'";
$query_s=mysql_query($sql_s) or die(mysql_error());
if(mysql_num_rows($query_s)!=0){
$row_s=mysql_fetch_array($query_s);
$_SESSION['cart'][$row_s['productCode']]=array(
"quantity" => 1,
"price" => $row_s['buyPrice']
);
}else{
$message="This product id it's invalid!";
}
}
}
?>
<h1>Classic Cars</h1>
<?php
if(isset($message)){
echo "<h2>$message</h2>";
}
?>
<div class="container">
<?php
$sql="SELECT * FROM products ORDER BY productName ASC";
$query=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_array($query)) {
?>
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div class="recent-work-wrap">
<img class="img-responsive" src="images/portfolio/recent/item1.png" alt="">
<div class="overlay">
<div class="recent-work-inner">
<h3><?php echo $row['productName'] ?> </h3>
<p>€<?php echo $row['buyPrice'] ?></p>
<a class="btn btn-login" href="register.php">Add to cart</i></a>
<a class="btn btn-login" href="register.php">Read more</i></a>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
Never mind the pictures, they are all the same at the moment.
The css of this part is as follows:
#recent-works .col-xs-12.col-sm-4.col-md-3{
padding: 0;
}
.recent-work-wrap {
position: relative;
}
.recent-work-wrap img{
width: 100%;
}
.recent-work-wrap .recent-work-inner{
top: 0;
background: transparent;
opacity: .8;
width: 100%;
border-radius: 0;
margin-bottom: 0;
}
.recent-work-wrap .recent-work-inner h3{
margin: 10px 0;
}
.recent-work-wrap .recent-work-inner h3 a{
font-size: 24px;
color: #fff;
}
.recent-work-wrap .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
border-radius: 0;
background: #BDBDBD;
color: #fff;
vertical-align: middle;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
padding: 30px;
}
.recent-work-wrap .overlay .preview {
bottom: 0;
display: inline-block;
height: 35px;
line-height: 35px;
border-radius: 0;
background: transparent;
text-align: center;
color: #fff;
}
.recent-work-wrap:hover .overlay {
opacity: 1;
}
The result of the code looks like this:
Why are the columns stacked up? And how can I solve this?
HTML:
<img class="img-responsive inline-block" src="images/portfolio/recent/item1.png" alt="">
Add the below markup to your CSS:
.inline-block{ display: inline-block;}
You can try this CSS property to image:
img{
display: inline-block;
float:left;
}

Categories