Position the slideshow within the parent DIV element

I'm facing a challenge trying to incorporate a carousel within the boundaries of this div. I experimented with using z-index on the carousel, which did solve the issue but it rendered all other items within it unclickable.

I also attempted setting the border-radius of another wrapper to match, but for some reason, it didn't have any effect. Is there a way to position it behind the div that only serves as a border so that the edges do not overlap?

Thanks in advance.

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n > slides.length) {
    slideIndex = 1
  }
  if (n < 1) {
    slideIndex = slides.length
  }
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
    dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex - 1].style.display = "block";
  dots[slideIndex - 1].className += " active";
}
.main-wrap {
  width: 100%;
  min-height: 200px;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  border: solid red 5px;
  padding: 0;
  box-sizing: border-box;
  float: left;
  margin-bottom: 0;
}

.slides-outer {
  border-radius: 15px;
}

/* Slideshow container */

.slideshow-container {
  position: relative;
  background: #f1f1f1;
}

/* Slides */

.mySlides {
  display: none;
  padding: 80px;
  text-align: center;
}

/* Next & previous buttons */

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -30px;
  padding: 16px;
  color: #888;
  font-weight: bold;
  font-size: 20px;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

/* Position the "next button" to the right */

.next {
  position: absolute;
  right: 0;
  border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */

.prev:hover,
.next:hover {
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
}

/* The dot/bullet/indicator container */

.dot-container {
  text-align: center;
  padding: 20px;
  background: #ddd;
}

/* The dots/bullets/indicators */

.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

/* Add a background color to the active dot/circle */

.active,
.dot:hover {
  background-color: #717171;
}

/* Add an italic font style to all quotes */

q {
  font-style: italic;
}

/* Add a blue color to the author */

.author {
  color: cornflowerblue;
}
<div class="main-wrap">
  <div class="slides-outer">

    <div class="slideshow-container">

      <div class="mySlides">
        <q>I love you the more in that I believe you had liked me for my own sake and for nothing else</q>
        <p class="author">- John Keats</p>
      </div>

      <div class="mySlides">
        <q>But man is not made for defeat. A man can be destroyed but not defeated.</q>
        <p class="author">- Ernest Hemingway</p>
      </div>

      <div class="mySlides">
        <q>I have not failed. I've just found 10,000 ways that won't work.</q>
        <p class="author">- Thomas A. Edison</p>
      </div>

      <a class="prev" onclick="plusSlides(-1)">❮</a>
      <a class="next" onclick="plusSlides(1)">❯</a>
    </div>

    <div class="dot-container">
      <span class="dot" onclick="currentSlide(1)"></span>
      <span class="dot" onclick="currentSlide(2)"></span>
      <span class="dot" onclick="currentSlide(3)"></span>
    </div>

  </div>
</div>

Answer №1

To achieve the desired effect, apply overflow: hidden; to the .main-wrap class. The updated code snippet is as follows:

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n > slides.length) {
    slideIndex = 1
  }
  if (n < 1) {
    slideIndex = slides.length
  }
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
    dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex - 1].style.display = "block";
  dots[slideIndex - 1].className += " active";
}
.main-wrap {
  width: 100%;
  min-height: 200px;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  border: solid red 5px;
  padding: 0;
  box-sizing: border-box;
  float: left;
  margin-bottom: 0;
  overflow: hidden; /* Added property */
}

.slides-outer {
  border-radius: 15px;
}


/* Slideshow container */

.slideshow-container {
  position: relative;
  background: #f1f1f1;
}

/* Rest of the CSS styles remain unchanged */
<div class="main-wrap">
  <div class="slides-outer">

    <div class="slideshow-container">

      <div class="mySlides">
        <q>I love you the more in that I believe you had liked me for my own sake and for nothing else</q>
        <p class="author">- John Keats</p>
      </div>

      <div class="mySlides">
        <q>But man is not made for defeat. A man can be destroyed but not defeated.</q>
        <p class="author">- Ernest Hemingway</p>
      </div>

      <div class="mySlides">
        <q>I have not failed. I've just found 10,000 ways that won't work.</q>
        <p class="author">- Thomas A. Edison</p>
      </div>

      <a class="prev" onclick="plusSlides(-1)">❮</a>
      <a class="next" onclick="plusSlides(1)">❯</a>

    </div>

    <div class="dot-container">
      <span class="dot" onclick="currentSlide(1)"></span>
      <span class="dot" onclick="currentSlide(2)"></span>
      <span class="dot" onclick="currentSlide(3)"></span>
    </div>

  </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

NG-Bootstrap Navigation Bar- dynamic hamburger icon animation

I have been trying to implement an animated hamburger animation on the navbar using ng-bootstrap and Angular, but so far I have had no success. While the Navbar does collapse as expected, it lacks the animation and transformation into an 'x'. I w ...

What is the best way to create a loop with JSON data?

