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 trial
Abe Layee
8,378 PointsHow to center the next and previous button
I am trying to center the next and previous button. However, it doesn't seem to work for me.
<body>
<nav>
<a href="#" class="logo"><img src="" alt="">Elite Fitness </a>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">Get Started</a></li>
<li><a href="">Location</a></li>
<li><a href="">Sign Up</a></li>
<li><a href="">Our community</a></li>
</ul>
</nav>
<section class="slideshow">
<div class="myslide">
<img src="img/img2.jpg" alt="">
</div>
<div class="myslide">
<img src="img/img5.jpg" alt="">
</div>
<div class="myslide">
<img src="img/img6.jpg" alt="">
</div>
<div class="myslide">
<img src="img/img7.jpg" alt="">
</div>
<a class="prev" i href="#">❮</a>
<a class="next" href="#">❯</a>
</section>
</body>
Here is my css
*{
padding:0;
margin:0;
box-sizing: border-box;
list-style: none;
text-decoration: none;
font-family: 'Cabin', sans-serif
}
html,
body {
background:#fff;
color:#555;
font-family: 'Cabin', 'Arial', sans-serif;
font-size:1em;
font-weight:300;
text-rendering: optimizeLegibility; /*render font perfectly*/
overflow-x:hidden;
}
/* Navigation */
nav {
background:rgba(46, 204, 113, 0.8);
width:100%;
height: 60px;
border-top: 1px solid rgba(46, 204, 113, .5);
border-bottom: 1px solid rgba(46, 204, 113, .5);
position: sticky;
}
nav ul {
display: flex;
margin:0;
padding: 0 100px;
float:right;
}
nav ul li a {
display: block;
color:#fff;
padding: 0 20px;
text-decoration: none;
text-transform: uppercase;
line-height: 60px;
}
.logo {
padding-left:50px;
color:#fff;
line-height: 50px;
font-size:1.3rem;
}
/****** Slide Show ***/
.slideshow{
position: relative;
margin: auto;
width: 100%;
}
.myslide {
background-size:cover;
background-position:center;
display: none;
}
.prev,
.next {
margin-top:-45px;
position: absolute;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
2 Answers
Zhen Wong
7,816 PointsI don't know the approach that you have used to centered the buttons that you had mentioned (or the a tags with class "next" and "prev"). Since you have placed {position: absolute;} for the buttons and {position: relative;} for the slideshow, my take is that you want to center the buttons within the slideshow div.
Here is how I would have added to you css:
.prev {
left: 50%;
transform: translateX(-200%);
}
.next {
right: 50%;
transform: translateX(200%);
}
The translateX is just a final touch up, you can change the appropriate % to your needs.
Gabriel Galán
3,346 PointsHave you tried targeting .myslide and using the text-align: center rule?
Cheers