Fixed image within a div to make parallax scroll. - position

Okay. I have an issue with an image within a div. Fixed image within a div to make parallax scroll.
Here is what I want to do.
I have a div. Here is code.
#container{
height: 500px;
margin: 0 auto;
width: 100%;
max-width: 1920px;
position: relative;
overflow: hidden;
}
Now I want to add an image in there that is fixed.
#container-img{
position: absolute;
background-position:top center;
margin-right:0px;
bottom:0;
height: 500px;
margin: 0 auto;
width: 100%;
max-width: 1920px;
display-inline: block;
}
My problem is I want image fixed within the div and it goes all over the place. I do not want to add image via css as I have it in Wordpress for someone to change image when they want via dashboard. Here is HTML
<div id="container" >
<img id="container-img" src="<?php echo get_template_directory_uri(); ?>/images/home.jpg"/>
</div>
I want the css to make image fixed and not go outside the div? Any solutions? Thanks.

display-inline: block; is not a valid CSS. Try using display: block. Also background-position:top center; is not needed as you don't have any background image specified.
I would suggest you still use a background image with a background-size: cover; or you will have a hard time distorting the image proportions.
You will need to put the image in a inline style on your container:
<div id="container" style="background-image: url('<?php echo get_template_directory_uri(); ?>/images/home.jpg')">
Hope that helps.

Related

Adapting/cropping an animated svg, depending on aspect ratio

I don't find a way to make a proper crop of my svg image.
First, i am a newbie.
I tried fiddling in css with position absolute/relative, but the fact that this svg is animated with gsap makes me unable to load the svg as a background image in css.
I also tried modifying the viewbox parameters, but it seem a bit complex as a solution. I wonder if that can be responsive.
<div class="wrapper">
<div class="nav-bar>
"a nav bar here"
</div>
<div class="animatedSvg">
<svg>
the long svg code here of my fancy animated gsap.
</svg>
</div>
</div>
Css: elements are using flexbox for placement and sizing.
html, body{
margin: 0;
height: 100%;
}
.wrapper{
display: flex;
flex-direction: column;
height: 100
}
.nav-bar{
display: flex;
flex-direction: column;
}
.animatedSvg{
{
display: flex;
flex-direction: column;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0%;
background-color: black;
}
I am starting to wonder if this can only be fixed by controlling the viewBox with some javascript?
So it turns out that the answer was in fiddling with height, width, and the inline svg option preserveAspectRatio!
With these in the inline svg's code, things are now working as they should :)
`height="100%"
width="auto"
preserveAspectRatio="xMidYMin slice"`

Can I insert image into another image in Polymer?

What i have
If I have two images (one includes frame and another includes the picture),
My question
can I show it in the same image by using Polymer? I think it looks like bitmap in android and I want to do in web but I really don't know how
Here is one example on how to place a picture over a picture. Since I didn't have any pictures i "faked" them with span tags. Plunkr
<style>
.pic-one{
background: red;
position: absolute;
height: 30px;
width: 30px;
}
.pic-two{
background: blue;
position: absolute;
margin: 5px 5px;
height: 20px;
width: 20px;
}
</style>
<div class='container'>
<span class='pic-one'></span>
<span class='pic-two'></span>
</div>

Centering fluid div having max-width

I'm trying to center my content div. It's set to 100%, and the div is contained in body, which is also set to 100%. I have a max-width: 1400px because I don't want my content to stretch more than that if the screen resolution is higher. The thing is, it doesn't work using margin: auto. My content stands on the left, uncentered on screen wider than 1400px.
If I delete the max-width, everything is perfectly centered on wide screens, but the content is stretched to the the whole screen...
#content {
width: 100%;
height: auto;
position: absolute;
top: 400px;
margin: 0 auto;
margin-top: 50px;
display: none;
max-width: 1400px;
}
Easiest way to achieve this, is to set the width property to the max width you need, and add max-width: 100%;. This will prevent it from being bigger than 100% but still go up to the max width. Also, you should remove the absolute positioning:
JS Fiddle
You can use the transform technique, which doesn't require extra mark-up or media queries.
#content {
position: relative; /* 'fixed' will work also. */
max-width: 500px; /* Your required width here. */
width: 100%;
left: 50%;
transform: translateX(-50%);
}
Here's a demo https://jsfiddle.net/matharden/6uduf7av/
Use Flexbox...
Put this classes in the parent element (the body):
The HTML
<body class="p-flexbox flex-hcc">
<!-- The content -->
</body>
Where:
p-flexbox means parent-flexbox
flex-hcc means flexbox-horizontal-center-center
The CSS
.p-flexbox {
display: -webkit-box;
display: -moz-box;
display: box;
}
.flex-hcc {
-webkit-box-orient: horizontal;
-webkit-box-pack: center;
-webkit-box-align: center;
-moz-box-orient: horizontal;
-moz-box-pack: center;
-moz-box-align: center;
box-orient: horizontal;
box-pack: center;
box-align: center;
}
Cheers,
Leonardo

