"Can I create a CSS background cover that is fixed and covers only half of the

Can someone provide guidance on creating a layout that includes a top menu bar area, along with a split 75/25 screen featuring a fixed and covering background?

--------------------------------------------------------
|                                                      |
--------------------------------------------------------
|                                      |               |
|                                      |               |
|                                      |               |
|                                      |               |
|                                      |               |
|                                      |               |
--------------------------------------------------------

The main left-hand area should scroll vertically like a normal webpage.

The top menu bar should also scroll with the main content.

However, the right-hand area needs to have a fixed background that scales and covers the entire region (utilizing the CSS cover property) without scrolling.

I've been able to achieve some parts of this layout separately but struggling to get everything to work together seamlessly!

Currently, I'm facing an issue where the background image in the RHS area is not positioning correctly within the block. The backgrounds are in place and fixed, but the RHS background doesn't seem to fit perfectly:

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

<style>
html {
height: 100%;
width: 100%;
}
body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
.lhs {
width: 75%;
float: left;
background: url(lhs_bg.jpg) repeat left top;
}
.rhs {
width: 25%;
float: right;
background: url(rhs_bg_1.jpg) no-repeat left center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>

</head>
<body>

<div class="lhs">

lhs

...(content for lhs)...

</div>
<div class="rhs">

rhs

...(content for rhs)...

</div>

</body>
</html>

The numbers indicate the vertical scrolling behavior in both areas to demonstrate how the page extends beyond the browser height.

It seems like the background image in the RHS area is still sizing to cover the full screen rather than just fitting the parent div element. As a result, only a part of the image is visible in the RHS area instead of the complete image coverage.

Any suggestions or tips to resolve this issue would be greatly appreciated!

Answer №1

Do you want to achieve something like this? http://jsfiddle.net/oneeezy/kc4umn1c/1/

 /* Rows (clears floats) */
.row:before, .row:after { content: " "; display: table; }
.row:after { clear: both; }
.row { *zoom: 1; clear: both; }

.wrapper { margin: 4em auto 0; height: 100%; }
header { background: black; position: fixed; top: 0; left: 0; right: 0; padding: 1em; color: white; }
main { width: 75%; float: left; display: block; background: #f2f2f2; padding: 1em; }
nav { width: 25%; float: left; display: block; background: yellow; padding: 1em; position: fixed; right: 0; top: 5em; }
p { background: white; padding: 2em; margin: 1em 1em 2em; }

Answer №2

Are you in search of something like the following?

I implemented the code snippet below to enable scrolling on the site:

<head>
 <title>My Website</title>
 <style type='text/css'>
    body {
      background-color: #EEE0A7;
      margin:0px;
      min-width:1200px;
    }
    .container {
      text-align: center;
      display:block;
    }
    #rightbanner {
      background-color: orange;
      width: 25%;
      float: right;
      margin-top: 1em;
      margin-right: 2%;
      min-height:250px;
      padding:10px;
    }
    #content {
      position:relative;
      min-width:475px;
      background-color: orange;
      margin-left: 2%;
      margin-right: 30%;
      min-height:350px;
      margin-bottom:1em;
      margin-top:1em;
   }
   #filler {
      min-height:700px;
   }
   h2 {
     padding:0;
     margin:0;
     font-size:1.2em;
   }
   a {
     color:black;
     font-family: "Times New Roman", Georgia, Serif;
   }
   p {
     padding:0;
     margin:5px;
   }
  `.item {
     width:468px;
     margin:0 auto;
     padding: 0;
     border:gray solid 2px;
     border-radius:10px;
     }
   header {
     top:1em;
     margin-right:2%;
     margin-left:2%;
     background-color: orange;
     height: 3em;
     margin-top:1em;
   }
   h1 {
     margin-top:0;
   }
   }
   #search {
     display:none;
   }
   </style>
   </head>
   <body>
     <div class="container">
       <header>
         <a href="#"><h1>My Website</h1></a>
       </header>
       <div id="rightbanner">
         <div  id="search">
           <b>Search Box:</b><br>
            <form method="get" action="#">
              <input type="text" id="search_input" name="search" placeholder="Search"/><br>
              <input type="submit" value="Search"/>
           </form>
         </div>
         <b>MENU</b><br>
         <div id=navbar>
           <a href='#'>Site 1</a><br><a href='#'>Site 2</a><br>      
         </div>
       </div>
       <div id="content"><br>
             ...
       </div>
     </div>
   </body>

Answer №3

Do you need the background to remain fixed on the right-hand side div while the content scrolls over it?

You should take a look at this informative article:

Following the guidelines from that article, here is what I implemented:

<html>
<head>
    <style>
    html {
    height: 100%;
    width: 100%;
    }

    body {
    margin: 0px auto;
    background-color:blue;
    }

    #menu{
    height:250px;
    background-color:green;
    }

    #container{
    position:relative;
    }

    #lhs {
    width: 75%;
    float:left;
    background: url(lhs_bg.jpg)repeat left top;
    }

    #rhs {
    width: 25%;
    float:right;
    background-image:url(rhs_bg.jpg);
    background-repeat:no-repeat;
    background-position:50%;
    background-size: cover;
    }
</style>

</head>

<body>

<div id = "menu"></di
 v>
<div id = "container">
    <div id = "lhs">
        lhs
    <br /><br /><br /><br /><br /><br />1
    <br /><br /><br /><br /><br /><br />2
    <br /><br /><br /><br /><br /><br />3
    <br /><br /><br /><br /><br /><br />4
    <br /><br /><br /><br /><br /><br />5
    <br /><br /><br /><br /><br /><br />6
    <br /><br /><br /><br /><br /><br />7
    <br /><br /><br /><br /><br /><br />8
    <br /><br /><br /><br /><br /><br />9
    <br /><br /><br /><br /><br /><br />10
    <br /><br /><br /><br /><br /><br />11
    </div>

    <div id="rhs">
        rhs
    <br 

/><br /><br /><br /><br /><br />1
    <br /><br /><br /><br /><br /><br />2
    <br /><br /><br /><br /><br /><br />3
    <br /><br /><br /><br /><br /><br />4
    <br /><br /><br /><br /><br /><br />5
    <br /><br /><br /><br /><br /><br />6
    <br /><br /><br /><br /><br /><br />7
    <br /><br /><br /><br /><br /><br />8
    <br /><br /><br /><br /><br /><br />9
    <br 


/>10
    <br /><br /><br /><br /><br /><br />11

</div>
</div>

</body>
</html>

This method ensures that the background image in the right div remains fixed and centered within the right div.

Answer №4

Consider inserting the following code into the .rhs section

right: 0px;
position: fixed;

Check if this aligns with your requirements. Alternatively, are you suggesting the rhs content should also move up while keeping the background static?

In that scenario, simply include an additional div for rhs with only a background style. Example.

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

Tips for ensuring text is consistently aligned at the top using CSS and div elements

After receiving guidance from stackoverflow, I created this HTML and CSS structure. However, the small text on the right is appearing vertically positioned at the top of the larger font above it. Despite trying different solutions, I haven't been able ...

One-time PHP form submission only

On my website, I offer a variety of PDF download options. To access these downloads, I encourage visitors to sign up using a form. After signing up, they receive a direct link to the chosen PDF in their email. My goal is to streamline the process so that ...

Having trouble uploading images using ReactJS on the web platform

I am currently in the process of developing a portfolio website using react js, but I'm experiencing an issue where the image I intended to display is not showing up on the live site. Despite thoroughly checking my code, I can't seem to identify ...

Selenium not registering click on enabled element

I am trying to trigger a click event on an element on the page, but for some reason the Selenium click function is not working as expected. Here is the relevant code snippet: username_form = driver.find_element_by_id('form3-username') passwor ...

How to eliminate spacing between photos in a flexbox layout

[Unique] Find the Solution Image inside div has extra space below the image My design showcases various images of different sizes in multiple rows. See an example here. Despite my efforts, there are noticeable gaps between the rows that I can't seem ...

Streaming RTMP video through a WebView

Currently, I am working on implementing rtmp streaming using WebView. To achieve this, I referred to the code provided on Stack Overflow under this link The easiest way to play an audio RTMP stream in Android, which was shared by a user named Club. After a ...

Creating tabbed content with a classless CSS design by utilizing radio buttons instead of the traditional unordered

I am attempting to transform the classless CSS and HTML provided below from a list format to using radio buttons and labels for tabbed content. My goal is to make it concise and avoid redundancy. Here is the setup of what I am aiming for: <nav> ...

What is the process for linking functionality to buttons in Embedded Elixir?

When it comes to rendering templates, I follow this method: <%= for country <- @countries do %> <div> <div>A compilation of countries you have visited</div> <a href="/countries/<%= String.downcase(country) %& ...

"Adjusting the width of columns in a Datatable

I have arranged a data table with multiple rows and columns, and I am seeking guidance on how to increase the width of the "Tel. 1, Tel. 2, and Fecha" columns to ensure that the text appears on a single line. I've attempted adjusting the s width and t ...

Guide to adjusting the position of a dropdown menu within a navigation bar

ANSWER BELOW HTML: <div class = "navbar"> <a href = "index.php">NON-HOVER</a> <div class="dropdown"> <a href = "index.php">HOVER</a> <div class="dropdown-c ...

PHP - Printing out various embedded HTML quotes

My goal is to display the following line of HTML using PHP echo "<a class='fa fa-ban fa-2x cancelClass' onClick='cancelClass('$id', '$formattedDate', '$time')'></a><p class='text-center ...

My goal is to populate all of these elements with Javascript

My goal is to have all the boxes filled with "excellent": https://i.sstatic.net/oHW6W.png let a = document.querySelectorAll('.select2-choice'); a.forEach((e) => {console.log(e)}) a.forEach((e) => {e.innerHTML = ` <span ...

