Tips for concealing elements beyond div boundaries

First and foremost, I want to mention that my focus is on studying frontend development, so I could really use some assistance with a task.

I am looking to create a tab slider where the content on the left and right will flank it, ensuring the tab slider remains centered.

The tab slider should consist of two buttons: < (slide to left) and > (slide to right).

Within the tab slider, there are numerous elements whose total width exceeds the max-width of the parent div (which has the "content" class).

To address this issue, I attempted to apply

overflow: hidden;

However, these elements ended up shifting to the second row.

div.menu {
  width: 100%;
  display: block;
  float: left;
}

div.content {
  display: inline-block;
  width: 50%;
  max-width: 50%;
  background-color: lightgray;
  max-height: 40px;
  overflow: hidden;
}

div.left,
div.right {
  display: inline-block;
  width: 24%;
  background-color: green;
}

div.flex {
  display: flex;
}

ul,
li {
  display: inline-block;
}

li {
  background-color: yellow;
  width: 30px;
}
<div class="menu">
  <div class="left">something in left</div>
  <div class="content">
    <div class="flex">
      <i><</i>
      <ul>
        <li>i-1</li>
        <li>i-2</li>
        <li>i-3</li>
        <li>i-4</li>
        <li>i-5</li>
        <li>i-6</li>
        <li>i-7</li>
        <li>i-8</li>
        <li>i-9</li>
        <li>i-10</li>
        <li>i-11</li>
        <li>i-12</li>
        <li>i-13</li>
        <li>i-14</li>
        <li>i-15</li>
        <li>i-16</li>
      </ul>
      <i>></i>
    </div>
  </div>
  <div class="right">something in right</div>
</div>

What am I missing here?

I had hoped that by using overflow and max-height, the exceeding elements would be hidden (on one row to the right) rather than shifting to the second row.

Here is an example of my issue.

Could you provide me with some guidance on how to resolve this?

Answer №1

To ensure all items stay in the same line, utilize white-space: nowrap within the .flex container.

div.menu {
  width: 100%;
  display: block;
  float: left;
}

div.content {
  display: inline-block;
  width: 50%;
  max-width: 50%;
  background-color: lightgray;
  max-height: 40px;
  overflow: hidden;
}

div.left,
div.right {
  display: inline-block;
  width: 24%;
  background-color: green;
}

div.flex {
  display: flex;
  white-space: nowrap;
  position: relative;
}

ul {
  padding-left: 10px;
  padding-right: 10px;
}

ul,
li {
  display: inline-block;
}

li {
  background-color: yellow;
  width: 30px;
}

.flex i {
  position: absolute;
  top: 10px;
}

.flex i.prev {
  left: 0;
}

.flex i.next {
  right: 0;
}
<div class="menu">
  <div class="left">something in left</div>
  <div class="content">
    <div class="flex">
      <i class="prev"><</i>
      <ul>
        <li>i-1</li>
        <li>i-2</li>
        <li>i-3</li>
        <li>i-4</li>
        <li>i-5</li>
        <li>i-6</li>
        <li>i-7</li>
        <li>i-8</li>
        <li>i-9</li>
        <li>i-10</li>
        <li>i-11</li>
        <li>i-12</li>
      </ul>
      <i class="next">></i>
    </div>
  </div>
  <div class="right">something in right</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

Leveraging AngularJS ngBind with a JavaScript object

Within the given string, integrating a javascript object and embedding it into an ngBinding does not result in proper evaluation. I have a string where I want to incorporate a specific part of a javascript object and am transitioning to Angular for its use ...

Achieving an oval shape using HTML5 and CSS3: Step-by-step guide

<!DOCTYPE html> <head> <title> Oval shape</title> </head> <body> <div style="width:400px; height:400px; background-color:#ff0;">Oval</div> <p> Exploring the creation of an oval shape using HTML5 ...

Load CSS styles once the HTML content has been generated by the PHP script

One way to dynamically add a section of HTML during page load is by making use of PHP in the index.php file: In your index.php file, you can include a section like this: <html> <head> <link href="css/style.css" rel="stylesheet"> ...

Is it possible to programmatically hide the Textarea and submit button for each row in a PHP-generated database table?

After spending a considerable amount of time on this project, I'm looking to incorporate a JavaScript effect (hide/unhide) into a basic submit form. Although the functionality is successful, it seems to be limited to only one row in the database tabl ...

