Need image to cross the container height - javascript

I have an img inside a div container which has some background color. I want the image to overlay on top of the div container and cross it's height beyond the div's height, without any scroll bars.
A fiddle related to this http://jsfiddle.net/mLtfcm6n/2/
Fiddle code:
<div class="container">
<img class="image" src="https://cdn1.iconfinder.com/data/icons/prettyoffice9/256/triangle.png"></img>
</div>
.container {
background-color:red;
height:100px;
position:relative;
overflow:hidden;
}
.image {
position:absolute;
left:40px;
height:256px;
}
I can't set overflow-y to hidden and overflow-x has to be hidden
The end result should be like this fiddle: http://jsfiddle.net/mLtfcm6n/3/
CSS for it is(only change is removal of overflow property):
.container {
background-color:red;
height:100px;
position:relative;
}
.image {
position:absolute;
left:40px;
height:256px;
}
Help!

.container {
background-color:red;
height:100px;
position:relative;
overflow:hidden;
}
.image {
position:fixed;
left:40px;
height:256px;
}
<div class="container">
<img class="image" src="https://cdn1.iconfinder.com/data/icons/prettyoffice9/256/triangle.png"></img>
</div>

Related

Resize image according to div width

I have a div width that resizes according to the browser width, right now it is set to 80%.
What I'm trying to accomplish is depending on the image size, I would like the image to take up the whole div width. If it's a small image, keep image size and center.
In my fiddle, any image width over 800px should start from the right and expand according to the div re-size. It should always touch the right side and expand with the div width.
If the image width is smaller than or equal to 500px, it should stay it's size and resize according to div but stay in middle of div only.
The problem is, I'm not sure how to only affect certain images, I would like a solution that detects the image size because the images might switch.
.parent{
border:1px solid purple;
height:100%;
width:80%;
float:Right;
}
.child{
border:1px solid red;
height:100%;
background:gray;
text-align:center;
}
.child-img{
display:inline-block;
max-width:100%;
margin:0 auto;
}
.image-wrapper{
width:100%;
background:orange;
}
img{
width:auto;
height:100%;
width:100%;
}
<div class="parent">
<div class="child">
<div class="image-wrapper">
<img src="http://cdn.bulbagarden.net/upload/thumb/0/0d/025Pikachu.png/250px-025Pikachu.png" alt="" class="child-img">
</div>
<div class="image-wrapper">
<img src="https://i.kinja-img.com/gawker-media/image/upload/unnbgkdbmsszmazgxkmr.jpg" alt="" class="child-img">
</div>
<div class="image-wrapper">
<img src="https://em.wattpad.com/62f9f1c9de49ad97d7834b1e58e16a99eb2dc3c7/687474703a2f2f6170692e6e696e672e636f6d2f66696c65732f7363525a66707a54694d7a4d48484e586b7247575277674b6878726537617531666736413834472d684c484c616c7271302d6f4152524f6f525a6e55387076415a41637a545a6b4c6442476f6144496336507834395030744245426d4a646e382f50696b616368752e66756c6c2e313435323733332e6a7067?s=fit&h=360&w=360&q=80" alt="" class="child-img">
</div>
<div class="image-wrapper">
<img src="http://vignette3.wikia.nocookie.net/scratchpad/images/0/02/Pikachu.gif/revision/latest?cb=20150217015901" alt="" class="child-img">
</div>
</div>
</div>
Try using jQuery to detect the image's size.
$('.child-img').each(function() {
if ($(this).width() > 800) { $(this).addClass('right'); }
else if ($(this).width() < 500) {$(this).addClass('center');}
});
And the required css would be:
.child-img.right {
display: block;
max-width: 100%;
}
.child-image.center {
width: auto;
max-width: 100%;
display: inline-block'
}
.parent { text-align: center; }
I think you should be able to place the image in the background of the div and make its width and height percentage values.
background: url(img_flwr.gif);
background-size: 100% 100%;
background-repeat: no-repeat;

how to expand a child div than a parent with dynamic width on 100% of body

