z-index and <a href> - php

I have a sequence of 5 user images that I am stacking horizontally using a z-index. i.e: <img src="xxxx" style="z-index:5;position:relative;"> and then z-index 4...3..etc.
I now want to link these images to the user's 'profile'. If I surround my <img> with an <a> it breaks the formatting. It just shows the images in a line (with the z-indexes still correct(!?)) instead of overlapped. I tried just <img> and also <img> but nothing has worked.
<?php $count = 5; ?>
<?php foreach($today_all_result as $today_all_results) : ?>
<a href="<?php echo BASE_URI; ?>/user/?user=<?php echo $today_all_results->user_id; ?>" style="position:relative;z-index:<?php echo $count; ?>">
<img src='<?php echo BASE_URI; ?>/images/userImages/<?php echo $today_all_results->userPicture; ?>' class="pic-athlete <?php echo $stacked; ?>" style="z-index:<?php echo $count; ?>;position:relative;">
</a>
<?php $count--; ?>
<?php $stacked = "stacked"; ?>
<?php if($count <= 0) break; ?>
<?php endforeach; ?>
Does anyone know how to fix this? Thank you in advance!

Change the style from position: relative; to position: absolute;
img{
height: 100px;
width: 100px;
position: absolute;
}
<img src="" style="background-color: blue; z-index: 10;"/>
<img src="" style="background-color: green; z-index: 2;"/>
<img src="" style="background-color: red; z-index: 3;"/>
Another example:
img{
height: 100px;
width: 100px;
position: absolute;
}
<img src="" style="background-color: blue; z-index: 1;"/>
<img src="" style="background-color: green; z-index: 2; left: 20px; top: 20px;"/>
<img src="" style="background-color: red; z-index: 3;left: 40px; top: 40px;"/>

Related

Play button over thumbnail with CSS

I'm trying to display play button over a thumbnail with CSS in my WordPress. I tried many methods but always is bad. Can you help me, where I am wrong?
.post-thumbnail-sidebar {
display: block;
text-align: center;
}
.post-thumbnail-sidebar embed,
.post-thumbnail-sidebar iframe,
.post-thumbnail-sidebar object {
margin-bottom: 30px;
}
.post-thumbnail-sidebar a {
position: absolute;
display: block;
background: url("https://i.imgur.com/FPwyRnP.png") no-repeat;
height: 85px;
width: 136px;
top: 100%;
left: 100%;
margin: -64px 0 0 -88px;
}
<a class="post-thumbnail-sidebar" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( $r_post_thumb_size, array( 'itemprop' => 'image' ) ); ?>
</a>
Not enough but i think you can start with this.
here's a fiddle
.second-img {
position: absolute;
top: 0px;
margin-left: 20px
}
<div>
<img class="background-img" width="100%" height="100%" style="position:absolute; top:0; left:0;" src= "https://vincentloy.files.wordpress.com/2012/01/in-time-2011-r5-line-xvid-fusion_screenshot_4.jpg">
<img class="second-img" width="100%" height="100%" src = "http://sanyangfrp.com/data/out/805/511806414-play-button-png.png" />
</div>

How to add border to a image when its appeared?

I have a button to choose an image and i have a space where i want to show a preview of that image. This space is just above of that button.
Now I want to add a dashed border on this image and border opacity should be 0.47. But the problem is I have already inserted image tag in my code and i'm just changing the <img src=""> dynamically using JS & that is why i can see the border even before choosing an image.
I want this kind of thing:
When image is there its perfectly fine, like this:
But image is not there its showing a small border just above the post button, like this:
Here is my HTML/PHP code :
<div>
<div id="post-image-content">
<div id="post-image-div">
<img id="blah" class="post-image" alt=" " width="100" height="100"/>
<img id="closes" class="close-button-image" src="<?php echo $this->webroot.'mainsite/img/img-close.png'?>" />
</div>
</div>
<a href="#">
<i class="fa fa-camera" aria-hidden="true" id="capture_image_01"></i>
</a>
<?php echo $this->Form->input('cover_image_url', array('type' => 'file','onchange' => 'document.getElementById(\'blah\').src = window.URL.createObjectURL(this.files[0])','style' => array("display:none"),'label' => false, 'div' => false));?>
</div>
And here is my CSS
.post-image {
margin-bottom: 10px;
margin-left: 10px;
border-radius: 4px;
opacity: 0.5;
border: 2px dashed rgba(20, 134, 171, 0.47);
padding: 3px;
}
#post-image-content {
display: block;
overflow: hidden;
}
#post-image-div {
position:relative;
z-index:0;
float: right;
margin: 2px 2px;
}
#post-image-div:hover .close-button-image {
position: absolute;
right: 6px;
top: 8px;
display: block !important;
z-index: 1;
height: 10px;
width: 10px;
}
.close-button-image {
position: absolute;
right: 6px;
top: 8px;
display: none;
z-index: 1;
height: 10px;
width: 10px;
}
Any help would be highly appreciated as i don't have any clue now.
You can add condition before image, if no default image or img tag not needed to shown
<?php if ($image): ?>
<img id="blah" class="post-image" alt=" " width="100" height="100"/>
<?php endif ?>
or add condition to that class only (apply required css)
<img id="blah" class="<?php echo $image ? 'post-image' : '' ?>" alt=" " width="100" height="100"/>
#post-image-div{
border: 2px dashed rgba(20, 134, 171, 0.47);
padding:2px;
border-radius:3px;
}
#post-image-div img,#post-image-div{
width:100px;
height:100px;
<div id="post-image-div">
<img id="closes" class="close-button-image" src="https://static.pexels.com/photos/33109/fall-autumn-red-season.jpg" />
</div>
try this code

