Ways to implement CSS for limiting the scrollable width of a div element in a web browser

Can anyone guide me on using CSS to limit the scrollable width of a page when the browser is not maximized? An example can be seen on the landing page of

When the browser is maximized, there is space around the lady in the picture, but as you reduce the browser area, scrolling becomes restricted.

I'm aiming for a similar layout as . However, with my current code, the image gets cut off on the right side when I shrink the browser window and try to scroll right.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; 

charset=utf-8" />
<title>Untitled Document</title>
<link href="ave.css" rel="stylesheet" type="text/css" />

<link href="gh.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#EEEEEE">
<div id="bigpicturecontainer"></div><!--image size is 1600px x 

400px and can be downloaded here 

http://www.ghanabuildingplans.com/trial.png
-->

<div id="bigmessage">Content for  id &quot;bigmessage&quot; 

Goes Here</div>
</body>
</html>

Here's my CSS code:

#bigpicturecontainer {
background-color: #000;
background-image: url(images/trial.png);
background-repeat: no-repeat;
background-attachment: scroll;
background-position: center center;
height: 400px;
width: 100%;
}
#bigmessage {
height: 45px;
width: 900px;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
margin-top: 50px;
font-size: 36px;
text-align: center;
margin-left: auto;
margin-right: auto;
}

Success! Simply setting the min-width solved the issue.

Answer №1

Presented here is an image overlaying another background. The figure depicted in the image can be viewed by following this link: Notice how there is a smooth transition to black on one side. Beyond this, the underlying background-image features a simple solid black background.

background-image: url(../../images/LayoutNMHP/hero-image-tablet-couch.jpg);
background: #000

For further information on CSS backgrounds, check out this resource: http://www.w3schools.com/css/css_background.asp

Answer №2

The image you are referencing is actually incorporated into the website as a CSS property called background-image. Its visibility is determined by the element it is placed within, such as the .hero div in this case. This particular div has a fixed height, with its width set to 100% by default. The image is centered within the div, ensuring that it will always fit perfectly regardless of the window size. This setup prevents the image from causing the website to overflow outside of the window.

.hero {
    background-color: #000;
    background-image: url(http://cdn.lynda.com/assets/197-r20131102/Website/ui/images/LayoutNMHP/hero-image-tablet-couch.jpg);
    background-repeat: no-repeat;
    background-attachment: scroll;
    background-position: center center;
}

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 do I switch back and forth between displaying content as 'none' and 'block' using JQUERY?

Take a look at this code snippet. <div class="sweet-overlay" tabindex="-1" style="opacity: 1;display: none;"></div> Is there a way to switch the style attribute value from none to block and back? ...

Ways to add a CSS class to an ID that immediately follows

I've been working on an editable table using the HTML5 attribute contenteditable. Everything was going smoothly until I had an idea to highlight the cell that was just updated by adding a class called alert-danger from Bootstrap. Once a cell is succe ...

What methods are available to generate dynamic shapes using HTML?

Looking to create an interactive triangle where users can move vertices or sides, updating angles in real-time. I'm struggling with how to accomplish this task. My initial attempt was to manually draw the triangle using the code below. <!DOCTYPE ht ...

The <h1> element is not responding to the style attribute

Exploring HTML as a beginner has led me to an interesting issue. I've been practicing my newfound skills on W3Schools' platform and everything was running smoothly until I encountered a discrepancy in how the code is rendered on Wordpress. The s ...

Unusual grey rectangle (similar to a selection tool) found in the top left corner of a contenteditable div on

I recently utilized Vue to create a contenteditable div on my website. However, I encountered an issue where a gray area appeared on the upper left corner when hovering over the div. Oddly enough, this problem only occurred in Chrome, while Safari and Fire ...

Concealing Form Values with Radio Buttons using HTML, CSS, and PHP

I'm working on creating a sign-in form with multiple options. I want users to be able to choose between signing in with their username or email using radio buttons. I'm wondering if there's a way to achieve this using HTML, CSS, and PHP, or ...

What is the best way to use flexbox to horizontally and vertically center a div within another div?

Is there a way to perfectly center a div both horizontally and vertically within another div using flexbox? If you've looked at other Q/A threads like this one or that one, you may find them too specialized for your needs. ...

The HTML checkbox appears disproportionately large on the user's screen when using Firefox and Chrome, but not when using Internet Explorer

There seems to be a strange issue that I've come across. One of our QA tester's computers is displaying an HTML checkbox in a very large size when using Firefox and Chrome, but it appears normal in size when viewed in IE. Meanwhile, on my comput ...

Ways to center text in a div using vertical alignment

/* Styles for alignment */ .floatsidebar { height: 100%; float: left; overflow: hidden; width: 30px; line-height: 1.5; } .vertical-text { height: 100%; display: inline-block; white-space: nowrap; transform: translate(0, 100%) rotate(-90 ...

Failure to link style sheet to document

Experiencing some difficulties with a seemingly simple task that I can't figure out. When I check my code in the browser, none of my styles are being applied to the HTML elements. The style sheet is located in the same folder as the main document, and ...

The expansion animation for the Nextjs/React accordion box did not work as expected when utilizing tailwindcss

I am currently working on creating an animation for a collapsible box (accordion). My goal is to have the child component initially hidden with display:none. When I hover over the parent component, the child should be revealed and the dimensions of the pa ...

Creating CSS for a specific class on a single webpage can be achieved by targeting that class

Here is my custom style: <style> ul { padding:0 0 0 0; margin:0 0 0 0; } ul li { list-style:none; margin-bottom:25px; } ul li img { cursor: poin ...

What could be the reason for lxml not being able to locate this class?

Trying to extract text from a webpage using Python has always been tricky, especially with the surprises lxml tends to throw. Here's what I attempted: >>> import lxml.html >>> import urllib >>> response = urllib.urlopen(&a ...

Using a function as a parameter for the background-image url in jQuery

Can I send a function as an argument to the background-image URL parameter in jQuery? Is it possible to achieve something similar to this example... jQuery('<span>').css('background-image', 'url(' + check_file_type(val ...

Struggling with combining CSS stylesheets?

I am looking to incorporate the vertical timeline feature from CodyHouse into a project utilizing a Bootstrap template hosted on Github. I have successfully transferred the HTML content, however, there are some complications with the CSS files. The issues ...

Every third item is selected using a JQuery selector

Currently, I am tackling the task of working with PHP loops to generate multiple li elements within a single ul. The issue arises when I attempt to display every fourth li upon clicking one of the preceding three li. My current implementation only toggles ...

I prefer to disable the toggle feature if the target remains unchanged

My goal is to create a step-by-step ordering system using the data-id="x" attribute to determine which content should be visible when selected. I want to make sure that if two elements have the same data-id, clicking on one will deselect the other. Any su ...

What is the best way to retrieve the value of a chosen option utilizing Javascript or Jquery?

I have been working on a custom select box and I am trying to retrieve the value of the selected label. When I click the "check" button, an alert pops up showing the code inside the div, which makes sense. However, I am wondering how I can extract the valu ...

The height of my text input box in HTML and CSS keeps fluctuating

I've encountered an issue while creating a search bar. The text input box and search button are positioned next to each other as intended, but the height of the input box fluctuates when I expand the browser window. I have thoroughly reviewed my code ...

What are the steps to modify the appearance of an input box in IE7 when it is in focus?

It's common knowledge that IE7 has its fair share of issues... I've scoured through countless posts here and on Google, all pointing me towards setting the style manually with onfocus() and onblur(). Alas, nothing seems to be working! This is t ...