:checked not working in css - php

Context:
I've been working on the front and back-end for a fun startup company for the last month. There is a profile page on the website for users who are logged in. As shown below in its default state:
Default state
Using the 'checkbox' hack / trick, by clicking on the setting icon (as referenced through the label tag in the css below) The logged in user can open a side menu, with settings and options for their account as shown below:
The menu expanded
The problem:
Clicking on the profile text is supposed to create a drop-down menu so that the user can upload their own profile picture. I was hoping to do this through the same checkbox hack as before. However, when clicking on the profile text (referenced as h1), the checkbox is ticked but the background (referenced as .sidebar h1) doesn't change its colour to red. I think this is because of a problem with the :checked function in css, because when I click on the profile text I can see the checkbox become checked and unchecked.
Of note:
I can use javascript, but it's really not preferable (the person I'm working for isn't a big fan.)
Here is the whole file: https://pastebin.com/E0H6HgRe
CSS
.sidebar {
background-color: white;
position: fixed;
top: 0;
width: 0;
bottom: 0;
}
input#slide-sidebar[type="checkbox"] {
display: none;
}
input#slide-sidebar:checked ~ .sidebar{
left: 0;
width: 201;
z-index: 3;
-webkit-transition: width 2s;
transition: width 2s;
}
.setting {
font-size: 100px;
color:black;
z-index: 0;
background-color:white;
position: fixed;
left: 18.8%;
width: 100%;
}
input#slide-sidebar:not(:checked) ~ .sidebar {
width: 0;
-webkit-transition: width 2s;
transition: width 2s;
}
h1{
color: #222;
font-size: 20;
letter-spacing: 1px;
text-decoration: none;
text-transform: uppercase;
color:black;
left: 0px;
opacity:0;
position: fixed;
top: 200px;
}
input#slide-sidebar:checked ~ .sidebar h1 {
opacity: 1;
transition: opacity 1s ease-in;
-webkit-transition: opacity 1s ease-in;
}
input#slide-sidebar:not(:checked) ~ .sidebar h1 {
opacity: 0;
transition: opacity 0.5s ease-out;
-webkit-transition: opacity 0.5s ease-out;
}
input#profile-pic:checked ~ .sidebar h1 {
background-color: red;
}
Php (html running inside php)
echo "<div class='main-wrap'><input id='slide-sidebar' type = 'checkbox' role='button' /> <label for='slide-sidebar' class='setting'><span><i class = 'fa fa-cog'></i></span></label><div class='sidebar'>
<input id='profile-pic' type = 'checkbox' role='button' /><label for='profile-pic'><span><h1> Profile</h1></span></label></div>";

Related

HTML Hidden button is still clickable if the user clicks in the area where the button appears

I created a makeshift hide/show menu in HTML/CSS using a checkbox, it works great to hide and show text and links, but I have a section where I'd like to show a button when the "checkbox" is clicked. At first it looks great, the button is hidden and when the user clicks the checkbox, a button appears below it. My problem that I'm having is that if the user clicks below the checkbox where the button appears before the button actually appears, they can still trigger the button. Any idea?
<td>
<label class="collapsible">
<input type="checkbox" />
<span class="collapser">Edit</span>
<span class="arrow">></span>
<div class="collapsed">
<form method="post">
<input type="hidden" id="pwd" name="deleteid" value='. $value["id"] . '>
<button onclick="return confirm_delete();" type="submit" name="DelBidSubmit" class="btn btn-default">Delete</button>
<script type="text/javascript">
function confirm_delete() {
return confirm("Are you sure you wish to delete that?");
}
</script></form></div></label></td>
Heres my CSS code just in case
.collapsible {
display: block;
margin-bottom: 1rem;
}
.collapsible input {
position: absolute;
left: -9999px;
}
.collapsible input:focus ~ .collapser {
border-color: grey;
}
.collapsible .collapser {
cursor: pointer;
border: 1px transparent dotted;
}
.collapsible .arrow {
float: right;
margin-left: 0.5em;
display: inline-block;
transform: rotate(90deg);
transition: transform 0.25s ease-out;
}
.collapsible input:checked ~ .arrow,
.collapsible input:checked ~ .collapser .arrow {
transform: rotate(270deg);
}
.collapsible .collapsed {
font-size: 0;
margin: 0;
opacity: 0;
padding: 0;
/* fade out, then shrink */
transition: opacity 0.25s, margin 0.5s 0.25s, font-size 0.5s 0.25s, padding 0.5s 0.25s;
}
.collapsible input:checked ~ .collapsed {
font-size: 12px;
opacity: 1;
height: auto;
padding: 5px 0;
/* grow, then fade in */
transition: margin 0.25s, padding 0.25s, font-size 0.25s, opacity 0.5s 0.25s;
}
I think you must use {display: none}; and {display: block} to handle show/hide actions. Remove opacity:0 and opacity:1 from your styles and replace display:none and display:block styles.

How to Change Mobile Menu Icon Using PHP (Toggling Hamburger Menu)