Is it possible to style the placeholder text of the <img> element?

I'm building site a with store images, although some stores don't have an available image. The best I can do is use its placeholder text to display the store title. However, by default the placeholder text is located at the top left of the div and is unstyled.
How can I target the placeholder text to style it??
UPDATE
Ok, maybe I should mention that I'm using WordPress. Perhaps using a simple PHP if else statement would suffice?? Show img if it exists, else show h4 element that I can add in.
Put the text into a and style it as you would for any other html element.
<div class="store-title">
This is where the store name goes.
</div>
If the text is already into an HTML element you can not modify you will have to use existing class or id to hook up to it and style it.
Of you can style the <img> element as well.
You can use line-height to vertically center:
HTML
<img title="Test Text" src="http://example.com/i-dont-exist.png" width="200" height="200" onerror="this.classList.add('no-image')" />
CSS
img.no-image {
color: red;
font-size: 20px;
line-height: 200px;
text-align: center;
}
JSFiddle demo: https://jsfiddle.net/ugr6gp8n/2/
Here's another way to style alt text but it only works in Chrome so it's not recommended:
HTML
<img title="Test Text" src="http://example.com/i-dont-exist.png" width="200" height="200" onerror="this.classList.add('no-image')" />
CSS
img[title] {
position: relative;
}
img[title]:after {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #fff;
color: red;
line-height: 200px;
text-align: center;
content: attr(title);
}
JSFiddle Demo: https://jsfiddle.net/cxa37mLd/1/
Sources:
Can I style an image's ALT text with CSS?
Positioning image alt text
CSS :after not adding content to certain elements
Why doesn't line-height work on img elements?
You can style some properties directly on img:
img {
color:red;
font-size:20px;
text-align:center;
line-height:200px;
}
<img title="Test Text" src="http://exmaple.com/123.jpg" width="200" height="200"/>
UPDATE 2
Ok this is resolved
HTML/PHP:
<?php if(have_posts() ) : while (have_posts() ) :the_post(); ?>
<div class="col-xs-12 col-sm-6 col-md-4">
<a class="store-item-link" href="<?php the_permalink(); ?>">
<div class="store-item" style="border-bottom: 10px solid <?php the_field('color'); ?>">
/* Starting here */
<?php if(wp_get_attachment_url(get_post_thumbnail_id()) == ''):?>
<h3><?php the_title(); ?></h3>
<?php else: ?>
<img src="<?php echo wp_get_attachment_url(get_post_thumbnail_id()); ?>">
<?php endif; ?>
/* Ending here */
</div>
</a>
</div>
<?php endwhile; endif; ?>
CSS
h3{
margin: 0;
font-weight: bold;
font-size: 3rem;
line-height: 175px;
text-align: center;
}
This worked great and thanks everyone for your ideas.

Modal box content depends of custom field

