Add a pair of arrows on either side of a div element and ensure that it adjusts seamlessly for different

I'm facing a frustrating issue with my app. I have implemented a picture carousel and now I want to add navigation arrows on either side of the image. Despite using flexbox for my page layout, I am unable to achieve the desired result. Many suggestions I found online recommend using position: absolute, but this approach lacks responsiveness. As my design is focused on mobile-first, any slight increase in width causes the arrow positions to go haywire, leading to a need for numerous media queries to maintain responsiveness.

Below is the React code snippet:

<div className="dashboard">

   <div className="left-right-btn">
     <div className='left_button'>
     <button className="left-btn btn" onClick={this.prevPicture}>{'<'} 
 </button>
     </div>

     <div className='right_button'>
     <button className="right-btn btn" onClick={this.nextPicture}>{'>'} 
 </button>
     </div>
   </div>

   <div className="dashboard-pic">
     <div className="picture-name">{userName}</div>

     <div className="picture-carousel">    
        <Link to={`/profile/${userId}`}><img src={userPic} alt=''/></Link>
     </div>

     <div className='eventify_link_button'>
        {this.renderEventifyButton()}
     </div>
   </div>
</div>

CSS styling used:

.dashboard {
    display: flex;
    position: relative;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 30px;
}

.dashboard-pic {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-wrap: wrap;
    padding-top: 5%;
}

.picture-carousel {
    min-width:L 0;
    margin: 5px;
}

.picture-carousel img {
   width:300px;
   max-width: 100%;
   max-height: 300px
}

.left-right-btn {
    position: relative;
}

.left_button {
    position: absolute;
    left: -140px;
    top: 14em;
}

.right_button{
    position: absolute;
    right: -140px;
    top: 14em;
}

The current mobile view displays the navigation arrows using position: absolute. However, I aim to maintain this layout regardless of the screen width.

https://i.sstatic.net/UA9D5.png

Answer №1

Employ flexbox in the .dashboard container with a default direction of row and update the HTML structure to optimize the layout.

.dashboard {
  display: flex;
  align-items: center;
  justify-content: center;
}
<div class="dashboard">
  <div class="left_button">
    <button class="left-btn btn">Previous</button>
  </div>
  <div class="dashboard-pic">
    <img src="http://www.fillmurray.com/140/200" alt="">
  </div>
  <div class="right_button">
    <button class="right-btn btn">Next</button>
  </div>
</div>

<div class="dashboard">
  <div class="left_button">
    <button class="left-btn btn">Previous</button>
  </div>
  <div class="dashboard-pic">
    <img src="http://www.fillmurray.com/460/300" alt="">
  </div>
  <div class="right_button">
    <button class="right-btn btn">Next</button>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React drag and drop feature now comes with autoscroll functionality, making

I am encountering an issue with my nested list Items that are draggable and droppable. When I reach the bottom of the page, I want it to automatically scroll down. Take a look at the screenshot below: https://i.sstatic.net/ADI2f.png As shown in the image ...

Arranging Div Elements in a Specific Layout

I am currently experimenting with http://jsfiddle.net/ngZdg/ My main goal is to create a parallax website, but I am facing some challenges with the initial layout. I am aiming for the following design: ------------------------------------- | ...

Are Css3 Transition and Transform properties dysfunctional in older versions of IE?

