I am trying to bring two objects (a cable and a cable cover) together in the center of the screen using CSS animation (ultimately showing the cover going over the cable).
The animation should be this: the cable will fade in and slide in from the right of a responsive (100% width) div, and the cover will fade in and slide in from the left; the cover will be assigned a higher z-index so that it sits on top of the cable end, giving the appearance that it has covered the cable.
Ideally, the animation would be triggered by a button click, since the experience needs to be the same on desktop and mobile. The two objects would have to come together (and slightly overlap) in the center of the div (no matter its current width). The animation is not required to reverse itself once completed.
Does anybody have any leads on how this might be achievable? I, for the life of me, can't wrap my head around how this would be accomplished. I appreciate any help here!
The basic idea would be to start by positioning one element off the left side of the screen: right: 100%
and the other element off the right side of the screen: left: 100%
When the user triggers the change, bring both elements to the center of the screen by setting left/right to 50%.
As an example, here is a rudimentary (and webkit specific) version:
html:
<button id="doit">show me</button>
<div class="cover">cover</div>
<div class="cable">cable</div>
CSS:
.cover, .cable {
position: absolute;
top: 100px;
width: 100px;
height: 25px;
color: white;
-webkit-transition: all .5s ease;
}
.cover {
right: 100%;
background-color: green;
}
.cable {
left: 100%;
background-color: red;
}
javascript:
var doit = document.querySelector('#doit');
doit.addEventListener('click', function() {
var cover = document.querySelector('.cover');
var cable = document.querySelector('.cable');
cable.style.left = "50%";
cover.style.right = "50%";
});
jsfiddle demo
In terms of animations, CSS3 transitions work best in my opinion, as they are far faster and easier to do, however the drawback is that you can only use one animation at a time. A good jQuery library to manage these is http://ricostacruz.com/jquery.transit/. If you need more functionality (and can sacrifice some speed) look at http://julian.com/research/velocity/.
jQuery button clicks are really easy to do:
$('#btnid').click(function() {
// Stuff happens here
});
More information on this can be found at http://api.jquery.com/click/.
Finally, for the CSS. I imagine that this will be the hardest part. You can set the cable images using background-image (http://www.w3schools.com/cssref/pr_background-image.asp). I recommend that you set both elements to position: absolute and then set the one on top to z-index: 99999 (never just use 1). Finally, you can fiddle around with the top, left, and margin CSS attributes if there are some problems with alignment. You may have to put both images in a parent div.
Hope this helps!
Related
I have an image that I want to achieve a certain effect. Essentially as you make your browser window smaller, I want to crop off left and right side equally, so that the image is not resized and I always see the center.
I have accomplished that in the following way:
<style>
.banner{
text-align: center;
overflow: hidden;
height: 350px;
position: relative;
}
.banner img{
position: relative;
left: 300%;
margin-left: -600%;
}
</style>
<div class="banner"><img src="https://lh3.google.com/u/0/d/0B1qZWmK2ucS8ZDN3Ni02VXo2SEE=w1129-h720-iv1" alt="Image is missing" /></div>
Js fiddle: https://jsfiddle.net/szsj6f9m/
One thing I have noticed with this approach is that if I make left be 100% and margin-left be -200% the image will then half way through start sliding back to the right. I don't fully understand why, I just know that I need to make the percentage to 300% so it behaves correctly on 320px screen.
Here is the example of what I am talking about, just resize your browser small to big and you will see what I am talking about:
Js fiddle: https://jsfiddle.net/szsj6f9m/1/
My question is this:
Is it ok to have the position of the screen so far and throw such a large left-margin on it? Does this causes any kind of problems from the performance point of view on smaller devices or any devices really? Are there any reasons you can think that would say not to do this.
I personally use left:50%;transform:translate(-50%,0); (works even for vertical centering) top:50%;transform:translate(0,-50%); https://jsfiddle.net/szsj6f9m/3/
I'm really new to programming and trying to customize a theme that I am using. However I am having several issues where if I fix one thing something else breaks. I've researched solutions for about 3 days and I think it's time I reach out to some more experienced with CSS for help.
I tried setting up a JSFiddle but it's not working correctly as I can't access the HTML file directly. The website is www.preethijagadeesh.com. Would it be possible to review the html/css files and provide suggestions for the following requirements?
Center the title (I believe this is found in the 'site_header'
class which is pasted below). I am using margin to change the percentage and it looks
different on various browsers.
I would also like to 'fix' the title so that when I scroll the title
goes with me. I used 'position: fixed' but it cause all the
content in the 'index' ID (pasted below) to overlay on the title/site_header.
The text in the 'About' page appears to be more on the left with
a lot of white space on the right. No matter what I am unable to get
the content to center regardless of which class I update.
The line/border_bottom that appears under the navigation items should be
the same length as the text. I tried updating it but now every time
I hover over the items the text/options move around
overlay a
black color on the thumbnails on hover. I got it to 'kind of' work.
It's just when I hover on the thumbnails, the images and the
'background color' flicker
Widen the gap between the thumbnails.
Right now, there are two columns, it would be great to just put some
space in between them.
Please let me know if there's any other information I can provide.
Change
.header_image {
float: left;
margin-top: 80px;
max-width: 100%;
}
to
.header_image {
text-align: center
margin-top: 80px;
max-width: 100%;
}
Add these to .site_header:
.site_header{
/* old css remains here... */
position: fixed;
top: 0;
left: 0;
right: 0;
}
Move the padding properties from the a to their parent instead (the .page_link div).
and 5. I can't get the thumbnails to display on your jsfiddle so I can't really give the answer. But for 4 I think something like this will help:
put a <div class="thumbnail-overlay"></div> inside your thumbnail html.
For the css:
.thumbnail-overlay{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 1;
/* this z-index should be higher than the thumbnails' child element. If no z-index is set for their child element leave it at 1 */
}
.thumbnail-overlay:hover{
background-color: rgba(0,0,0,0.5);
}
Hopefully this helps.
.header_image is floating, so you can't center it nicely. If you remove the float and then use text-align: center;, the image should center.
Not really sure where you are wanting the title to appear - should it be above the content or to the left of the content?
You have removed the padding from the links to resize the underline, but it's only been changed on hover. This is what is causing the "jumping" navigation links. If you add this code to .navigation a (instead of .navigation a:hover), this should work nicely:
.navigation a {
padding: 0;
margin-right: 6px;
margin-left: 7px;
}
Instead of using .thumb_image:hover, try using .thumbnail:hover .thumb_image and see if that's helps with the flickering. Also, maybe remove the background-position: 0 -30px;.
Is a plugin being used to generate and control the thumbnail images? The absolute positioning being used on the thumbnail images will make it difficult to reposition them.
You should be creating the site offline and reviewing your work before migrating the site to your host.
If your host does not allow you to migrate your site and/or denies you access to your HTML files, you need find a new web host.
I'm trying to build a rather complicated header. This is what it should look like:
As you can see, the header needs to be centered on the page, but the elements need to expand the width of the page. The issue I'm running in to is that I can't get the white part to extend properly. This is what I currently have:
I can't figure out any way to extend the white background over the black bar on the left side. I can kind of get it working using :before, but only at certain zoom levels (at certain points, a gap would appear between the logo and the overlapping :before, causing a bit of the black bar to bleed through), and we need this to work at all zoom levels.
My only other thought would be to use an extremely wide background image for the entire navigation, but I don't think that's an acceptable solution either.
Does anyone have any suggestions?
Demo: http://www.weblinxinc.com/beta/header/
Try that, on your current code (I used your current #headerLeft:after pseudo element) :
#headerWrapper header #headerLeft:after {
/* clear: both; */
content: "\0020";
display: block;
/* visibility: hidden; */
/* zoom: 1; */
width: 1000px;
height: 50px;
background: white;
top: 50px;
right: 100%;
position: absolute;
margin-right: -60px;
}
In a word, I just use a pseudo element to cover the left part in white. So I put it a very high width, and I position it relatively to the logo.
Feel free to put it on another element / pseudo element : I guess this one is making a clearfix.
I am creating a site here, to replicate the functionality of Chanel's website.
Currently the re-sizing works width wise but when it comes to height I can't for the life of me get it to work correctly so that the image is centered and just a bit above the footer. All my images are 1920 x 1080 just as Chanel has. Also Chanels site if you scroll just a bit down it pulls the bottom half up automatically where as I only got it to work with just the button.
When I view the page on an iPad only about 75% of the site shows up. I thought it was do to the more buttons padding but that was not the issue.
Thanks!
Also Chanels site if you scroll just a bit down it pulls the bottom
half up automatically where as I only got it to work with just the
button.
This is because the div at the top is fixed or absolute. The "bottom half" probably has a top margin of 100% that only becomes visible on scroll.
It "pulls up automatically" via javascript; if you turn javascript off acts normally. To do that, they probably use something like document.body.onscroll = function() { ...animation... }.
The CSS for the div#languages.popin (id = languages, class = popin) is as follows:
.popin {
position: absolute;
top: 50%;
left: 50%;
width: 900px;
height: 600px;
margin-top: -300px;
margin-left: -450px;
background: none repeat scroll 0% 0% rgb(255, 255, 255);
z-index: 150;
overflow: hidden;
}
I assume by following that, you'll get similar results. Try out firebug, or a variant thereof, and inspect the elements to find parts you may have forgotten.
I want to display images in a 144px x 144px div element.
Images are always larger than 144px and so I want to zoom scale them. By that I mean that the smallest side will touch the edge of the div, cutting a bit from the other side - the opposite of letterbox.
How can I do this and have it work on older browsers like IE as well?
EDIT:
Changed the image, the first was wrong, sorry.
Resize the image so that inside the div there is no space without image
My first answer addressed intentionally blocking out the part of the image while intentionally keeping the space occupied. If you just want part of the image visible with no space or anything else taken up, the best option will be to use CSS Sprite techniques.
Here's an example:
HTML (copy and paste into your own file for a full test):
<html>
<head>
<style type="text/css">
.clippedImg {
background-image: url("http://www.grinderschool.com/images/top_main.jpg");
background-position: -75px -55px;
height: 100px;
width: 235px;
}
</style>
</head>
<body>
<div class='clippedImg'> </div>
</body>
</html>
CSS (this is really the key):
.clippedImg {
background-image: url("http://www.grinderschool.com/images/top_main.jpg");
background-position: -75px -55px;
}
You can adjust the position numbers to get exactly the portion and size of the image that you want.
Note also that if you want a black box around this, it's even easier than the other post I made. Just put a parent div around this one:
<div class='blackBox'>
<div class='clippedImg'> </div>
<div>
With a padding and width set to create the black-box effect you want:
.blackBox {
background-color: black;
padding: 0 20px;
width: 235px;
}
Set only the width of the image to 144px in CSS or in the attribute. The height will scale automatically. I'm fairly certain this works as low as IE 6. I'm not certain about anything older than that.
If I read your question right, you aren't trying to resize the image, but rather to actually cut off part of the image. If you just want to resize the image, then follow the other answers about that.
The simplest way I can think of to actually cut off the image this is to add <div class='blockOut'> </div> and then use CSS to place & size the div, make it's color match the background color of your page, and put it in front of the image. Example CSS:
.blockOut {
position: relative;
top: -100px;
left: 100px;
background-color: white;
z-index: 2; //this is the important part for putting this div in front of the other one
}
Edit: Note that since you added an example showing that you want all sides blacked out, this would require separate divs for blacking out the top, each side, and the bottom. Also, if you want part of the image to show through (as it does in your example) you can use CSS transparency options.
div{height:114px;width:114px;overflow:hidden;}
div img{position:relative;left:-100px /*or whatever you want. can change it with js*/;top:-100px;}
that is masking to only show a part of the img, as you say in the title. but in the description says you want to resize the img. decide yuorself
to do what you want with css, you should use max-height:144px;max-width:144px. but ie6 doesn't implements those simple properties, so you'll have to use js