I'm trying to display 2 different content in a modal box using featherlight.js. It's very simple :
If there is an 'image', it displays the 'image', otherwise if there is a 'soundcloud url', it displays a 'soundcloud url' iframe.
But it doesn't work!
Here is my website
And here is the code
<div id="post">
<a href="#" data-featherlight="#featherlight">
<div class="img">
<div class="art-overlay">
<div class="small">
<img src="<?php echo get_template_directory_uri(); ?>/images/skuar_small.png" alt="skuar" />
</div>
</div>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('post-thumbnails');
}
?>
<?php
if( get_field( 'image' ) ) { ?>
<?php the_field( 'image' ); ?>
<?php }
else { ?>
<iframe width="600" height="166" scrolling="no" class="lightbox" class="frame" id="featherlight" frameborder="no" src="https://w.soundcloud.com/player/?url=<?php the_field( 'music' ); ?>&color=1b1e25&theme_color=1b1e25&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false"></iframe>
<?php endif; ?><?php } ?>
</div>
</a>
</div>
If you have a look now, using featherlight.js it works : skuar.com
Just because I removed the overlay on thumbnails!
Is there any way to add this very simple overlay?
<div class="art-overlay">
<div class="small">
<img src="<?php echo get_template_directory_uri(); ?>/images/skuar_small.png" alt="skuar" />
</div>
.art-overlay {
display: flex;
background: rgba(0,0,0,0.2);
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
opacity: 0;
-webkit-transition: opacity 300ms;
transition: opacity 300ms;
.small {
margin: auto;
width: 59px;
height: 75px;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
}
#post:hover .art-overlay {
opacity: 1;
cursor: pointer;
}

Display database content in 3 blocks

