CSS3 Animate/Translate DIV via onClick with Submit Button - css

I would like to see if anyone can direct me in the right direction to achieve the follow:
When the user clicks on SUBMIT the DIV WRAP containing the form will slide off horizontally the page (ie, the 100% width container) showing a NEW DIV underneath (acknowledging confirmation). Of course everything is z-index'd and layered.
Anyone with CSS3 suggestions?
Many thanks as always.
Cheers,
Erik

You could do something like this: (demo)
//HTML
<div id="container">
<div id="wrap">
<form id="myform">
...
</form>
</div>
<div id="new">
Thanking you!! :)
</div>
</div>
//CSS
#container {
height:100px;
width:200px;
position:relative; /* set position so #wrap can position correctly */
}
#new {
width:100%; /* optional, fills up the container once the #wrap has gone */
height:100%; /* same here */
}
#wrap {
background:#FFF; /* set background so you dont see the overlapping */
position:absolute; /* position it to the relative block */
width:100%; /* make it just as big */
height:100%;
z-index:10; /* set it on top */
overflow:hidden; /* prevent awkward animation when sliding horizontal */
}
// JS
$(function(){
$('form').submit(function(){
$('#wrap').animate({width:0},400); // add fading by adding opacity:0
return false;
});
});
​

I have created this demo for you using jQuery :)
Here is the code being used:
$('#myform :submit').click(function(){
// your code - use ajax to submit the form
$(this).parent('#frm').slideUp('slow', function(){
$('#success').slideDown('slow');
});
return false;
});
And sample html code:
<form id="myform">
<div id="frm">
<input type="text" /><br />
<textarea cols="50" rows="10"></textarea><br />
<input type="submit">
</div>
</form>
<div id="success">Thanks form submitted !!</div>

Related

Fix element to bottom of screen

I have a textbox I want at the very bottom of the screen at all times. Using the following markup and css, I was able to get it close but there's a weird gap under it and it sits on top of other content.
Markup:
<div class="content">
... stuff here
</div>
<div class="message-text">
<input type="text" placeholder="Start typing to share a message">
</div>
CSS:
.message-text {
position:fixed;
bottom:0px;
width:100%;
}
And here's a visual:
Any help would be awesome.
Just add this property, it'll work.
.message-text {
margin:0px;
}

CSS/Javascript to move background image up and reveal another image on click

I have a background image in a div that displays a US flag to represent English language. When the user clicks on the US flag, I want the flag to move up and display the Japanese flag below it so that the user can then switch languages when they click on either the US or Japanese flag.
I assume this, however, is what you want: http://jsfiddle.net/ctwheels/5fmjkkcf/
HTML
<body>
<div id="chooseLanguage">
<img style="z-index:100;" class="flags" src="http://static.buildasign.com/UPLOAD/images/listings/PID970_United_States_Flag.jpg" />
<img class="flags" src="http://worldwide.bose.com/electroforce/assets/images/learning_center/Japan_Flag.jpg" />
</div>
</body>
CSS
body {
background-color:grey;
}
#chooseLanguage {
margin-top:50px;
position:relative;
}
.flags {
height:30px;
width:40px;
position:absolute;
}
JS
$(".flags").click(function () {
flagHeight = $(this).height();
$(".flags").removeAttr('style');
$(this).css({
top: -flagHeight + "px"
});
});

Changing CSS property of an element when hovering another element

I have a div called image. It has a CSS-property visibility:hidden;. I have another button called button.
What I need is when I hover the button, the image changes to visibility:visible;.
Can I do it with CSS or do I have to use JavaScript?
yes you can do this
as like this
HTML
<label for="button">Click here</label>
<input type="checkbox" id="button">
<div class="one">Show my div</div>
Css
label{
background:green;
padding:10px;
}
.one{
width:100px;
display:none;
height:100px;
background:red;
margin-top:20px;
}
input[type="checkbox"]{
visibility:hidden;
}
input[type="checkbox"]:checked ~ .one{
display:block;
}
Live demo
Updated answer
if you want to just hover than check to this *Demo*
Note that this is a javascript / jQuery solution:
$(button).hover(function() {
$('div#image').attr('visibility', 'visible');
}, function() {
$('div#image').attr('visibility', 'hidden');
});
You can only do this if the div is a child of the button - which isn't possible.
It's possible if you make it a child of something else (i.e. not a button, do it differently).
However, what browser? All the main ones? Because if you are willing to use only the most modern it's possible by using sibling selectors.
But for mainstream usage you can only do it if the div is a child of the hover element. Note: You can hover anything, it doesn't have to be a button or a link <a>. So that's what I would do - make a div element that looks like a button, and has a child that you want to change.
You need javascript for that. You can use css if your div is parent for the button, but in your case this is not possible
JS
function changeVisibility(objID) {
var el = document.getElementById(objID);
if(el.style.visibility == 'hidden') {
el.style.visibility = 'visible';
return true;
}
el.style.visibility = 'hidden';
}
HTML
<div id="box">Something to show</div>
<input type="button" class="button" onmouseover="changeVisibility('box')" value="Change visibility" />