Snippet of HTML Code: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="css/demo.css" /> </head> <body> <div></div> </body> </html> CSS Snippet: div { width: 100p ...

Is there a way to prevent the imported JQuery from causing issues with current code implementations?

Being a novice developer in Html/Javascript/CSS/Jquery coding, I recently encountered an issue while integrating Jquery into my project. When I imported Jquery, the styling of simple buttons went haywire. Jquery worked perfectly fine when using its classes ...

Styling may vary between the CSS used in the development environment and the one

After launching my web page on a server yesterday, I noticed some differences compared to the development environment. There are a few elements with altered colors, but my main concern is the appearance of the jQuery autocomplete search widget. Instead o ...

What is the most efficient way to toggle the enable and disable functionality of a submit input type after selecting a radio input type?

Can someone help me figure this out? I have a form with multiple groups of radio buttons, and I want to disable the submit button until at least one radio button from each group is selected. The code I've tried so far isn't working as expected. W ...

All about Props in ReactJS

Hi there, I am a beginner in reactJS and just starting to explore this amazing technology. I am facing an issue while trying to pass the name as props and display it on the screen. Can anyone lend me a hand with this? <!DOCTYPE html> <html lang ...

Angular 5: Transforming and Concealing CSS Class Names

Can CSS selectors be renamed or obfuscated in an Angular CLI project? Many top websites like Google and Facebook use randomized CSS names for various reasons, such as preventing website scripting through targeting static class names. I would like to imple ...

Is the border length less than the width of the div element?

I came across this code snippet div { width: 200px; border-bottom: 1px solid magenta; height: 50px; } <div></div> The div has a width of 200px which causes the bottom border to also be 200px long. However, I am looking for a way ...

stop bootstrap submit button from clearing form when errors are detected

Currently, I am working with bootstrap and reactJS in order to create a form. Take a look at the following code snippet: const CustomForm = () => { const [alertText, setAlertText] = ('') const [username, setUsername] = (''); ...

The specified method is not recognized as a function in the ReactJS library

Within my reactJS application, there is a function that calls upon a helper function to retrieve the result of a calculation. The component looks like this: import React, { Component } from "react"; import * as d3 from "d3"; class DrawImage extends Comp ...

Tips for showcasing a lineup horizontally with HTML and CSS

I'm currently working on creating a menu using HTML. I've included my links in an unordered list (ul) as shown below. In my CSS, I added a display:inline; property to the links to make them appear side by side like a menu. However, for some reaso ...

Extract data from nested divs using Excel VBA

Can anyone help me extract the start date from the code below? My current code does not seem to recognize the 'nested' div "daysTips." Any assistance would be highly appreciated. Thank you! HTML Screen Capture: https://i.sstatic.net/4fej8.jpg S ...

Experiencing an unexpected abundance of console logs when implementing React Hooks

I am attempting to retrieve data from an API. The desired result is being obtained, but when I attempt to log it to the console, it logs 4 times. Within my app.js, I am utilizing the fetchData function: import React, {useEffect, useState} from 'rea ...

Bring in a video file in order to watch it on your web page (HTML)

Is there a way to upload and play a video file using the video element? I am looking to add a video file to my webpage that can be played using a video element. <input type="file"> <h3>Video to be imported:</h3> <video width="320" ...

How can I align two responsive rows side by side in Bootstrap 3?

Utilizing Bootstrap 3, I'm faced with a challenge to achieve the layout depicted in the image. I have set up one row with two columns, positioned next to each other as shown; however, upon resizing to mobile view, I want the right column to drop below ...

Use JavaScript to dynamically populate dropdown list options with array elements

I attempted to populate a dropdown list with array elements using javascript, but I encountered issues. I referred to the following links for assistance: JavaScript - populate drop down list with array use a javascript array to fill up a drop down se ...

Error with adaptable menu

I am attempting to develop a responsive menu similar to the Bootstrap nav bar using only CSS. I have managed to get the functionality working, but the positioning of the menu grabber is incorrect and I'm unsure how to correct it. The grabber should al ...

Link PayPal payments to the individual making the payment

On my website, I offer in-game features that can be purchased through a miniature store with PayPal buy now buttons. I'm looking for the best and most secure method to automatically deliver these in-game bonuses to users after they have completed thei ...

Is it possible to create a column break within a CSS multicolumn design?

My text content sprawls over a CSS multicolumn layout with two, three, or four columns, utilizing CSS hyphenation. Sometimes, I want to terminate the text in one column early to allow the next paragraph to begin at the top of the next column. Is there a s ...