I need to build a menu inside an element which can have different width and different positions of the page.
I would like to create an edit menu which appears when hover on element,but I need the menu is as wide as the entire page
I need to use position:absolute as not to "disturb" the page layout
this is my fiddle
http://jsfiddle.net/bkoqv52e/
HTML
<div class="container row">
<div class="col-md-6 left">
<nav>nav</nav>
<div class="content">content left</div>
</div>
<div class="col-md-6 right">
<nav>nav</nav>
<div class="content">content-right</div>
</div>
</div>
CSS
.container {
width:100%;
background:#eee;
padding:30px;
}
nav {
height:30px;
background:#999;
display:none;
width:100%;
position:absolute;
top:-30px;
left:0;
}
.left {
background:#ddd;
height:300px;
}
.right {
background:#ccc;
height:200px;
margin-top:100px;
}
.col-md-6:hover > nav {
display:block;
}
Any suggestion is appreciated! thanks
Without js, you can define .left and .right to position static in order to refer nav to container on position relative like:
.container {
width:100%;
background:#eee;
padding:30px;
position: relative;
}
nav {
height:30px;
background:#999;
display:none;
width:100%;
position:absolute;
left:0;
}
.left {
background:#ddd;
height:300px;
position: static;
}
.right {
background:#ccc;
height:200px;
margin-top:100px;
position: static;
}
.col-md-6:hover > nav {
display:block;
}
<div class="container row">
<div class="col-md-6 left">
<nav>nav</nav>
<div class="content">content left</div>
</div>
<div class="col-md-6 right">
<nav>nav</nav>
<div class="content">content-right</div>
</div>
</div>

Image slider wont center

I can't seem to center my image slider, seems like an easy fix but I can't get it to center dead in the middle of my page (centered left & right, centered top and bottom) Any suggestions?
The image slider is #logo-and-slider in the CSS
Heres the jsfiddle: http://jsfiddle.net/gZDVL/13/ (thanks to #MaggiQall)
And here is a live link to it: http://jtcraddock.ie/boards/
I don't understand.
Is this your desired result?
<div><img src="http://testjd.net46.net/1.jpg" alt="1"/></div>
<div><img src="http://testjd.net46.net/2.jpg" alt="1"/></div>
<div><img src="http://testjd.net46.net/3.jpg" alt="1"/></div>
I closed your img-tags. with />
http://jsfiddle.net/gZDVL/2/
I am not very sure about whether you want to include the logo in the content to be centered. I have shown the idea below. I have added some borders to clearly display how the elements are laid out. If you don't want to include logo remove it from the HTML structure. Basically what I have done is placed the content in a table-cell element with the content center aligned horizontally with middle vertical alignment. That places the content at "dead center" as you wanted :-) See the fiddle at http://jsfiddle.net/linuxexpert/WYadL/
HTML:
<html>
<body>
<div class="outer-box">
<div class="inner-box">
<div class="innermost-box">
<div class="logo">
Logo
</div>
<div class="controller">
<
</div>
<div class="scroller">
Image scroller
</div>
<div class="controller">
>
</div>
</div>
</div>
</div>
</body>
</html>
CSS:
html, body {
width:100%;
height:100%;
}
.outer-box {
display:table;
width:100%;
height:100%;
}
.inner-box {
display:table-cell;
vertical-align:middle;
height:100%;
width:100%;
border:1px solid red;
text-align:center;
}
.innermost-box {
display:table;
height:50%;
width:80%;
margin:0px auto;
border:1px solid blue;
}
.innermost-box > * {
display:table-cell;
height:100%;
vertical-align:middle;
border:1px solid green;
}
.logo {
width:40%;
}
.controller {
width:5%;
}
.scroller {
width:50%;
}

The content slider concept

