as you lower a div element, the background image will also be shifted

While working on a rails project, I mastered all the rails elements easily. Surprisingly, I encountered an issue with CSS this time - something that is not usual for me as I usually face Ruby problems!

The problem arises when trying to move a div element further down the page that has a background image set. It seems like the div and the background image are linked in some way. Below is the code snippet:

HTML:

<div class="about_background">

 <div class="container heading_block">
    <h1 class="about_heading"><i class="fa fa-flask"></i> About Abby <i   
    class="fa fa-cutlery"></i></h1>
 </div>

</div>

CSS:

.about_background {
background-image: url("bread.jpeg");
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-attachment:fixed;
}

.heading_block {
background-color: rgba(200,100,175, 0.8);
border-radius: 35px;
}

.about_heading {
text-align: center;
font-size: 50px;
}

If anyone can spot what's missing or offer guidance, it would be greatly appreciated. I attempted to create a jsfiddle but couldn't achieve the desired outcome. You can find the code on Github under ravenusmc, food_blog. Thank you in advance for the assistance!

Answer №1

If you are attempting to relocate the div, the code snippet below demonstrates a common method used for moving elements:

.heading_block {
position: relative;
top: 10px; //adjust this value to set the desired distance of movement
background-color: rgba(200,100,175, 0.8);
border-radius: 35px;
 }

Answer №2

It seems to me that you're suggesting to include...

min-height: 100%; in the about_background class.

Answer №3

I'm a bit puzzled by the issue you seem to be facing.

  1. Could you clarify which div you are attempting to move? If it's the first (outer) div, then the background will move along with it since it is connected to that container. The background-attachment property won't alter this behavior. To demonstrate this, try resizing your window and observe how the background remains locked in position relative to your screen, scrolling within the container upon resizing.

  2. When I tested moving the second div (the inner one), the background stayed stationary.

If necessary, consider attaching the background to the body element to achieve the desired fixed positioning.

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

Using a regular expression to replace text within a TextNode with a new DOM node

I am currently working on a function that preprocesses a Text Node within the HTML DOM. The main objective is to carry out interpolation or string templating. Essentially, the function examines occurrences that match the regular expressions /\${([^}] ...

Assistance needed with Angular 2 form for integrating backend features

Attempting to develop backend functions for a form within an Angular 2 project. While I successfully completed the front end portion, I am encountering difficulties with the backend implementation. The goal is to input data into the fields and upon hitting ...

Tips for troubleshooting objects within an Angular template in an HTML file

When I'm creating a template, I embed some Angular code within my HTML elements: <button id="btnMainMenu" class="button button-icon fa fa-chevron-left header-icon" ng-if="(!CoursesVm.showcheckboxes || (CoursesVm.tabSelected == 'curren ...

How can recursive data be displayed in a template?

I am working with a model in Django that has a ForeignKey pointing to itself, and I need to display all the data from the database using lists and sublists: Below is my model definition: class Place(models.Model) name = models.CharField(max_length=1 ...

Codeigniter: Troubleshooting Session Variable Issues

Hey there! I'm facing an issue with my session variable in Codeigniter. I have set the session variable in my model, but when I try to access it in my view through the controller, the value of the session variable becomes null. Any suggestions on how ...

Personalizing CSS for showcasing bot icon next to bot reply container

I'm currently working on modifying the layout of this HTML page. I want to include a bot icon next to each bot response, and I also need to decrease the space between consecutive messages. https://i.sstatic.net/lBiMD.png Any suggestions on how I can ...

Run an ajax function when a variable is populated with data

My current dilemma involves a session variable email=$_GET['email'];. I am seeking a way to trigger an ajax function only when this variable is available, and to set it to do nothing if the variable is not present. What is the technique for invo ...

Display the button only if the specified condition aligns with the input data

I am working on a project where I have an input text field that retrieves data from a database using a combination of JavaScript and PHP. get.html is responsible for fetching the data through JavaScript. function showUser(str) { if (str == "") { ...

Render inline CSS styles with AngularJS

Can we use angular variables to write inline CSS styles? <div style="background: transparent url({{eventInfo.eventHeaderImg}}) top center no-repeat;"></div> Here is the output I received: "NetworkError: 404 Not Found - http://test/eventInfo. ...

"Enhance user experience with jQuery's text expansion and collapse

Figuring out how to collapse and expand text with a button click has been challenging for me. I managed to make the text collapse when the button is clicked, but now I also need it to expand back again. The goal is to have the text initially hidden, then e ...

Creating multiple divs with input fields dynamically using JavaScript is a useful skill to have

I need to generate 3 input text boxes for gathering user input on names and email addresses. These inputs must be created dynamically, meaning that as the user clicks on the email input field, a new line with all three elements should be generated. Below i ...

I need to verify that the input type for time is valid, starting from today's date and extending beyond the current

<input type="date" onChange={(e)=>setDate(e.target.value)}/> <input type="time" onChange={(e)=>setTime(e.target.value)} /> If the selected date is after today and the time is after the current time, display a valida ...

Centering text within a dynamic div can help create a visually appealing design

While browsing through various forums, I noticed several questions on stackoverflow that touch upon a similar issue to mine. However, my particular problem is a bit unique, and despite my best efforts, I have not been able to find a solution yet. It's ...

Is it possible to include ternary in the "homepage" section of the package.json file?

When making API calls in production, they will be on the same domain as where my app is hosted, so it's necessary to include "homepage": "." in the package.json. However, when working locally from localhost, I need to make API calls to the production ...

Seeking assistance in incorporating an image into a drop-down menu

I am in the process of integrating a CSS based drop-down menu into my Wordpress website, and I need assistance with adding an image on the right side of my links when a user hovers over them in the menu. Below is the code I currently have, along with a ref ...

When the text exceeds its container, the CSS property overflow will display only the

.example{ overflow:auto; } <div class="example"> <p>Some Additional Text Here<P> </div> This particular code snippet showcases the initial portion of the text, allowing for scrolling down to reveal items 5 and 6: 1 2 ...

Issue with horizontal scrolling in ng-scrollbars occurs when scrolling from right to left

We are currently developing a single page application that supports two languages, one being right to left and the other left to right. For scrolling functionality, we have implemented ng-scrollbars, an Angularjs wrapper for the malihu-custom-scrollbar-pl ...

I'm having trouble with keeping my centered form in place when I try to use container-fluid. How can I ensure it stays in the center?

https://i.sstatic.net/IYEvl.png While attempting to apply a gradient color to the entire screen, I encountered an issue where the centered form within a card was shifting to the left when using the container-fluid class. Below is the code snippet: <di ...

Using jQuery, discover if a script tag is present within a paragraph tag

I have encountered a situation where there is a script tag inside an HTML <p> element. For example: <p> <script> function essb_window1149322389(oUrl, oService) { essb_window_stat(oUrl, oService, 55311); }; </ ...

Building an HTML Form for Requests

Having some trouble creating an HTML form, particularly with resizing the Fieldset and legend elements. As a novice programmer, I am practicing building HTML forms. My goal is to have the form adjust its size based on the window without displacing the cont ...