I'm working with 100% width relative positioning, but need an absolute positioned child div or span to hold a jquery image slider.
Layout
------ width 100%-------
| img1 | slider | img2 |
Currently the slider span isn't being positioned inline like the other objects and overlapping
What I have so far:
Fiddle
HTML
<div class="pic_container">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
<span class="viewer">
<img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" alt="" class="active" />
<img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" alt="" />
<img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" alt="" />
</span>
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
</div>
</div>
CSS
/*slideshow*/
.viewer {
font-size:0;
display:inline;
}
.viewer IMG {
position:absolute;
z-index:8;
width:50%;
vertical-align:top;
}
.viewer IMG.active {
z-index:10;
}
.viewer IMG.last-active {
z-index:9;
}
/*pics*/
.pic_container{
font-size:0;
display:inline;
}
.pic_container img {
width:25%;
vertical-align:top;
}
I've added a wrapper to the viewer and removed the extra spacing between your outer images and the slideshow viewer using the html comment tags (this is better than setting font-size:0). I've adjusted the JS, so that the transition works. I've also cleaned up and reduced the amount of CSS needed.
HTML
<div class="picture-container">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg" /><!--
--><div class="viewer">
<img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" class="active" />
<img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" />
<img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" />
</div><!--
--><img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg" />
</div>
CSS:
* {margin:0;padding:0}
.picture-container > img {display:inline-block;width:25%;}
.viewer {display:inline-block;position:relative;width:50%;vertical-align:top;}
.viewer img {position:absolute;width:100%;}
JS
function slideSwitch() {
var transitionDuration = 1000;
var active = $('.viewer img.active');
var next = $('.viewer img:first').insertAfter(active);
active.removeClass('active').fadeOut(transitionDuration);
next.addClass('active').hide().fadeIn(transitionDuration);
}
$(document).ready(function(){
$('.viewer img.active').insertAfter('.viewer img:last');
setInterval("slideSwitch()", 4000);
});
You can see it here: http://jsfiddle.net/Ry7Su/1/
Hope this helps.
The following changes will solve your problem.
This is based on your code. You can tweak it to make it shorter.
HTML part:
<div class="pic_container">
<div class="leftDiv">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
</div><!--
--><div class="viewerWrapper"><div class="viewer">
<img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" alt="" class="active" />
<img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" alt="" />
<img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" alt="" />
</div></div><!--
--><div class="rightDiv">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
</div>
</div>
CSS Part:
.pic_container {
display: block;
width: 100%;
position:relative;
}
.leftDiv {
display:inline-block;
width: 25%;
position:relative;
}
.rightDiv {
display:inline-block;
width: 25%;
position:relative;
}
.viewerWrapper {
display:inline-block;
width: 50%;
position:relative;
vertical-align: top;
}
.viewer {
width:100%;
}
.leftDiv IMG, .rightDiv IMG, .viewer IMG {
max-width: 100%;
}
.viewer IMG {
z-index:8;
position: absolute;
}
.viewer IMG.active {
z-index:10;
}
.viewer IMG.last-active {
z-index:9;
}
See it here: http://jsfiddle.net/FTEan/
try to give pic_container position: relative; and try to give viewer display: inline-block; this might work. pic_container could may also be display: inline-block;
Related
The following code (jsfiddle) implements an image viewer in CSS
<!DOCTYPE html>
<head>
<title>Trains, Planes, Automobiles, and Boats</title>
<meta charset="UTF-8">
<style type="text/css" media="screen">
html, body { background:#ddd; margin:0; padding:0; height:100%; }
#foo { position:absolute; left:5%; width:60%; top:5%; height:80%; background:#dcc; }
#bar { position:absolute; left:70%; width:25%; top:5%; height:80%; background:#cbd; vertical-align: middle; }
.fullwidth { width: 100%; vertical-align: middle; }
.vcenter {
display: block;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="foo">
<div class="vcenter">
<img class="fullwidth" src="https://openclipart.org/image/800px/svg_to_png/19623/philrich123-A380.png" />
</div>
</div>
<div id="bar">
<img class="fullwidth" src="https://openclipart.org/image/800px/svg_to_png/4703/ryanlerch-Steam-Train-Engine.png" />
<img class="fullwidth" src="https://openclipart.org/image/800px/svg_to_png/19623/philrich123-A380.png" />
<img class="fullwidth" src="http://openclipart.org/image/800px/svg_to_png/74557/rally-car.png" />
<img class="fullwidth" src="https://openclipart.org/image/800px/svg_to_png/196201/Model-T-Ford.png&disposition=attachment" />
<img class="fullwidth" src="https://openclipart.org/image/800px/svg_to_png/24418/Jarno-Boat-1.png&disposition=attachment" />
</div>
</body>
How do I fix the following two bugs?
The bar side does not scroll.
The image in the foo side is not centered. The intention is to make all the image visible in the left side while filling its container in one dimension (vertical/horizontal) and being scaled in the other (horizontal/vertical) to remain at 1:1 ratio.
I'm not sure I understood your question, but if you only want to make your right div scrollable then add this to your css
#bar{
overflow: scroll;
}
Example
To answer your second question (vertically centering the left image), add these rules to your vcenter class
position: relative;
top: 50%;
transform: translateY(-50%);
Example 2
I'm trying to center a masonry container on a page. At the moment, it's aligned to the left. I have margin auto in my CSS and isFitWidth: true in JS, but neither seems to be doing anything. I've also tried putting display:block in my CSS.
This is the HTML;
<div id="masonry_container" class="group">
<div class="masonry_item">
<a href="http://storyville.jonmarkoff.com/storyvillewp"target="_blank">
<img src="images/storyville_home.png" alt="Storyville Entertainment"/>
<h3>Storyville Entertainment</h3></a>
</div><!--masonry_item-->
<div class="masonry_item">
<a href="http://www.ducklingfarm.com"target="_blank">
<img src="images/udof_home.jpg" alt="Ugly Duckling Organic Farm"/>
<h3>Ugly Duckling Organic Farm</h3></a>
</div> <!--masonry_item-->
<div class="masonry_item">
<a href="http://www.underdonk.com"target="_blank">
<img src="images/underdonk_home.png" alt="underdonk"/>
<h3>Underdonk</h3></a>
</div> <!--masonry_item-->
<div class="masonry_item">
<a href="http://www.jaeeunlee.com" target="_blank">
<img src="images/jaeeunlee_home.png" alt="jaeeunlee"/>
<h3>www.jaeeunlee.com</h3></a>
</div> <!--masonry_item-->
<div class="masonry_item">
<img src="images/goindoor_hospitals.png" alt="goindoor"/>
<h3>Goindoor</h3>
</div> <!--masonry_item-->
<div class="masonry_item">
<img src="images/cakes_home.jpg" alt="wonderfully whimsical cakes"/>
<h3>Wonderfully Whimsical Cakes</h3>
</div> <!--masonry_item-->
</div><!--#masonry_container .group-->
CSS;
.group {
display: inline-block;
clear:both;
}
.group:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
#masonry_container {
margin:50px auto;
width:100%;
position:relative;
z-index:2001;
}
.masonry_item {
width:300px;
margin:0 0 20px 0px;
padding:20px;
}
.masonry_item:hover{
outline:1px solid white;
}
#masonry_container img {
width:100%;
}
and JS;
var container = document.querySelector('#masonry_container');
var msnry = new Masonry( container, {
// options
isFitWidth: true,
itemSelector: '.masonry_item'
});
I'd appreciate your help!
I was trying to figure this out for myself today and thought I'd share a possible solution.
As per Masonry's own options page "isFitWidth": true seems to be the key
http://masonry.desandro.com/options.html#isfitwidth
Here's their codepen example..
http://codepen.io/desandro/pen/nGLvx
Here's my simplified and bare bones method..
fiddle
https://jsfiddle.net/Hastig/xtw113wx/2/ - code play
https://jsfiddle.net/Hastig/xtw113wx/2/embedded/result/ - full screen
html
<div class="masonry-container js-masonry" data-masonry-options='{ "isFitWidth": true }'>
<div class="image-div">
<img class="image" src="" style="width: 200px; height: 100px;">
</div>
<!-- ..lots more divs in jsfiddle.. -->
</div>
css
.masonry-container {
margin: 0 auto; /* this is the css that keeps the container centered in page */
}
.image-div {
float: left;
width: 230px;
margin: 5px;
font-size: 0;
}
.image {
width: 230px;
height: auto;
}
Try this in the css:
.masonry_item {
width:300px;
margin:0 auto 20px auto;
padding:20px;
}
EDIT
I didn't read this correctly the first time. If you want to center the actual container you will need to set a fixed size for the container instead of 100%. Maybe 500px. Then remove the display: inline-block from the .group class. That should do it.
Set a fixed size for the container, such as width = 300px; height = 500px. Then, move the container with left: 50%; top: 50%. Finally, set the margin-left to -1/2 the value of the width, and margin-top to -1/2 the value of the height. This only works with absolute positioning.
I want to put one image left, one image right and text in the middle.
I keep thinking I am close then one or another runs away! I would appreciate some help and guidance.
Code for page and CSS below
VB page
<div id="HeaderTitleWrapper">
<h2><img src="images/Header/logo.jpg" alt="Writting Icon" />
<div id="HeaderTel">
GATEWAY<img src="images/Header/pic2.jpg" alt="Writing Icon" />
</div> <!-- HeaderTel -->
</h2>
</div> <!-- HeaderTitleWrapper -->
CSS
/* Header Text Title */
#HeaderTitleWrapper {
width: 1000px ;
margin-left: auto ;
margin-right: auto ;
}
#HeaderTitleContent {
padding: 0px;
height: auto;
position: relative;
left: 0px;
top:10px;
}
#HeaderTel
{
position:absolute;
right:150px;
top:auto;
}
Using text-align:justify and pseudo , you can spray inline-boxes from left to right.
<header>
<img/>
<span>text</span>
<img/
<header>
header {
line-height:0;
text-align:justify;
}
header span {
display:inline-block;
vertical-align:middle;
line-height:1.2em;
}
header:after {
content:'';
display:inline-block;
width:99%;
vertical-align:top;
}
similar exemple : http://codepen.io/gcyrillus/pen/dlvCp
<div
id="firstImage">
<img
src="1.jpg"
alt="Writting Icon"
/>
</div>
<span
id="Text">
GATEWAY
</span>
<div
id="secondImage">
<img
src="2.jpg"
alt="Writing Icon"
/>
</div>
<!-- HeaderTel -->
</div>
i am i am new in CSS.. i have converted my psd file into html/css.. now i want to move my webpage page into center of the window.. i tried some code and that code align only text the background image "back.gif" remains at left.. here is my html and CSS code"
**HTML**
<body>
<div id="main">
<div id="header">
<div id="logo">
<img src="logo.gif" />
</div>
</div>
<div id="menu">
<img src="images/menu_07.gif" />
<div id="m">
<ul>
<li> Home</li>
<li> Pages</li>
<li> Donor</li>
<li>Seeker</li>
<li>Hospitals</li>
<li>Life Saving Contacts</li>
<li>Feedback</li>
</ul>
</div>
</div>
<div id="content">
<div id="center" align="center">
<h3>WELCOME TO ADMIN AREA</h3>
<p id="ajk">AJKBLOODBANK.COM</p>
<?php
echo "welcome!".$_SESSION['username'];
echo "<br>";
echo "<a href=logout.php>Logout</a> ";
?>
</div>
</div>
<div id="footer">
</div>
</div>
</body>
**CSS**
body
{
background:url(../back.gif) repeat-y;
padding-left:105px;
height:900px;
text-align: center;
margin:auto;
min-width: 760px;
}
div#main
{
width: 720px;
margin: 0 auto;
text-align: left;
}
#header
{
width:787px;
margin-top:10px;
}
#menu
{
width:787px;
float:left;
margin-top:20px;
}
#content
{
background-color:#FFF;
border:groove;
width:790px;
float:left;
padding-top:30px;
margin-top:30px;
}
#footer
{
float:left;
height:52px;
width:790px;
}
Please tell me where i made mistake ..
the diameseion of background image "backgif" = 995x1000
Whichever element you want centered - set an explicit width and then set left/right margins to auto
#main { width:995px; margin:0 auto; }
...this will center the element in its parent. If you were to center #main, it would be centered on the page (assuming your body has 100% width)
EDIT
Try making your background image apply to #main instead of body. Or, center the background image using background-position, or shorthand:
body { background:url(../back.gif) repeat-y center top; }
Cheers
To center the body element, I would use something similar to this:
.body {
width: 940px;
margin-left: auto;
margin-right: auto;
}
http://img263.imageshack.us/img263/6803/32007451.jpg http://img263.imageshack.us/img263/6803/32007451.jpg
I have two problems with my friendlisting box.
1. Images are set 100px in width but they vary in height. Problem here is, friendlisting div is not extending along with image's height as it should. As a result image overpositioned on bottom border.
2. Commonfriends div needs to extend in height and fully fill friendlisting box. Not happening.
I spent hours to fix these two issues, just couldn't make it. Any advise appreciated!
My html
<div class="friendlisting">
<img src="http://www.hurriyet.com.tr/_np/3375/8623375.jpg" alt="xxxx" class="profile" />
<div class="userinfo">
<span><strong>George Lexington</strong></span>
<span>Bruges, Belgium</span>
</div>
<div class="commonfriends">13 common friends</div>
<div class="tools">
<span><img src="images/icons/user_add.png" />Add to friend list</span>
<span><img src="images/icons/email_edit.png" />Send Message</span>
</div>
</div>
css
#content .friendlisting { min-height:40px; padding:5px 0 5px; border-bottom:1px solid #DDD; }
#content .friendlisting img.profile { float:left; width:100px; }
#content .friendlisting .userinfo { float:left; width: 200px; padding:10px; }
#content .friendlisting .userinfo span { display:block; }
#content .friendlisting .commonfriends { float:left; width:150px; height:100%; background:#ffe996; }
#content .friendlisting .commonfriends:hover { background:#FEDF62; }
#content .friendlisting .tools { float:left; width:160px; }
#content .friendlisting .tools span { display:block; }
you could try using a clearing div like this:
<div class="friendlisting">
<img src="http://www.hurriyet.com.tr/_np/3375/8623375.jpg" alt="xxxx" class="profile" />
<div class="userinfo">
<span><strong>George Lexington</strong></span>
<span>Bruges, Belgium</span>
</div>
<div class="commonfriends">13 common friends</div>
<div class="tools">
<span><img src="images/icons/user_add.png" />Add to friend list</span>
<span><img src="images/icons/email_edit.png" />Send Message</span>
</div>
<div style="clear:both;"></div>
</div>
or if you dont like the in-line style
.clear
{
clear:both;
}
then <div class="clear"></div>