Making 1 image go between two other images?

At my site on the first page i have two images put together so it looks like a sunset. I want to my logo to go down between them as if it was the sun, but i cant make this happend. The logo is currently at the second page of the site
Heres i the html:
<div id="intro">
<div id="introbaggrundbagved"></div>
<a name="section1" class="section">SECTION 1</a>
<div id="logo">
</div>
</div> <!--#intro-->
And the css:
#intro{
background: url('images/introforan.png') no-repeat center;
height: 900px;
margin: 0;
position: relative;
z-index: 3;
}
#introbaggrundbagved{
background: url('images/introbagved.png') no-repeat center;
height: 900px;
width: 1440;
margin:0;
position: relative;
}
#logo{
background: transparent url('images/logo.png') no-repeat center;
width: 600px;
height: 600px;
position: relative;
margin-left: 420px;
margin-top: 100px;
z-index: 2;
}
You need to take the #logo div out of its parent element #introand give it a z-index that is larger than both of its siblings— then wrap all of the header elements into an #intro-wrapper div. In addition, I would then position the #logo element using position: absolute, instead of relative, this will give you more granular control on it's placement without disturbing the document flow of the surrounding elements.
Also, it appears that you have the function parallaxScroll updating the top property of #logo, which will prevent the element from being placed between your two images.
function parallaxScroll(){
var scrolledY = $(window).scrollTop();
$('#logo').css('top','+'+((scrolledY*.376))+'px');
....
}

No scrollbar for DIV wider than browser

I'm doing some tests on a website using Wordpress as a CMS. In the example below the top left of the page has an "S" graphic outside of the main content area, clipped accordingly depending on the browser width. I would like to do something similar with an "L" graphic to the right in the footer.
The page width is set to 960px, and I've made the footer container DIV 1088px so that the "L" appears outside the content area. The trouble is this makes a scrollbar appear when it exceeds the current width of the browser.
I've tried overflow:hidden on the footer container DIV but this doesn't seem to work. I've also tried overflow:hidden on the BODY element and this works ok in IE, but not in other browsers.
Example: http://unclemort.com/wp/
I really hope there is away to do this, any help gratefully received.
I was trying to figure this out myself today and stumbled upon the answer.
What you need is a surrounding element around everything that has this:
#wrapper {
min-width: 600px; //whatever width you want
overflow-x: hidden;
}
Your main content should have that same width, and the things that need to jut out should have a negative margin.
Here's a complete example:
HTML:
<div id="outer">
<div id="container">
<div class="row">
<div class="inner">Hello World</div>
</div>
</div>
</div>
CSS:
#outer {
min-width: 300px;
overflow-x: hidden;
}
#container {
width: 300px;
margin: 0px auto;
background: gray;
height: 500px;
}
.row {
width: 350px;
background: blue;
margin-left: -25px;
}
.inner {
background: yellow;
margin-left: 25px;
width: 300px;
height: 100px;
}
#media screen and (min-width: 301px) {
body {
//overflow-x: hidden;
}
}
jsfiddle:
http://jsfiddle.net/aaronjensen/9szhN/
Try in style.css, line 65, adding:
#footer-container {
border: none;
overflow: hidden;
}
Explanation:
#footer-container #footer {
background: #f5e8f7 url('images/slobraico-footer-pink-full.gif') no-repeat top left;
width: 1088px;
height: 217px;
overflow: hidden;
}
The scrollbar you're hiding is effectively not there.
The scrollbar you're seing is another one.
The problem is that the footer is 1088px wide, and that's causing a scrollbar to appear.
As long as the footer has fixed width and it's parent doesn't have overflow: hidden, you'll get a scroll if there's not enough width for the footer to fit.
Same goes for any other container.

Resources