Changing the style of login field in picture

I would like to make the login and password field in thesame order. when i try to change order in css file with margin command, it moves both field.
Try something like this. There are many way to do it, but this is the most straighforward.
http://jsfiddle.net/QutGz/1/
dunno want is going on width the fiddle. You can accomplish evening out the "columns" like this:
label
{
float:left;
width: 100px;
}
input
{
float:left;
}
​
Set the width to something that will be larger than the largest label text.
You can use CSS float to fix the inputs position in relation to each other and their parents elements:
See this working Fiddle example!
Assuming a structure like:
<form method="post" action="#">
<div class="clear">
<label>KULLANICI ADI</label>
<input type="text" value="" name="foo">
</div>
<div class="clear">
<label>SIFRE</label>
<input type="text" value="" name="bar">
</div>
</form>
The CSS solution would be:
input[type="text"] {
float: right;
}
.clear {
clear:both;
}

How do you make an icon change from grey to full colour on hover?

I have a grey facebook icon and a full colour facebook icon. I would like to have them on my website so that when the mouse cursor is placed over the grey icon it becomes the full colour one. How do I achieve this?
Use CSS sprites and shift position based on CSS class for element and element:hover.
Old question, new answer with an old link:
http://webdesignerwall.com/tutorials/html5-grayscale-image-hover shows a solution with jQuery, which doesn't need 2 images (so it saves time and resorces if you want to do a larger gallery)
you need to have 2 versions from the Icon, one grey and another colored, and on hover, switch:
icon
{
background-image: greyIconURL
}
icon:hover
{
background-image: coloredIconURL
}
another way and better is #Kon solution
It can be done through the filter in css.
example
/* needed code */
.employee:hover img {
filter: none;
-webkit-filter: grayscale(0);
-webkit-transform: scale(1.01);
}
.employee img {
filter: gray;
-webkit-filter: grayscale(1);
transition: all .8s ease-in-out;
width: 100%; }
/* style col -- no need */
.row {
display:flex;
}
.col-md-3{
padding:5px;
width:25%;
}
<div class="row ourTeam">
<div class="col-md-3 col-12 q-pa-md employee">
<img src="https://placeimg.com/640/480/any">
<h6>Name</h6>
<span>CEO</span>
</div>
<div class="col-md-3 col-12 q-pa-md employee">
<img src="https://placeimg.com/640/480/any">
<h6>Name</h6>
<span>CEO</span>
</div>
<div class="col-md-3 col-12 q-pa-md employee">
<img src="https://placeimg.com/640/480/any">
<h6>Name</h6>
<span>CEO</span>
</div>
<div class="col-md-3 col-12 q-pa-md employee">
<img src="https://placeimg.com/640/480/any">
<h6>Name</h6>
<span>CEO</span>
</div>
</div>
that easy!
<img src="grey.png" onmouseover="this.src='blue.png'" onmouseout="this.src='greay.png'" />
EDIT use this instead of you wish to be following rules but increasing complexities and KBs
HTML
<img id="yourImage" />
JS
document.getElementsByTagNames('body')[0].addEventListener('load', function() {
document.getElementById('yourImage').addEventListener('mouseover', function() {
document.getElementById('yourImage').src = 'color.jpg'
}, false);
document.getElementById('yourImage').addEventListener('mouseout', function() {
document.getElementById('yourImage').src = 'grey.jpg'
}, false);
}, false);
PS this uses javascript as opposed to your css tag simply because it is a good practice to use image tag wherever possible because browsers will image as an image as opposed to a div tag where they will treat it as a content block (which is not good!).

Resources