Ways to make a child div extend beyond its parent's width, but only up to the width of the screen

Let's start by reviewing the JSFiddle example - check it out here.

The issue lies in the styling and positioning of the div with the class class="overflow-parent". Although the class name seems descriptive, this div is actually intended to display the site content.

The horizontal and vertical divs with the red border are meant for navigation features, and the goal is to have the content displayed inside them. Specifically in this example:

  • The content (the green-bordered div with a paragraph containing "aaaaa..") should be positioned next to the red vertical menu without overflowing it as it currently does.
  • The class="overflow-parent" should overflow its parent on the right side only to the size of the screen, rather than creating horizontal scrollbars as seen now.

In addition, I'd like the height of the vertical menu (red-bordered div) to at least match the display height. If the content exceeds the screen's height, the menu's height should adjust to match that of the

<div class="overflow-parent">
, where the page content is displayed.

While I may lack experience in design, the structure and approach presented are my own. There may be more efficient ways to achieve the desired result without these issues, as long as the final appearance remains unchanged.

EDIT Keeping the navigation centered is crucial, hence the use of the .container class.

.container {
  width: 970px;
  padding-left: 0px;
  padding-right: 0px;
  margin-right: auto;
  margin-left: auto;
}

The container needs to remain at a width of 970px and centered, resulting in white space on both sides. Due to the presence of the vertical menu, the left side will remain empty while I aim to utilize the right side fully without exceeding the screen width.

Answer №1

The paragraph within the green-bordered div should be aligned next to the red vertical menu without overflowing it, as it is currently doing.

Removing the position: absolute; property will help achieve this.

The "overflow-parent" class should only overflow its parent container on the right side up to the width of the screen, rather than causing a horizontal scroll like it does now.

Setting the width to auto (width: auto;) should resolve this issue.

I have added the following properties:

to .vertical-menu

width: 25%;

to .overflow-parent

width: auto;
max-width: 72.6%; /* adjust for border width */
word-wrap: break-word; /* prevent layout disruption by long words */

Example Link

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

I aim to utilize vanilla JavaScript in order to remove the parent element of the button being clicked when the user interacts with it

My latest project involves a meme generator that allows users to input text and images, which are then combined to create a unique 'meme'. Each meme is assigned a unique ID and features buttons for deleting the meme upon hovering. To achieve this ...

Storing multiple email addresses in an array using an HTML input element

I have a small React Bootstrap form where I am trying to save multiple email addresses entered by the user into an array. However, when I use onChange={()=> setEmails(e.target.value as any} it stores them in string format like this --> [email p ...

Align text to the left and right with a centered div

Visualize the asterisk * at the center of the div textAlignRight * text AlignLeft This is essentially my goal to accomplish <center> <span class="left_host">Right aligned</span> * <span class="righ ...

Unable to fetch JSON values using Jquery

I'm struggling to identify the error in my code. The line $.getJSON is designed to fetch data through an AJAX request by passing the currently selected fruit name. The retrieved data, which consists of an array with 'variety' index containi ...

Creating a Link Between Two Elements in Javascript

Currently in the process of developing a method to generate a single-line diagram using Javascript. I have successfully implemented a function that connects two html elements as shown below: adjustLine (from, to, line) { var fT = from.offsetTop + from. ...

Using JavaScript and jQuery to fill a div with content from an external file

Feeling extremely frustrated at the moment. I am struggling to make this work and can't figure out why it's not working. My current challenge involves populating a div with content from another HTML file. Below is the code snippet: <script s ...

I'm just getting started with codeigniter and I'm looking to incorporate pagination into my data table using ajax

Currently I am utilizing dynamic data table bootstrap 4 and I aim to incorporate pagination into my table View: <form role="form"> <div class="card-body"> <div class="row"> <table id="example1" class=" ...

The dropdown feature fails to function properly when contained within a Bootstrap Popover

Utilizing jQuery v1.12.4, Bootstrap v3.3.7 and Bootstrap-Select v1.10.0. In a popover, I have 2 components. When the popover is opened, I am able to interact with the dropdowns but the selection does not change when clicking an option. You can view the e ...

What is the best way to assign a JavaScript return value to a PHP variable?

Is it possible to capture the return value of a JavaScript function that checks if text boxes are empty and assign it to a PHP variable? I have successfully created a JavaScript function that returns false if any of the text boxes are empty, but now I ne ...

How to deactivate the dropdown hover effect in ngx-intl-tel-input

Issue: When hovering over the dropdown items in the country list, I'm encountering a gray background color that I'd like to remove while still maintaining the functionality of the dropdown. Despite attempting to set background-color: transparent ...

Utilizing Next.js Image Component to Apply CSS for Width and Height Settings

Currently, I am utilizing the Image component provided by Next.js, which requires setting specific width and height values. To address this, I am incorporating Tailwind CSS utility classes to establish the desired dimensions. https://i.sstatic.net/A28fB.j ...

RSelenium: Struggling to retrieve specific text snippet from table

Check out this webpage. I am trying to extract the text '2013'. I am currently using RSelenium, but open to other package suggestions as well. Here is my current script: startServer() remDr <- remoteDriver(browserName="chrome") remDr$open(si ...

Generate visual at reduced quality (three.js)

Is there a way to reduce the resolution of my rendered canvas similar to how it can be done with the Blender camera resolution? I came across a suggestion to use renderer.setDevicePixelRatio(window.devicePixelRatio) However, when I tried this, the objec ...

What do attributes and parameters in the HTML Flash tag signify?

Can you identify all the parameters and attributes used in the code below, explain their significance, and why they are necessary? What parameters and attributes should be included or excluded when using a Flash tag within an HTML page? <object id="vf ...

Page not loading Ajax function upon initialization

I am currently experimenting with this: https://github.com/derekmartinez18/Simple-Ajax-Spotify-Now-Playing and have created a simple function to display my Spotify listening activity: function get_spotify() { $.ajax({ type: 'POST', url: ...

Place the DIV element above the Input Box while keeping the Input Box in its current position

Is there a way to incorporate a DIV above an input box (textbox) without causing the textbox's position to change? I want this DIV to appear or disappear based on whether the textbox is in focus or not. What is the correct CSS syntax to place this DIV ...

What is the method that Google uses to automatically load the footer at the bottom of the web page?

Google manages to keep its footer at the bottom of the browser regardless of resolution when fully maximized. How can I achieve a similar effect? ...

What is the best way to display index.ejs when the input field is blank?

If the input field is left empty when I click the form button, I want to redirect to "/". After clicking the button, the desired URL should be: http://localhost:3000 Header.ejs <form action="/search" method="GET"> < ...

Implementing image upload functionality with jQuery

I am currently working on developing an announcements module for my website and I would like to give users the ability to upload 3-5 photos along with their announcement. I am in search of a pre-existing solution that will enable users to upload photos, se ...

JavaScript encountered an error stating that $ is undefined and has not been defined in the program

I am facing an issue while trying to submit a form in Django using AJAX. The error message displayed in the console is giving me a hard time in identifying the root cause. Despite trying several solutions, I have not been able to resolve this issue. Here i ...