I'm using the hamburger toggling method from the AMP-WP website and replaced the text with a symbol ☰ to create the hamburger.
https://amp-wp.org/documentation/playbooks/toggling-hamburger-menus/
<?php echo( '☰' ); ?>
Everything works great, apart from I'd like to change the symbol to ✕ when the menu is open/active.
What PHP is required to do this please?
You need to take a different approach where your icon is really a set of HTML elements where each line is separate and can be targeted by animation, CSS transforms in this case:
const hamburger = document.querySelector('#hamburger-toggle');
hamburger.addEventListener('click', function() {
if (this.classList.contains('open')) {
this.classList.remove('open');
} else {
this.classList.add('open');
}
});
#hamburger-toggle {
position: relative;
cursor: pointer;
height: 40px;
width: 50px;
margin: 10px 0;
padding: 10px 0;
}
.hamburger-line {
display: block;
width: 24px;
height: 2px;
background-color: black;
margin-top: 6px;
opacity: 1;
}
.hamburger-line-1 {
margin-top: 0;
}
.hamburger-line-1, .hamburger-line-3 {
transform-style: preserve-3d;
transition: transform 200ms; /* this line animates the change in position */
transform: translateY(0px) rotateZ(0deg);
}
.hamburger-line-2 {
transition: opacity 200ms; /* this line animates the change in opacity fading in/out the middle hamburger line */
}
#hamburger-toggle.open .hamburger-line-1 {
transform-style: preserve-3d;
transition: transform 200ms;
transform: translateY(8px) rotateZ(44deg);
}
#hamburger-toggle.open .hamburger-line-2 {
transition: opacity 200ms;
opacity: 0;
}
#hamburger-toggle.open .hamburger-line-3 {
transform-style: preserve-3d;
transition: transform 200ms;
transform: translateY(-8px) rotateZ(-44deg);
}
<div id="hamburger-toggle">
<span class="hamburger-line hamburger-line-1"></span>
<span class="hamburger-line hamburger-line-2"></span>
<span class="hamburger-line hamburger-line-3"></span>
</div>

Why do the images and text in the html page are also displayed on the popup in this code?[ PHTML]

I have used following css classes to create a popup box for a button click event.
<style type="text/css">
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 10;
}
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 40%;
position: relative;
transition: all 5s ease-in-out;
}
.popup h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: #06D85F;
}
.popup .content {
max-height: 30%;
overflow: auto;
}
#media screen and (max-width: 700px){
.box{
width: 70%;
}
.popup{
width: 70%;
}
}
</style>
Popup is working as expected.But when I scroll down on the popup,images and text which are not in the popup area(Which are below the popup) are also displayed as they are on the same level.I have included a screen shot of my problem.Can any one help me in this? Where have I gone wrong?
I have obtained these classes from the Bootsnip site
https://bootsnipp.com/snippets/featured/ecommerce-quick-view-popup-amp-product-row
This is the problematic view
Just add z-index: 1 to .overlay. This should fix this issue.
See CSS z-index property for more informations.
I can't see a different z-index value in this case, but If you do, just increase the number of z-index.

i want make a drop down menu at which after click list will open rather mouse hover using CSS not using jquery, javascript etc

i have made my own drop down menu but i want to make that condition to which after clicking mouse it'll show the list rather mouse hover showing so how to do it using CSS is there any property that can i use ?? and i don't want to use jquery or JS.
here is my source code:
<ul><li>Home</li>
<li>About</li>
<li>
Portfolio
<ul>
<li>Web Design</li>
<li>Web Development</li>
<li>Illustrations</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
background: #E3CAA1;
}
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
Unfortunately, CSS doesn't have events like Javascript does. The closest thing you'll have to this is the :active state:
ul:active
{
//stuff
}
However, this will only be applied while the user is holding the mouse button down on the element. It will not toggle anything.
You need some form of JS in order to do this properly.
What you could do is check whether the ul li is active instead of checking for a hover.
So what you could do is.
ul li ul li:active { background: #666; }
ul li:active ul {
display: block;
opacity: 1;
visibility: visible;
}
My guess is that you can use z-index for that matter.
I would put the menu into a div and change the z-index of the div when the event you prefere is triggered (mouse over, on click, etc...)
There is no way to detect a click action in CSS alone. You will either have to use JS or settle for hovering to expand it. As mentioned in other answers, element:active will detect if the user is HOLDING THE MOUSE BUTTON DOWN on that element, but that seems... less desirable.

img flickering on css picture wall

im doing this project for university. i'm currently facing a minor problem but yet disturbing.
link to site: http://haw.finekost.com/ws2013/PP_HATE_SITE/
CSS:
.box {
filter: grayscale(1);
float: left;
height: 0;
margin: 0;
moz-filter: grayscale(1);
ms-filter: grayscale(1);
o-filter: grayscale(1);
opacity: 0.5;
padding-bottom: 20%;
position: relative;
webkit-filter: grayscale(1);
width: 20%;
}
.box:hover {
cursor: pointer;
moz-filter: all .5s ease-in-out;
opacity: 1;
webkit-filter: grayscale(0);
webkit-transition: all .5s ease-in-out;
}
img {
height: 100%;
left: 0;
position: absolute;
width: 100%;
}
the boxes are generated via php.
the image boxes change in size (just 1px) when i hover them. i really dont know why they do it. Hopefully someone can help me
it appears to be related to the webkit transition filter in your .box:hover
Maybe this will help?
Prevent flicker on webkit-transition of webkit-transform
actually if you add -webkit-backface-visibility: hidden; to the box:hover css it appears this will fix the problem.
It is happening due to your webkit-transition style rule setup on your box:hover selector.
If you take it out, then there is no 'flicker'. THe reason it does not happen in Firefox is because you do not have a firefox vendor property set there such as -moz-transition.
Why do you need a transition in this case ?
In your website you use for .box a width of 20%. It looks like this causes somehow a 1px gap. However this could be solved by using width: 20vw for .box.
vw is viewport width in % this removed the 1px border.
So use:
.box {
filter: grayscale(1);
float: left;
height: 0;
margin: 0;
moz-filter: grayscale(1);
ms-filter: grayscale(1);
o-filter: grayscale(1);
opacity: 0.5;
position: relative;
webkit-filter: grayscale(1);
padding-bottom: 20vw;
width: 20vw;
}

Categories