My challenge is to showcase json data using a loop. I have received the following results, but I am unsure of how to display them with a loop. [ {"latitude":"23.046100780353495","longitude":"72.56860542227514"}, {"latitude":"23.088427701737665"," ...

Safari not fully supporting CSS translate functionality

When I click a button on my app, an element slides into view and then slides out when I click the button again. This is achieved using a combination of CSS and JS. It works perfectly in Chrome and Firefox, but only partially in Safari. In Safari, the elem ...

Failure of AJAX Callback Triggering

Behold, behold! Witness the mighty ajax function: function ajax_call(call_method,data_to_send) { logger("Journey with me through the lands of ajax_call. Lo and behold, the data_to_send: "); logger(data_to_send); $('.clickable save_button& ...

Locally hosted website failing to transfer login details to external domain

Having trouble with an ajax call that is supposed to retrieve data from a web page, but instead returns a jQuery parse Error. Even though I can access the page directly, the ajax call doesn't seem to be working and storing the result properly. Below ...

Saving Style Sheets in a Database

Currently, I am interested in saving CSS data in a mySql database as part of my LAMP setup. My intention is to create an input field that includes the following code: body{ background: url("http://google.com/image.jpg") no-repeat; color: orange; } #someDi ...

The PHP script's header() function is failing to execute

Recently, I encountered an issue with my JavaScript code that calls a backend PHP script using AJAX. The main function of the AJAX request is to send user login data (username and password) to the PHP script, which in turn queries this information on the S ...

What steps can be taken to identify the two highest numbers in an array, one being positive and the other

Seeking the optimal solution to resolve this issue Issue: Develop a function called ArrayChallenge (Javascript) that takes a single argument "arr" representing an array of numbers. The function should return the string true if there exist two numbers in t ...

Deletion of a custom function in JavaScript

I have written some basic code to generate and remove an image using functions. Specifically, I need help with removing the image created by the function Generate() when a button linked to the function Reset1() is clicked. Here's the code snippet for ...

Automatically selecting a div using jQuery upon loading the page

Hello everyone. I've implemented some jQuery code that allows div elements to slide horizontally when a link is clicked. However, upon page load, no link is clicked and therefore no div is visible (only the ul is visible). I would like to have the div ...

Troubleshooting CSS override issues when swapping components in ReactJS

Access.js import React from 'react' export default class Access extends React.Component { componentWillMount(){ import ('./styles/access_page.css'); } .... <Link to="/new-account">Sign Up</Link> } Cr ...

Changing the value of a focused input in the Android browser using programming methods

Is it possible to enforce a specific date format (00/00/0000) on a text input field? The input field has a maxlength of 10 characters, and validation is being handled separately. Below is the jQuery code snippet I am currently using: $(function( ...

Two adjacent div tags spanning the full width of the page, with differing widths (40% and 60%) that resize to 100% width and stack on top of each

I've been experimenting with a layout challenge and running into some obstacles. Two div tags are at the heart of the issue. Div A features an image with a default size of 768 x 400, while Div B displays an image at 1152 x 400. These images are meant ...

"Despite receiving a successful response from curl, AWS Lambda and API Gateway return a 500 error when accessed from a

I am facing challenges with AWS Lambda and API Gateway. While I can successfully call my API using curl and Postman, I am unable to do so from my browser. It works when: curl --header "Content-Type: application/json" \ --request POST \ ...

Uploading files with jQuery using Rails and CarrierWave with Amazon S3 storage

I'm relatively new to using jquery file uploading plugins and libraries. Currently, I am working on developing an image uploader that can load images via jquery/ajax on the frontend without requiring a site update as the image is uploaded. Then, I ne ...

The overflowing pop-up container

When I trigger a popup that dynamically generates a fixed background with a centered dialog, it works well. However, on smaller monitors like laptops, tablets, and phones, the content can overflow beyond the visible area due to its fixed container, making ...

Empower the parent container to wrap around its child elements using Flexbox

I am trying to make the flexbox parent item adjust its width based on the children, but currently it is stretching out to full width and leaving empty space on the right side. Here is the CSS code I have tried: .flexParent { display:flex; background:# ...

JavaScript Node only providing numerical values and not returning correct data types

I am currently working on using JavaScript Node.js to retrieve data from a MySQL query and display it on a webpage. Right now, I am only able to view the results of the query in the console. Here is the code snippet: var mysql = require('mysql' ...

Personalize the Facebook like button to suit your preferences

I have posted my code on jsfiddle. You can find the link here: http://jsfiddle.net/QWAYE/1/. I have also included another sample code in this link: http://jsfiddle.net/MCb5K/. The first link is functioning correctly for me, but I want to achieve the same a ...

Is it possible to implement Ajax functionality in JavaScript without using XMLhttp and connection the same socket for every request?

Can data on a page be communicated and updated without the need for reloading, all while avoiding the XMLHttpRequest object and using the same connection or socket for each request (without closing the connection each time)? ...