automatic (not hover) css overlay depending on database field content - php

I want to make the following bootstrap code automatically show an overlay for two out of three options contained in a database field. They are SOLD, CONTRACT, and NO.
I want different overlays for SOLD and CONTRACT, and no overlay for NO
I have searched for overlays, most tutorials have on hover events, and I am lost as to how to do this.
<div class="row">
<div class="col-md-6 col-md-offset-3">
<a href="listing_show.php?ID=<?php echo($Recordset1->getColumnVal("ID")); ?>">
<img src="images/<?php echo($Recordset1->getColumnVal("IMAGE")); ?>" class="img-responsive center-block sold" alt="<?php echo($Recordset1->getColumnVal("TITLE")); ?>"/>
</a>
</div><br><br>
</div>

I worked it out through a couple of js fiddles on other questions here, if it helps anyone here is the code I added...
html
I added a thumbnail div and a caption div underneath the image both conditional on the contents of the database field.
<?php if($Recordset1->getColumnVal("SOLD") == "YES") { ?>
<div class="caption post-content-sold"></div>
<? } ?>
<?php if($Recordset1->getColumnVal("SOLD") == "CON") { ?>
<div class="caption post-content-contract"></div>
<? } ?>
Then in the CSS I added code to make the thumbnail relative, and then added the two classes to style the image relating to the database field
.thumbnail {
position: relative;
}
.post-content-sold {
background: rgba(255, 255, 255, 0.8) none repeat scroll 0 0;
opacity: 0.8;
top:0;
left:0;
min-width: 100%;
max-height: 98%;
position: absolute;
color: #ffffff;
content:url(http://www.mtnlakerealty.com/sold.png);
}
.post-content-contract {
background: rgba(255, 255, 0, 1) none repeat scroll 0 0;
opacity: 1;
top:5%;
left:5%;
max-width: 50%;
max-height: 50%;
position: absolute;
color: #ffffff;
content:url(http://www.mtnlakerealty.com/contract.png);
}

Related

Full Screen Background Image - Wordpress

I have a 1 page site with full screen scrolling sections.
Each section displays correctly on desktop, but on mobile the 'team' section has a white block top and bottom.
I have made another section for teams ('team2test') for use only on mobile - with HTML to try to make the section full height but the background image is not full screen
Please assist in either why the 'team' section has a gap top and bottom - or why my background image is not full screen in 'team2test'
Code for 'team2Test':
body,
html {
height: 100%;
margin: 0;
}
.team-images-mobile {
display: block;
margin-left: auto;
margin-right: auto;
padding: 10px;
width: 200px;
height: 200px;
}
.team-section {
background-image: url(https://neuefund.com/wp-content/uploads/2022/01/team_7693a7d4f435b52cec2b4ce8cbbf00a4.png);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 100vh;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
position: relative;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="team-section">
<div class="team-images-mobile">
<img src="https://neuefund.com/wp-content/uploads/2022/01/MAX-300x300.png" alt="" >
<img src="https://neuefund.com/wp-content/uploads/2022/01/KRISH-300x300.png" alt="">
<img src="https://neuefund.com/wp-content/uploads/2022/01/COFIELD-300x300.png" alt="">
</div>
</div>
Link to site
Your problem comes from:
why the 'team' section has a gap top and bottom
That comes from your padding in
.team-images-mobile {
padding: 10px;
}
why my background image is not full screen
This come from the height: 100vh you set in .team-section
body,
html {
height: 100%;
margin: 0;
}
.team-images-mobile {
display: block;
margin-left: auto;
margin-right: auto;
width: 200px;
}
.team-section {
background-image: url(https://neuefund.com/wp-content/uploads/2022/01/team_7693a7d4f435b52cec2b4ce8cbbf00a4.png);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.team-section img {
width: inherit;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="team-section">
<div class="team-images-mobile">
<img src="https://neuefund.com/wp-content/uploads/2022/01/MAX-300x300.png" alt="" >
<img src="https://neuefund.com/wp-content/uploads/2022/01/KRISH-300x300.png" alt="">
<img src="https://neuefund.com/wp-content/uploads/2022/01/COFIELD-300x300.png" alt="">
</div>
</div>
The HTML of your "Team section" looks like this now:
<div class="grve-column wpb_column grve-column-1">
<div class="grve-column-wrapper">
<div class="grve-element grve-text">
<h2 style="text-align: center;">Team</h2>
</div>
<div class="wpb_raw_code wpb_content_element wpb_raw_html">
<div class="wpb_wrapper">
<div class="team-section">
<div class="team-images-mobile">
...
</div>
</div>
</div>
</div>
<div class="grve-empty-space grve-height-1x" style=""></div>
</div>
</div>
If you check in your browser inspector, you'd find that the .grve-element (the heading text "Team") is taking up space before the actual .team-section in your code. And that element has a white background.
So it doesn't really matter with your .team-section style. It's more of an HTML structure issue.
There are 2 direction to solve this:
If you can control the overall HTML, simply move your .team-section background css settings to the .grve-column level; or
Make .grve-element height 0 by setting it as "position: absolute; width: 100%;". You'd need to give .team-images-mobile some padding so they won't overlap with "Team".

How to round image border in generated pdf

I should round the image in pdf. I generate a pdf with PHP that shows also an image inside. Everything works correctly. When I add "width" and "hight" to the image it works, but when I try to round the corners of the image it does not work. When I envelop image with div and add to div border-radius and overflow: hidden; -> overflow: hidden; does not work.
Here is part of my code:
<style>
.visuel-carte{
text-align: center;
margin-top: 25px;
margin-bottom: 40px;
position: relative;
border-radius: 20px;
background-color: green;
}
.visuel-carte img {
height: 270px;
width: 420px;
border-radius: 20px
}
</style>
<page>
<div class="visuel-carte">
<img src="<?php echo $eboutique['visuel_carte']; ?>"/>
</div>
</page>
maybe you have some idea?
I tried also
<div style="background-image: url('<?php echo $eboutique['visuel_carte'];?>')">
but it shows me an error
I found an error in my code:
does not work:
<div style="background-image: url('<?php echo $eboutique['visuel_carte'];?>')">
work (without a little quotes ;) ):
<div style="background-image: url(<?php echo $eboutique['visuel_carte'];?>)">

CSS Adjustment of HTML Elements

I need help with adjusting a certain html element <div class="content"> with css so that it will be fixed and responsive like this (https://i.imgur.com/vYsIUXy.jpg) on that position regardless of screen dimensions and not like this (https://i.imgur.com/qUHHI0q.jpg).
I change the width of #info #head>.content from 100% to 82% but on a smaller screen dimension it overlaps with the cover image.
HTML Code
Snippet
<div id="head">
<div class="content">
<div class="uigrid">
<div class="contingo">
<p style="font-size:30px;">Meng Qi Shi Shen</p>
<div class="horizontal-list">
Adventure
Comedy
Drama
Historical
Romance
Shoujo
<div class="type"><span class="sub" onclick="if (!window.__cfRLUnblockHandlers) return false; changegrid()">Sub</span><span class="dub" onclick="if (!window.__cfRLUnblockHandlers) return false; changegrid()">Dub</span></div> </div>
</div>
</div>
</div>
<div class="overlay"></div>
</div>
Full php(html) code
https://codeshare.io/arj6eA
CSS Code
https://codeshare.io/GbyP86
you can try to use max-width of device to adjust the with you want. Like for instance if the decive is width is 600ps
#media (max-width: 600px) {
#info #head:after {
content: '';
position: absolute;
bottom: 0;
width: 82%;
height: 3px;
box-shadow: 0 2px #1b1c1d;
}
}
or like this one when the width of the device is 1000px
#media (max-width: 1000px) {
#info #head:after {
content: '';
position: absolute;
bottom: 0;
width: 75%;
height: 3px;
box-shadow: 0 2px #1b1c1d;
}
}
for more of this please check here https://www.w3schools.com/css/css_templates.asp

Add and remove default and hover background images on hover through ACF

This is my very first thread, I'll try to be as precise as possible.
I'm very new to working with php, and my current project is therefor quite a challenge.
I have 2 products, I would like to be able to, through ACF, to exchange both the default BG image and the hover image.
ATM I can exchange the hover, but its visible at all time.
If I add an image through the wysiwyg editor, it wont set as bg image, but on top of the content.
Heres what I have:
These are the two products. The left one has the hover bg img, shown at all time. The right one doesnt have any for now
Here you can see the ACF on the relevant page
Here is what it looks like, if I add an image through the wysiwyg editor (the hover img shows in the background)
Here is my css, for the products
Here what the code looks like:
<?php
/**
* Variables
*/
$introductiontitle = get_sub_field('introduction_title');
$introductionsubtitle = get_sub_field('introduction_subtitle');
$introductionsubtitle2 = get_sub_field('introduction_subtitle_2');
$hover_image1 = get_sub_field('hover_element_1_background');
$hover_image2 = get_sub_field('hover_element_2_background');
<!-- Introduction
-------------------------------------------------------------->
<div class="container-fluid pt-5 pb-8">
<div class="container">
<div class="row">
<div class="col-12 text-center mb-3">
<h1 class="font-weight-bold mb-3">
<?php echo $introductiontitle; ?>
</h1>
<p>
<?php echo $introductionsubtitle; ?>
</p>
<p>
<?php echo $introductionsubtitle2; ?>
</p>
</div>
<div class="col-12 col-md-6">
<div class="col-12 product chart py-5 mb-3 bg-center bg-cover"
<?php if ($hover_image1) { ?>
style="background-image: url(<?php echo $hover_image1 ?>"
<?php } ?>
>
<?php the_sub_field('hover_element_1'); ?>
</div>
</div>
<div class="col-12 col-md-6">
<div class="col-12 product chart py-5 mb-3 bg-center bg-cover"
<?php if ($hover_image2) { ?>
style="background-image: url(<?php echo $hover_image2 ?>"
<?php } ?>
>
<?php the_sub_field('hover_element_2'); ?>
</div>
</div>
</div>
</div>
I hope this all made sense!? Otherwise just let me know, and I'll explain it better.
Thanks in advance
I would've posted a comment for clarification but don't have enough points for that yet so decided I'd post an answer as it might be what you're trying to achieve.
Using a combination of layered elements and opacity you should be able to achieve an effect where the background image changes.
Here's an example using solid colours, but they can easily be changed to other elements (e.g. your custom background images, and images):
https://codepen.io/epsilon42/pen/NBNVad
HTML:
<div class="product" style="background: #ccc;"><!-- change inline style to to ACF initial background-image -->
<div class="hover-background" style="background: #666;"><!-- change inline style to to ACF hover background-image --></div>
<div class="copy">
<h2>test</h2>
<p>lorem ipsum lorem ipsum</p>
<div class="icon">
<div class="initial-icon" style="background: #f00;"><!-- change this div to initial <img> --></div>
<div class="hover-icon" style="background: #b4d455;"><!-- change this div to hover <img> --></div>
</div>
</div>
</div>
CSS:
.product {
width: 300px;
height: 300px;
position: relative;
}
.product .hover-background,
.product .copy {
width: 100%;
height: 100%;
position: absolute;
}
.product .hover-background {
opacity: 0;
transition: 0.2s all ease-in;
}
.product .copy {
text-align: center;
}
.product .copy .icon {
width: 50px;
height: 50px;
margin: 0 auto;
position: relative;
}
.product .copy .icon .initial-icon,
.product .copy .icon .hover-icon {
width: 100%;
height: 100%;
position: absolute;
}
.product .copy .icon .hover-icon {
opacity: 0;
transition: 0.2s all ease-in;
}
.product:hover .hover-background {
opacity: 1;
}
.product:hover .copy .icon .hover-icon {
opacity: 1;
}
You will need to adjust the CSS a bit to suit your situation.

Scale down images effectively without losing aspect ratio or quality in php

I am about launch my biggest dream website(my first one), but have some unresolved issues. I am a complete newbie to coding and highly rely on plugins and tutorials to get stuff done. Now, I am facing problems in handling images and I have tried a lot of options to solve these issues, but not found any perfect solution. I have a feature where users can create their own profile, upload profile pic and a cover pic, re-position it and save it(somewhat like facebook). And also they can update their statuses where they can post multiple images(up to 5).
My requirements are:
While re-positioning and saving the cover pic, I am saving the 'x' and 'y' position of the new position and cropping the image to save it separately. Problem here is, the cropping is done to fit the height and width of the container div of the image.(say the height of the container is 250px and width is 325px, image is cropped to fit that div). Since my container is responsive, the height and width vary in different screen sizes, and so does my cropped image. On a small screen, the image is cropped to 100px * 180px, which is a disaster. I want to know the effective way to deal with this so that the image is consistent everywhere.
In multiple uploads, everything seemed to work fine until I opened the Network tab in my chrome developer tools. One page had 26 images and the page size was a whooping 11.8mb. I used GD library to scale down my images, but now if I try to further resize them to reduce file size, the quality is lost and images become blurry. I am planning to use ImageMagick, but have no idea whether it will serve my purpose. I don't want any of my images to cross 50kb - 60kb but still maintain considerable amount quality. Can I achieve this !
Here is the code I use for Cover pic
HTML
<div class="drag-banner">
<!--Container div for Cropped and repositioned image-->
<div class="banner-wrapper">
<!--Dropdown menu for Options-->
<div class="dropdown upload-banner">
<div class="dropdown-toggle cam-wrap" type="button" data-toggle="dropdown" >
<i class="fa fa-camera"></i>
</div>
<ul class="dropdown-menu" role="menu">
<li role="presentation" id="" class="uplbBtn">
<a role="menuitem" tabindex="-1" class="type-file">
<form class="banrPosition-form" method="post" enctype="multipart/form-data">
<label class="label-file" for="uploadImage">
<i class="fa fa-upload"></i>Upload Cover
<input type="file" class="btn-file" name="uploadImg" id="uploadImage">
</label>
<input type="hidden" class="banrPosition" name="pos" id="pos" value="0">
</form>
</a>
</li>
<li role="presentation"><a role="menuitem" tabindex="-1" id="repstnBnr"><i class="fa fa-arrows"></i>Reposition Cover</a></li>
</ul>
</div>
<!--Cropped Image-->
<img class="img-responsive bannr-img" id="cropped" src="<?php echo $croppedUrl; ?>">
</div>
<!--Container div for Original uncropped image-->
<div class="banner-resize-wrapper">
<img class="img-responsive banner-img" id="uncropped" src="">
</div>
<!--Drag and reposition instruction text-->
<div class="drag">
<div class="txt"><i class="fa fa-arrows"></i> Drag to reposition banner</div>
</div>
<!--Div shown during ajax submit-->
<div class="ajxFrmDiv"><div class="txt"></div></div>
</div>
<button id="savRpstn" class="btn btn-primary btn-xs savRpstn marg-all-sm">Save Position</button>
<button id="cnclRpstn" class="btn btn-default btn-xs cnclRpstn marg-all-sm">Cancel</button>
CSS
.drag-banner {margin: 0 auto;padding: 0;position: relative;height:275px;} /*Main Container*/
.banner-wrapper {display: block;} /*Original Image Wrapper*/
.banner-resize-wrapper {display: none;} /*Original Image Wrapper*/
.banner-wrapper,.banner-resize-wrapper{width: 100%;position:relative;overflow:hidden;height:100%;}
.banner-wrapper img.banner-img{width: 100%;max-height: 100%;}
.banner-resize-wrapper img.banner-img {position: absolute;width: 100%;min-height:100%;cursor:s-resize;}
.cam-wrap{border-radius:50%;background: transparent;padding: 8px;border:2px solid transparent;}
.banner-wrapper:hover > .upload-banner > .cam-wrap, .upload-banner.open .cam-wrap
{border-radius:50%;background: rgba(0,0,0,0.5);padding: 8px;border:3px solid #ccc;}
.banner-wrapper:hover > .upload-banner > .cam-wrap > .fa-camera, .upload-banner.open .cam-wrap .fa-camera{
font-size: 120%;
-o-transition: all 0.085s;
-moz-transition: all 0.085s;
-webkit-transition: all 0.085s;
transition: all 0.085s;
}
.upload-banner{
cursor: pointer;
position: absolute;
z-index: 10;
top: 10px;
left: 10px;
}
.btn-file{padding:0;}
.dropdown-menu .label-file{width:100%;height:100%;padding:5px 15px;} /*Padding to match with dropdown-menu>li>a padding*/
.label-file{cursor: pointer;}
.label-file .btn-file {
position: fixed;
top: -1000px;
width: 100%;
height: 100%;
outline: none;
cursor: pointer !important;
}
.drag-banner .black-strip{padding: 0 10px;}
.drag{
line-height: 26px;
position: absolute;
text-align: center;
top: 40%;
width: 100%;
display: none;
}
.drag .txt{
background-color: rgba(84, 97, 133, 0.5);
-webkit-border-radius: 2px;
-webkit-box-shadow: inset 0 1px 0 rgba(0, 0, 0, .12);
color: #fff;
display: inline;
font-size: 13px;
font-weight: 700;
padding: 5px 10px;
}
.ajxFrmDiv{
top: 0;
left: 0;
width: 100%;
color: #000;
height: 100%;
display: none;
margin: 0 auto;
font-size: 150%;
font-weight: 700;
position: absolute;
z-index: 11000;
background: rgba(255,255,255,0.75);
}
.ajxFrmDiv .txt{
position: absolute;
top: 40%;
left: 35%;
align-items: center;
display: -webkit-flex;
display: flex;
-webkit-justify-content: center;
justify-content: center;
}
JS
$('body').on('click', '#savRpstn', function() {
saveReposition();
});
function saveReposition() {
x1 = $('.drag-banner').width(); //Container Width
y1 = $('.drag-banner').height(); //Container Height
y2 = $('.banner-resize-wrapper').find('img').height(); //Image Height
//The form is submitted here with the above values
}
PHP
//The width, height and position from top are sent like this
$from_top = abs($_POST['x1']);
$default_cover_width = $_POST['y1'];
$default_cover_height = $_POST['y2'];
$tb->cropThumb($default_cover_width, $default_cover_height, 0, $from_top);
//New Image is formed
public function cropThumb($width, $height, $x, $y)
{
$oldw = $this->getWidth();
$oldh = $this->getHeight();
$this->handlethumb = imagecreatetruecolor($width, $height);
return imagecopy($this->handlethumb, $this->handleimg, 0, 0, $x, $y, $width, $height);
}
I'm sorry I am not able to recreate the issue anywhere, I don't know how JSFiddle works.
I have uploaded a .gif image on Imagur which shows the issue. I have illustrated how the image is cropped in 2 different screen sizes.
Kindly take a look and help me in cropping and resizing these images efficiently

Categories