I am using a table to display information from my database but I'm having trouble formatting the CSS. Right now I have 12 icons and the respective name on the right and the problem is that everything is displayed like a list, one below the other and I wanted to break the list in three blocks, like this:
EDIT I don't need necessarily to do it with tables, I just need to display the values like this, dynamically. Because later I'd probably going to add more plants to database and I want them to be always listed like this.
This is my html:
<table id="plantslist">
<?php
foreach($resultado as $planta){ ?>
<tr>
<td><img src="http://www.coisas.pt/coisas/backoffice/<?php echo $planta['icon']; ?>"></img></td>
<td><a href="blabla.php?name=<?php echo $planta['name']?>&img=<?php echo $planta['img']?>&tagline=<?php echo $planta['tagline']?>&hum=<?php echo $planta['hum']?>&lum=<?php echo $planta['lum']?>&temp=<?php echo $planta['temp']?>&seed=<?php echo $planta['seed']?>&spacing=<?php echo $planta['spacing']?>&info1=<?php echo $planta['info1']?>&info2=<?php echo $planta['info2']?>&info3=<?php echo $planta['info3']?>&info4=<?php echo $planta['info4']?>">
<?php echo $planta['name'];?></a></td>
</tr>
<?php } ?>
</table>
CSS:
#plantslist {
border: 3px solid white;
overflow: scroll;
font-size: 1.7vw;
line-height: 2.8vw;
font-family: Robotomedium;
margin-top: 11%;
text-align: left;
}
#plantslist img {width: 2.3vw;}
#plantslist tr td {
display: inline-block;
vertical-align: top;
}
You can do a container with width: 100%; then make child elements with width: 33% each one. To make them place one next to other you can use float: left;. Here is an example.
.table {
width: 100%;
float: left;
}
.table > .items {
width: 33%;
float: left;
}
.table > .items:before {
content: "";
display: block;
background: url(http://placehold.it/20/000) no-repeat;
width: 20px;
height: 20px;
float: left;
margin: 0 6px 0 0;
}
<div class="table">
<div class="items">1</div>
<div class="items">2</div>
<div class="items">3</div>
<div class="items">4</div>
<div class="items">5</div>
<div class="items">6</div>
<div class="items">7</div>
<div class="items">8</div>
<div class="items">9</div>
</div>
Look that your icon it's placed with before pseudo element. You should change background value with the correct url.
EDIT
Use this if you have different images per plant.
.table {
width: 100%;
float: left;
}
.table > .items {
width: 33%;
float: left;
}
.table > .items img {
width: 20px;
height: 20px;
margin: 0 10px 0 0;
float: left;
}
<div class="table">
<div class="items">
<img src="http://placehold.it/20/dfa9a9" alt=""> 1
</div>
<div class="items">
<img src="http://placehold.it/20/dfa9de" alt=""> 2
</div>
<div class="items">
<img src="http://placehold.it/20/b1a9df" alt=""> 3
</div>
<div class="items">
<img src="http://placehold.it/20/a9cadf" alt=""> 4
</div>
<div class="items">
<img src="http://placehold.it/20/dfd8a9" alt=""> 5
</div>
<div class="items">
<img src="http://placehold.it/20/5cff46" alt=""> 6
</div>
<div class="items">
<img src="http://placehold.it/20/dfa9a9" alt=""> 7
</div>
<div class="items">
<img src="http://placehold.it/20/a9cadf" alt=""> 8
</div>
<div class="items">
<img src="http://placehold.it/20/a9cadf" alt=""> 9
</div>
</div>
Using your PHP code
HTML | PHP
<div class="table">
<?php
foreach($resultado as $planta){
?>
<div class="items">
<img src="http://www.growbox.pt/growbox/backoffice/<?php echo $planta['icon']; ?>" alt="<?php echo $planta['name'];?>">
<a href="intips.php?name=<?php echo $planta['name']?>&img=<?php echo $planta['img']?>&tagline=<?php echo $planta['tagline']?>&hum=<?php echo $planta['hum']?>&lum=<?php echo $planta['lum']?>&temp=<?php echo $planta['temp']?>&seed=<?php echo $planta['seed']?>&spacing=<?php echo $planta['spacing']?>&info1=<?php echo $planta['info1']?>&info2=<?php echo $planta['info2']?>&info3=<?php echo $planta['info3']?>&info4=<?php echo $planta['info4']?>"><?php echo $planta['name'];?>
</a>
</div>
<?php
}
?>
</div>
CSS
.table {
width: 100%;
float: left;
}
.table > .items {
width: 33%;
float: left;
}
.table > .items img {
width: 20px;
height: 20px;
margin: 0 10px 0 0;
float: left;
}
See if this works. I'm just creating more elements so that you have 3 sets of tds per row. Ideally, though, I wouldn't do this with tables. I'd do something like arglab suggested with divs, but here I'm just showing you how I'd do it with tables since that was your question. Make your divs inline blocks with width 33% and you should be good. You may also need to do box-sizing: border-box so that way any padding and margins get automatically put into the calculation for you.
<table id="plantslist">
<?php $count = 0; ?>
<tr>
<?php foreach($resultado as $planta) {
if (count === 2) {
count = 0; ?>
<td><img src="http://www.growbox.pt/growbox/backoffice/<?php echo $planta['icon']; ?>"></img></td>
<td><a href="intips.php?name=<?php echo $planta['name']?>&img=<?php echo $planta['img']?>&tagline=<?php echo $planta['tagline']?>&hum=<?php echo $planta['hum']?>&lum=<?php echo $planta['lum']?>&temp=<?php echo $planta['temp']?>&seed=<?php echo $planta['seed']?>&spacing=<?php echo $planta['spacing']?>&info1=<?php echo $planta['info1']?>&info2=<?php echo $planta['info2']?>&info3=<?php echo $planta['info3']?>&info4=<?php echo $planta['info4']?>">
<?php echo $planta['name'];?></a></td>
</tr>
<tr>
<?php }
else {
$count += 1;
// If this doesn't work, try $count = $count + 1;
<td><img src="http://www.growbox.pt/growbox/backoffice/<?php echo $planta['icon']; ?>"></img></td>
<td><a href="intips.php?name=<?php echo $planta['name']?>&img=<?php echo $planta['img']?>&tagline=<?php echo $planta['tagline']?>&hum=<?php echo $planta['hum']?>&lum=<?php echo $planta['lum']?>&temp=<?php echo $planta['temp']?>&seed=<?php echo $planta['seed']?>&spacing=<?php echo $planta['spacing']?>&info1=<?php echo $planta['info1']?>&info2=<?php echo $planta['info2']?>&info3=<?php echo $planta['info3']?>&info4=<?php echo $planta['info4']?>">
}
?>
</table>
SOLUTION WITH DIVS: See if this works...
<div id="plantslist">
<?php foreach($resultado as $planta) { ?>
<div class="plant">
<img src="http://www.growbox.pt/growbox/backoffice/<?php echo $planta['icon']; ?>"></img>
<a href="intips.php?name=<?php echo $planta['name']?>&img=<?php echo $planta['img']?>&tagline=<?php echo $planta['tagline']?>&hum=<?php echo $planta['hum']?>&lum=<?php echo $planta['lum']?>&temp=<?php echo $planta['temp']?>&seed=<?php echo $planta['seed']?>&spacing=<?php echo $planta['spacing']?>&info1=<?php echo $planta['info1']?>&info2=<?php echo $planta['info2']?>&info3=<?php echo $planta['info3']?>&info4=<?php echo $planta['info4']?>">
<?php echo $planta['name'];?></a>
</div>
<?php } ?>
</div>
CSS
#planstslist{
width: 100%;
/* this may help if the items don't stack properly */
white-space: nowrap;
}
.plant{
width: 33.33%
display: inline-block;
/* this may help if the items don't stack properly */
white-space: normal;
}
You may need to make the images inline blocks and set them and the links to have percentage width values adding up to no more than 100%. You may also need to add box-sizing: border-box; to the "plant" divs. I usually get in the habit of making the following declaration on all my CSS files: * {box-sizing: border-box};
I think it's enough if you simply erase display: inline-block; from this CSS rule;
#plantslist tr td {
display: inline-block;
vertical-align: top;
}
displayshould be table-cell, not inline-block, which is the default anyway in a <td> element. Also vertical-align: top; wouldn't be necessary, so you might as well erase the whole rule...

Categories