HTML border width is set to 100%, but there seems to be an issue with the responsive menu border and icon display

One issue I'm encountering with my website involves the border at the bottom of my navigation bar. Despite trying to adjust the box-sizing property to border-box, I still can't get it to display correctly. My goal is to have the border span 100% ...

Retain values of JavaScript variables acquired by their IDs even after a page refresh

I have a JavaScript function that retrieves HTML input values and inserts them into a table. However, when I refresh the page, those values are reset to null. How can I prevent this and keep the values visible after a refresh? I believe setting and getting ...

Simple Selection Panel

Looking to include a simple dropdown menu with 5 choices. Once a selection is made, an answer corresponding to that choice will appear in another field next to it. For example: Choosing France from the dropdown would display 'Paris' in the adjac ...

"Create a dynamic box grid with varying heights using the responsive design features of Bootstrap

I have been attempting to create a responsive grid consisting of 6 textboxes using the box class and bootstrap. My issue is that due to varying amounts of text in each textbox, they end up with different widths/heights. However, I want them all to have th ...

Utilizing the calc() function to determine height dimensions

I created a very simple layout with 5 divs, which can be viewed here: http://jsfiddle.net/8tSk6/. In this layout, I want the div with the ID "kubka" to have a height of 100% - 100px (height: calc(100% - 100px);). However, I am running into issues as it i ...

Switch between different content sections using a button in a Bootstrap tab-pane

Here is the code snippet I am currently working with: <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-s ...

Using a PHP variable to trigger the jQuery .show() function

I'm attempting to trigger jQuery .show() events based on PHP variables. Below is my PHP code (retrieved from a form submission on another page): $last_pic_displayed = trim($_POST["last_pic_displayed"]); if (strlen($last_pic_displayed) <= ...

Position the text alongside the Facebook emblem

I am having trouble getting the text Follow Us to align on the far right next to the Facebook Icon. I added the float:right property, but it is not working as expected. Here is the code snippet: <a href="#" target="_blank" style="font-family: Arial, ...

Ensuring Bootstrap4 columns have a minimum height within a row

How can I adjust the right column in this image layout to crop the height and match it with the left column, aligning the bottoms of the images? This customization should only apply to lg+ screen sizes. An ideal solution using Bootstrap 4 without jQuery i ...

Having trouble applying CSS while printing using the ngx-print library in Angular 14. Can anyone help me out with this issue

The table shown in the image is experiencing issues with applying CSS properties when printing. While the background graphics feature has been enabled, the preview section still does not reflect the CSS styling. What could be causing this discrepancy? Cli ...

Certain parts of the CSS grid are not aligning properly within the grid lines

I'm having trouble with my CSS grid. The red section fits in the first square, but the rest of the content seems to be out of place in the grid. I'm new to all this and I can't figure out what I'm missing. I've tried everything but ...

Fixed width blocks automatically adjusting to small containers

When I try to add text to my absolute block inner div, it doesn't expand as expected. I am aware that expanding within a parent container with a specified width, such as <div class="main_wrap"></div>, can be problematic. Unfortunately, I ...

Is it possible to create a translucent glass floating box over HTML elements, similar to the frosted glass effect seen in iOS7?

Creating an overlapping div with a frosted glass effect typically requires using an image background (like ). I am interested in having a floating div (position:fixed) that can apply a frosted glass effect over any content below it, whether it be an image ...

Display the Ajax response in a designated div

I am facing an issue with my ajax code. It doesn't print any output, but when I use alert() to print the output, it shows up fine. $(".grp-ans").each(function(e){ $.ajax({ type: 'POST', url: 'show-answ ...

Is there a way to customize the timepicker pop-up so that it extends the entire width of the parent form control

<FormControl fullWidth> <LocalizationProvider dateAdapter={AdapterDayjs}> <TimePicker views={["hours", "minutes", "seconds"]} label={t("StrategyManager.Select_Time")} value={timer} ...

"Challenges in styling a table within a div: the text fails to adhere to the

I am struggling to identify the source of a problem in my code. The issue seems to be related to the padding within the parent div, specifically with the text "1 Healthy Midday Meal for One Child Overseas" and how it is ignoring the 5px right padding. Upon ...