/    Sign up×
Community /Pin to ProfileBookmark

Center jQuery Cycle slideshow and text

Center jQuery Cycle slideshow and text

Hi all

I have a slideshow using the jquery cycles plugin.

[url]http://www.ttmt.org.uk/forum/cyclecenter/[/url]

The images used have different widths and have titles.

I need to have the slideshow and title centered.

The images are in div’s which also contain the <p> elements.

I’ve done it like this because I’m doing it in WordPress and this is how it’s structured there.

[code]
<div id=”slideshow”>
<div><img src=”01.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”02.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”03.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”04.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”05.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”06.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
</div>
[/code]

I had the images centered before using this jquery code

[url]http://www.ttmt.org.uk/forum/cycle/[/url]

[code]
<script type=”text/javascript”>
$(window).load(function() {
$(‘#slideshow div’).each(function(){
$(this).css({marginLeft: -$(this).width()/2})
});
$(‘#slideshow’).cycle({
fx: ‘fade’,
speed: 800,
timeout: 3000,
pause: 1,
next: ‘#next’,
prev: ‘#prev’,
});
});

</script>

//

#slideshow{
margin:0 auto
}
#slideshow img{
left:50%!important;
background:white
}
[/code]

but this used this html

[code]
<div id=”slideshow”>
<img src=”01.jpg” alt=”” />
<img src=”02.jpg” alt=”” />
<img src=”03.jpg” alt=”” />
<img src=”04.jpg” alt=”” />
<img src=”05.jpg” alt=”” />
<img src=”06.jpg” alt=”” />
</div>

[/code]

How can I now center the slideshow and title ?

[code]
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js”></script>
<script type=”text/javascript” src=”http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.74.js”></script>

<style type=”text/css” media=”screen”>
*{
margin:0;
padding:0;
}
/*
#slideshow{
margin:0 auto
}
#slideshow img{
left:50%!important;
background:white
}
*/
#slideshow{
margin:0 auto;
}
#slideshow div{
border: 1px solid green;
background:white;
left:50%!important;
}
#slideshow p{
border: 1px solid red;
text-align:center;
}

</style>

</head>

<body>

<div id=”slideshow”>
<div><img src=”01.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”02.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”03.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”04.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”05.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
<div><img src=”06.jpg” alt=”” /><p class=”wp-caption-text”>Image title</p></div>
</div>

<script type=”text/javascript”>
$(window).load(function() {
$(‘#slideshow div’).each(function(){
$(this).css({marginLeft: -$(this).width()/2})
});
$(‘#slideshow’).cycle({
fx: ‘fade’,
speed: 800,
timeout: 3000,
pause: 1,
next: ‘#next’,
prev: ‘#prev’,
});
});

</script>

</body>

</html>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@PadonakMar 31.2012 — [CODE]<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.74.js"></script>
<style type="text/css" media="screen">
body{padding:0px;margin:0px;}
#slideshow{text-align:center;width:100&#37;;}
#slideshow div{background:white;width:100%;}
</style>
<script type="text/javascript">
$(window).load(function(){$('#slideshow p').addClass("wp-caption-text");$('#slideshow').cycle({fx:'fade',speed:800,timeout:3000,pause:1,next:'#next',prev:'#prev',});});
</script>
</head>
<body>
<div id="slideshow">
<div><img src="http://www.ttmt.org.uk/forum/cycle/01.jpg" alt="" /><p>Image title 1</p></div>
<div><img src="http://www.ttmt.org.uk/forum/cycle/02.jpg" alt="" /><p>Image title 2</p></div>
<div><img src="http://www.ttmt.org.uk/forum/cycle/03.jpg" alt="" /><p>Image title 3</p></div>
<div><img src="http://www.ttmt.org.uk/forum/cycle/04.jpg" alt="" /><p>Image title 4</p></div>
<div><img src="http://www.ttmt.org.uk/forum/cycle/05.jpg" alt="" /><p>Image title 5</p></div>
<div><img src="http://www.ttmt.org.uk/forum/cycle/06.jpg" alt="" /><p>Image title 6</p></div>
</div>
</body>
</html>[/CODE]
×

Success!

Help @ttmt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...