Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMUZ140770 Selestino Gama
4,980 PointsCSS Slider
Hey guys, i am i want to build a simple HTML and css image and text slider which will have the image to the left and the text or description of the image on its right side.
Thanx in advance for those who will help.
5 Answers
Jacob McKinney
6,796 PointsYou're probably going to need more than CSS to make this slider. You can float two containers next to each other to provide the look you're going for, but to change what is in those containers or to move a duplicate set of containers into view, you'll need something like jQuery to perform the animation and then you'll use some logic to hide, show, slide in, etc the containers. Take a look at http://api.jquery.com/animate/ for some more help.
MUZ140770 Selestino Gama
4,980 PointsThat is very true. But here i was thinking of a simple slider with forward arrow for next and one for prev nothing much fancy.
Jacob McKinney
6,796 PointsYou'll probably use show/hide then:
http://api.jquery.com/show/ http://api.jquery.com/hide/
Have all of your containers set to display: none, except for the first container, in your css and use .show to show the correct container as the user presses the arrow and use .hide to hide the currently visible one.
<script>
$(document).ready(function() {
var containerShown = 1;
var maxContainer = 2;
$('#nextBtn').on("click", function() {
$('.myContainer').hide();
var nextContainer = containerShown + 1;
if(nextContainer > maxContainer) {
nextContainer = 1;
}
$('#container'+nextContainer).show();
});
});
</script>
<div>
<div id="prevBtn"></div>
<div class="myContainer" id="container1"></div>
<div class="myContainer" id="container2" style="display: none;"></div>
<div id="nextBtn"><div>
</div>
MUZ140770 Selestino Gama
4,980 PointsThis is cool, however i was thinking of using a clean css and html slider.
Erin Manahan
20,413 PointsI think this workshop would help you. Maybe use Jacob's suggestion for styling your divs and then apply what you make in the workshop to the first div, with the heading going in the second div.