Issues arise with the functionality of the sticky navigation script following a browser resize

I recently came across a jQuery script for sticky navigation that I've implemented on a website. $(function() { // get the initial top offset of the navigation var sticky_navigation_offset_top = $('#sticky_navigation').offset().to ...

How come when I applied height:100% and position: absolute to .test2, it ended up being 200px instead of the expected 204px

Upon setting the height of a container element to 200px, I encountered an issue when trying to set the height of another element within it to 100%. The height didn't render as expected, as height:100% takes the height of the parent element, which was ...

What is the process to extract the displayed font using JavaScript?

One interesting feature of Google Chrome is that it displays the rendered font in DevTools. For instance, when you have the CSS code: font-family: Montserrat, Helvetica, sans-serif; and the Montserrat font is not available or disabled, Chrome will indic ...

"The challenges faced while working with a PHP script on a mySQL table, including problems related to the FROM_UNIX

I am tackling my first PHP script for a MySQL table. My SQL table is structured as shown below: https://i.sstatic.net/Chjiw.png My goal is to create a dynamic HTML table from this data with the following criteria: The HTML table should be sorted in as ...

Tips on adjusting the color of a link once it has been clicked?

Looking for a link with a specific style? a { color: #999; &:hover { color: #008da0; } &:visited { color: #999; } /* I added this to test if it's gonna fix it, but it didn't */ } Upon clicking the link, it turns blue and remains s ...

What steps should be taken to transform this object into code?

In the code snippets provided below, I am trying to achieve the design outlined in the image. .stone-item{ width: 330px; transition: all .2s ease-in-out; -webkit-transition: all .2s ease-in-out; -moz-transition: all .2s ease-in-out; ...

hyperlinks along the edges surrounding a centrally positioned image

I'm facing an issue with an image that is also a link. I used the following code: <a href="link.html"><img src="img.png" id="cloud"></img></a> After, I centered and resized it with the help of this CSS: #cloud { display: blo ...

What is the process for adding information to the database when the checkbox is selected?

In my database, I have a table named "absent" that stores the ID of students and classes for absent students. Below is a table with student names, each accompanied by a checkbox. I am trying to insert into the absent table the IDs of students whose check ...