最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Centering slider navigation arrows according to the image not parent container - Stack Overflow

programmeradmin0浏览0评论

How can I center slider navigation buttons based on the images inside each slide instead of the parent container? I have a slider section displaying products with names and prices. The prev/next buttons are currently centered vertically relative to the parent container, but I need them to align with the images inside each .slider-item. I can't wrap the images in a separate div just for centering, as this would break the slider functionality. I have condiered using JS for centering but I don't like the idea of using anything other than HTML and CSS/SCSS.

Right now for centering I use absolute positioning

    .slider-controls {
        position: absolute;
        top: 50%;
        left:50%;
        width: 90%;
        display: flex;
        justify-content: space-between;
        transform: translate(-50%, -50%);
    }

What's the best approach to achieve this?

Quick demo here

How the navigation arrows should be

Cheers!

How can I center slider navigation buttons based on the images inside each slide instead of the parent container? I have a slider section displaying products with names and prices. The prev/next buttons are currently centered vertically relative to the parent container, but I need them to align with the images inside each .slider-item. I can't wrap the images in a separate div just for centering, as this would break the slider functionality. I have condiered using JS for centering but I don't like the idea of using anything other than HTML and CSS/SCSS.

Right now for centering I use absolute positioning

    .slider-controls {
        position: absolute;
        top: 50%;
        left:50%;
        width: 90%;
        display: flex;
        justify-content: space-between;
        transform: translate(-50%, -50%);
    }

What's the best approach to achieve this?

Quick demo here

https://codepen.io/in2d/pen/YPKmJge

How the navigation arrows should be

Cheers!

Share Improve this question asked Feb 8 at 5:49 in2din2d 63811 silver badges26 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

I have a solution here but the downside to it is that the slider images will lose responsiveness.

Idea is to wrap the slider navigation buttons inside a separate div which is absolute positioned and has fixed height lets say 200px, then we need to assign fixed height to the images also which is also 200px. This way it seems that the slider nav buttons are always centered related to the image.

This is just one solution I came up with, still open for other, more responsive solutions.

发布评论

评论列表(0)

  1. 暂无评论