Reputation: 4280
I'm trying to make a carousel (run snippet below) that:
The issue I'm facing is that neither margin NOR padding is working on the right side of the carousel and is only displaying on the left.
To see the exactly what I'm talking about, run the snippet below, scroll all the way to the right, and compare to when the carousel is scrolled all the way to the left (Day 7 should be in the middle of the div at the end):
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
text-align: center;
margin-top: 10px;
margin-bottom: 20px;
}
nav {
display: flex;
align-items: center;
justify-content: center;
}
.carousel-wrapper {
position: relative;
}
/* Arrows (ignore them, they don't work yet) */
.carousel-wrapper::before,
.carousel-wrapper::after {
content: "";
border-top: 2px solid black;
border-right: 2px solid black;
position: absolute;
height: 10px;
width: 10px;
top: calc(50% - 5px);
cursor: pointer;
}
.carousel-wrapper::before {
transform: rotate(-135deg);
left: -20px;
}
.carousel-wrapper::after {
transform: rotate(45deg);
right: -20px;
}
/* Where overflow hidden and overflow-x: scroll is */
.carousel {
border: 1px solid black;
background-color: #21abde;
overflow: hidden;
overflow-x: scroll;
width: 300px;
}
/* PROBLEM AREA (where the margin and padding should be but isn't working */
.links {
display: flex;
transform: skew(-15deg);
flex-shrink: 0;
margin: 0 100px;
margin-right: 100px;
}
/* Anchors */
a {
display: flex;
justify-content: center;
align-items: center;
color: white;
background-color: #21abde;
width: 100px;
height: 50px;
flex-shrink: 0;
text-decoration: none;
}
a span {
transform: skew(15deg);
}
a:hover {
background-color: #044c66;
}
<body>
<h1>Dates</h1>
<nav class="dates">
<div class="carousel-wrapper">
<div class="carousel">
<div class="links">
<a href=""><span>Day 1</span></a>
<a href=""><span>Day 2</span></a>
<a href=""><span>Day 3</span></a>
<a href=""><span>Day 4</span></a>
<a href=""><span>Day 5</span></a>
<a href=""><span>Day 6</span></a>
<a href=""><span>Day 7</span></a>
</div><!-- Padding / margin should be showing up here -->
</div>
</div>
</nav>
<script src="app.js"></script>
</body>
Now that you've seen the code snippet...
2 questions:
Thanks guys!
Upvotes: 2
Views: 1843
Reputation: 1549
Add this to you .items class:
width: max-content; padding: 0 100px;
Remove the margin and margin-right!
Upvotes: 3