Could someone help me with creating a simple concept for content sliding?
What I want can be seen in this website's (https://www.palatine.fr) bottom part - 4 panels, which slide out on hover, and coming back to their original state after unhovering. I already tried a few fiddles with css blocks, but it gets up very complex, plus I know that I'll need jQuery in the end anyway for things like not stopping animation when the mouse unhovers a panel.
So what I'm asking is if anyone would be so kind and help me create a simple concept of this type of animation for content?
EDIT: http://jsfiddle.net/z3gY7/ is what I've done, yet it's not much at all, and probably won't be compatable at all. It's basicly done by div's and animations.
LIVE DEMO
HTML:
<div class="slideContent">
<p>Content here</p>
<div class="slideIn"><p>Sub Content</p></div>
</div>
CSS:
.slideContent, .slideIn{
height:300px;
width:180px;
}
.slideContent{
position:relative;
overflow:hidden;
}
.slideIn{
position:absolute;
left:0;
bottom:0px;
display:none;
}
jQ:
$('.slideContent').hover(function(){
$('.slideIn',this).stop().slideToggle();
});
Important note: This one works even better than the one on the website you provided :)
<div class="wrap">
<div class="wrap-inner">
<div class="normal">
Original text
</div>
<div class="hover">
other text
</div>
</div>
</div>
.wrap
{
display:block;
width:300px;
height: 300px;
position:absolute;
top:0px;
overflow:hidden;
}
.wrap-inner{
position:absolute;
height:600px;
width:300px;
top:0;
-webkit-transition: top 300ms ease;
}
.wrap-inner:hover{
top:-300px;
}
.normal
{
display:block;
width:300px;
height:300px;
background-color:green;
}
.hover
{
width:300px;
height:300px;
background-color:red;
}
I think you are close, just have to keep a 600px container inside wrap, that could hold the two 300px items one below other. Otherwise the second item wont be rendered when wrap height is made 300px.
http://jsfiddle.net/z3gY7/4/
http://jsfiddle.net/z3gY7/19/
HTML:
<div class="wrap">
<div class='box'>
<div class="normal">
Original text
</div>
<div class="hover">
other text
</div>
</div>
<div class='box'>
<div class="normal">
Original text222
</div>
<div class="hover">
other text2222
</div>
</div>
</div>
CSS:
.wrap
{
width:100%;
height: 300px;
position:absolute;
overflow:hidden;
}
.box {
width:25%;
height:600px;
float:left;
}
.normal {
width:100%;
height:300px;
background-color:blue;
}
.hover {
width:100%;
height:300px;
background-color:red;
}
And, jquery:
$('.box').hover(
function () {
$(this).stop().animate({ 'margin-top':'-300px' }, 1000);
},
function () {
$(this).stop().animate({ 'margin-top': '0px' }, 1000);
}
);
You can change speed, to fit your needs...

Footer under fixed divs

I'm currently having difficulty getting the footer of my website to work properly. I think it's because of my fixed positioned header and container divs but I need them to be fixed to stay on top when scrolling. I'm not sure how to take this into account for the footer to appear at the bottom when the container div is empty.
HTML:-
<body>
<div id="wrapper">
<div id="header">
<div id="headerContent">
</div>
</div>
<script>
$(document).ready(function() {
$('#container').css('marginTop', $('#header').outerHeight(true) + $('#navbar').outerHeight(true) );
});
</script>
<div id="navbar">
<div id ="navbarContent">
</div>
</div>
<div id="container">
</div>
<div id="footer">
<div id="footerContent">
</div>
</div>
</div>
</body>
</html>
CSS:-
#container{
width:960px;
margin:auto;
overflow:hidden;
}
#wrapper{
min-height:100%;
position:relative;
}
#navbar{
width:100%;
height:40px;
margin:auto;
background-color:#4e8885;
position:fixed;
top:120px;
padding:0px;
}
#header{
width:100%;
height:120px;
margin:auto;
background-color:#8bbcba;
position:fixed;
top:0px;
}
#footer{
width:100%;
min-height:20px;
margin:auto;
background-color:#8bbcba;
position:absolute;
bottom:0;
left:0;
}
In your example using fixed heights, it's not necessary to dynamically calculate the margins. You should just be able to set the margins of container to match the totals of your headers and footer for margin-top and margin-bottom respectively. See this jsFiddle: http://jsfiddle.net/9Jdrr/
If you need to dynamically calculate it, you should be able to do it based on this arrangement.

Categories

Resources