Make the div larger if the child element exceeds 100%

Trying to ensure that the width of the header matches the intrinsic width of the content as divs are meant to occupy the full width.

Attempted applying overflow:auto to html,body,header

https://codesandbox.io/s/xrn9q6ojxw

<head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />

    <style>
        header {
            display: block;
            background: blue;
        }

        .content {
            width: 2000px;
            background: yellow;
        }
    </style>
</head>

<body>
    <div id="app"></div>

    <header>header</header>
    <div class="content">content</div>

    </script>
</body>

</html>

Expecting the entire page to scroll horizontally and have the width of the header matching either the content or body.

Is there a way for the header or div blocks to extend beyond the viewport's width without explicitly specifying a width?

Answer №1

To achieve the desired layout, it is recommended to add a wrapping div for both the header and content elements. The styling can be applied as shown below.

.wrapper{
  float:left
}
header {
  display:block;
  background: blue;
}

.content {
  width: 2000px;
  background: yellow;
}
<div class="wrapper">
<header>header</header>
<div class="content">content</div>
</div>

Answer №2

Check this out and let me know if it meets your requirements.

CSS

#scroll-container {
  position: absolute;
  height: 100%;
  overflow: scroll;
  overflow-y: hidden;
  white-space: nowrap;  
  background-color: red; 
}

#scroll-wrapper {
    height: 200px;
    width: 100%;
    background-color: red;
    position: relative;
}

.item {
    height: 100%;
    width: 25%;
    display: inline-block;
}

HTML:

<div id="scroll-wrapper">
    <div id="scroll-container">
        <div class="item">
            <h1>HELLO WORLD!</h1>
        </div>
        <div class="item">
            <h1>HELLO WORLD!</h1>
        </div>
        <div class="item">
            <h1>HELLO WORLD</h1>
        </div>
        <div class="item">
            <h1>HELLO WORLD!</h1>
        </div>
        <div class="item">
            <h1>HELLO WORLD!</h1>
        </div>
        <div class="item">
            <h1>HELLO WORLD!</h1>
        </div>
     </div>
</div>

By using this setup, you can achieve an infinite horizontal scroll based on the content provided.

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

How can I use XPath to choose tags that are located close to (both before and after) a

Is it feasible to use XPath to select all br tags that come before and after an h3 element? This XPath expression only captures the first br tag: //h3/following-sibling::*[1][name()='br'] I am looking for a way to target the 2 br tags preceding ...

After calling AJAX, jQuery fails to execute

Encountering an issue with JQuery on a dynamic page. I have a select input: <select id="select"> <option value="1">1</option> <option value="2">2</option> </select> and a text input: <input id="input" type= ...

css - targeting the last child element using a type selector

I'm attempting to target the final child element of type <div> within the container "#myDiv" <div id="myDiv"> <div> <img> <div> <div>text</div> ...

Creating a CSS layout with two columns using Flexbox and varying heights

I'm grappling with the following chunk of code: .wrapper { display: flex; flex-direction: column; flex-wrap: wrap; } .a { background-color: red; width: 65%; } .b { background-color: green; width: 35%; } .c { background-color: blu ...

What might be causing the status problem to not display correctly?

My toggle feature to switch between no issue and issue is not displaying the status correctly. Despite trying to troubleshoot, I can't figure out why the issue section is not showing up. <!DOCTYPE html> <html> <script src="https://aj ...

fancybox thumbs will never function properly

I recently made the switch from using PrettyPhoto to FancyBox for my gallery, which utilizes Isotope for filtering and animations. However, I am encountering an issue where the images appear but the thumbnails are missing. In the developer tools, there is ...

Enhancing the visual appeal of a standard jQuery slider with thumbnails

Recently, I incorporated the Basic jQuery slider into my website, which can be found at . As a novice in jQuery but well-versed in HTML and CSS, I have managed to make it work seamlessly on my site. However, I am curious to know if there is a way to displa ...

Utilizing inline JavaScript to automatically refresh a webpage at specified intervals and monitor for updates within a specific div element

I am currently working on creating an inline script that will automatically refresh a webpage at regular intervals and check for changes in a specific element. If the element meets certain criteria, then the script should proceed to click on a designated b ...

Automatically align to the main grid when dragging begins

Hi there! I'm still getting my feet wet in the world of JavaScript and JQuery, so please bear with me if I'm missing a few tricks. I have managed to make JQuery UI draggable elements align to a grid after the page loads, but I'm struggling ...

What could be causing the width of a table row (tr) in a table element to not function properly, while the height is functioning as expected?

My code is as follows: .table1 { background-color: gray; display: flex; justify-content: ; align-items: ; height: 400px; margin-left: 40px; padding-left: ; } .table1 tr { background-color: blue; height: 50px; width: 50px; } <tabl ...

What steps can I take to update the image displayed in the Google search results for my website?

Check out the image I found on Google search Is it possible to replace the toothbrush image with a different one? Or even remove it completely? In addition, my favicon has been a different image for about a week. How can I update that in the search resul ...

Click Event for Basic CSS Dropdown Menu

My goal is to develop a straightforward feature where a dropdown menu appears below a specific text field once it is clicked. $(".val").children("div").on("click", function() { alert("CLICK"); }); .container { display: inline-block; } .val { d ...

Images in CSS accordion not displaying correctly in WordPress website

It seems like I am overlooking a simple solution here, but it's escaping me. I'm attempting to make a CSS accordion function where each section links to a page. If you want to view the source refer to this link Here is my test site URL: this l ...

Textbox with an icon embedded within - reminiscent of the sleek glyphicon design

I'm working on adding a Symbol to a textbox that needs to always be visible, without involving code behind (when accessing the value of the textbox). It should be like a glyphicon icon. I attempted using a span but it's not appearing the way I wa ...

Ways to incorporate a border line between a pair of icons within a bootstrap card

Incorporating a border line within the card-header is my current goal. My approach involves positioning two icons - one on the left side and the other on the right. Illustrative example below: https://i.sstatic.net/BgxVu.png Utilizing HMTL and CSS to ac ...

phperror message is included and echoed

I am facing an issue while trying to utilize the php include tag for my header and footer sections. Even though my index file and header.php file seem to be error-free, the included file is not showing up when I preview it in a browser. Is there an easy fi ...

The div placed below a dropdown div when viewed on mobile

I’ve been developing a responsive website that works seamlessly on both mobile and desktop. After some tweaking, I managed to get the navigation menu to display just the way I wanted in desktop mode with no dropdowns. However, an issue arises when switch ...

Enhance Your Website with Stunning Bootstrap Icons

I have been attempting to utilize this bootstrap signup template here, but upon rendering it, the icons for the user, email, password, and so forth are not appearing as expected. <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email ...

Monochromatic CSS background transformation upon hovering

Looking for a solution with my CSS sprite setup: Here is the HTML: <a id="estates" href="http://www.domain.com/estate"></a> The corresponding CSS: #estates {background-position: -200px 0px;width: 96px;height: 90px;} #estates {background: u ...

Populating Dropdown list with values based on input provided in Textbox

Can you assist me in finding the solution to this issue? I have a TextBox and a DropDown list. For example, if I type "Anu" into the textbox, I want it to populate the dropdown list based on the text entered. How can I achieve this? I am working with vb. ...