Creating a nested div with a consistent image background

I have set an image background on the first div. Now, I am looking to create a div (illustrated here with an orange background) and another box placed "above" it for comments (referred to as the "comments box").

The issue I am facing is that I do not want the content of the "orange zone" to appear underneath it.

Currently, this is what I have:

The problem with my current code is that some of the content I place in the "orange zone" div ends up going under the Comment box, which is not visually appealing.

Here is a link to a jsfiddle showcasing this issue: http://jsfiddle.net/uu0xe2xL/1/:

HTML

<body class='example-page'>

<div id="content">
  <div class="page-main-image" >
  </div>
  <!--div with orange background -->
  <div id="orange-zone">  
  </div>
  <!-- comment box -->
  <div class="comment-box comment" style="opacity: 1;">
      xxx it's cool to comment<br/>
      nice one dude
   </div>
</div>
</body>

CSS

html {
    height:100%;
}

body.example-page {
    height:100%;
}

#content {
    height: 100%;
    margin-top: 18px;
    @media (max-width: 767px) {
        margin-top: 9px;
    }
}
.page-main-image {
    height: 100%;
    background: url('http://www.thedrum.com/uploads/drum_basic_article/115509/main_images/BBCb.jpg'); background-size: cover; background-repeat: no-repeat;
}

#orange-zone {
    position:fixed;
    top:10%; 
    left:30%;
    width:100%;
    height:100%; 
    background-color:orange;
}
.treasure{
  position: absolute;
}

.comment-box {
  position:relative;
  text-align: center;
  background-color: rgba(255, 255, 255, 0.3);
  padding: 10px;
  bottom:5%;
  right:5%;
}
.comment {
  position:absolute;  
}

Desired Outcome

Notice how the orange area never extends under the Comment zone, but the background image with an island remains visible under the "comment box," which is the desired effect.

Additionally, I need to add text to the orange zone, and I cannot place the background image in the body tag as it needs to start right after the menu, having a container of its own.

Feel free to make changes to this jsfiddle

Answer №1

The concept here involves utilizing borders to form a solid background color. Take a look at the demonstration and accompanying notes below.

View JsFiddle Demo

html, body {
    height: 100%;
    margin: 0;
}
/* establishing the background image */
.container {
    background: url("http://i.imgur.com/V4xzKOv.jpg") 0 0 no-repeat;
    background-size: cover;
    position: relative;
    height: 100%;
}
/* creating the borders */
.container:before {
    content: "";
    display: block;
    background-color: rgba(0, 0, 0, .25);
    position: absolute;
    right: 20px;
    bottom: 20px;
    border-style: solid;
    border-color: orange;
    border-width: 20px 30px 90px 190px;
    width: 120px;
    height: 60px;
}
/* positioning the text */
.container p {
    position: absolute;
    width: 280px;
    right: 50px;
    bottom: 45px;
    overflow: auto;
    padding: 0;
    margin: 0;
}
/* creating placeholder and floating it */
.container p:before {
    content: "";
    float: right;
    width: 120px;
    height: 60px;
}
<div class="container">
    <p>Gingerbread tootsie chocolate. Cheesecake gummi bears I love caramels gummies cake oat cake tootsie roll. Ice cream sesame snaps. Biscuit gingerbread I love gummi dragée bear chocolate cheesecake.</p>
</div>

Answer №2

If you're finding that the border solution created by sdcr isn't effective for your needs, there is another approach you can take. You can match the background color of the inner div to that of the outer div, and adjust the background-position so that they align perfectly. Additionally, a color layer has been incorporated for added visual appeal.

* {
    margin: 0;
    padding: 0;
}

#background {
    background-image: url('http://www.desktopaper.com/wp-content/uploads/tropical-island-wallpaper.jpg');
    width: 700px;
    height: 700px;
}

#innertext {
    width: 200px;
    height: 200px;
    background-color: yellow;
    position: absolute;
    top: 50px;
    left: 50px;
}

#transparent {
    width: 100px;
    height: 100px;
    position: relative;
    background-image: url('http://www.desktopaper.com/wp-content/uploads/tropical-island-wallpaper.jpg');
    background-position: -75px -75px;
    top: 25px;
    left: 25px;
}

#colorlayer {
    background-color: rgba(255, 0, 0, .3);
    height: 100%;
}

Access the example on jsfiddle

In addition, it's worth mentioning that this process can be easily automated using JavaScript if desired.

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

Incorporate a corner box feature to bring attention to the typed.js functionality

I have successfully integrated typed.js into my project and now I am looking to replicate the highlighted text with an excel-like box in one corner. I've managed to get the text typing out while also adding an SVG for the box in HTML, but I'm hav ...

Modifying the font style and color of text within the table header - Material Table version 0.19.4

Recently, I began using React and Material UI but have encountered an issue with modifying the color and font of text in the table header. Despite attempting to override it, the default style remains unchanged. It has been mentioned that utilizing "heade ...

Sticky sidebar navigation paired with a scrollable main content area and anchor links

Examining the fiddle reveals a straightforward page layout with a fixed menu on the left and scrollable content. I am looking to align the menu with the content without any blank space at the top that causes the menu to shift upwards while scrolling down. ...

My attempts to load the .mtl and .obj files using THREE.js have been unsuccessful

I've been working on creating a 3D model viewer using three.js, but I'm encountering issues with loading .mtl and .obj files. Despite following a tutorial at , the only model that loads successfully is the female one. Here is the code snippet I ...

How can a functional component be created in VueJS using x-templates?

Looking to create a functional component in VueJS with a template as a single-file component? Utilizing x-templates means your component will be stored in a .html file. Want to transform the given component into a functional component? <!-- my_compone ...

Spontaneous gradient background occasionally failing to load as expected

My to-do list is simple and functional, but I'm encountering an unusual issue with the background. The background is supposed to be a random gradient set using JS upon loading the HTML, but sometimes it doesn't apply at all. If you refresh the Co ...

Angular ng-repeat failing to display data as expected

I've been attempting to create a table from a JSON structure, but I'm having trouble getting it to display correctly. The output is not appearing as expected for the first two cells; "Partial" is empty and only filling the last one. You can see ...

Maximizing efficiency in Office Automation programming by choosing individuals proficient in Javascript and PHP

I am seeking a solution where upon selecting a department checkbox, the employees belonging to that department will be displayed in the second div. This way, I can easily select an employee and have their information displayed in a separate section. I al ...

Issues with the presentation of HTML DIV elements

I am puzzled by a situation where my HTML layout to present financial data does not seem to update properly in certain browsers. Despite using jQuery and inspecting it with Firebug, the visual display of the parent divs remains unaltered. This issue become ...

Setting the parent's height to match one of its children

I'm struggling to align the height of the pink '#images-wrap' with the main image. When there are too many small rollover images on the right, it causes the pink div to extend beyond the main image's height. If I could make them match i ...

Using a subheader in conjunction with a virtual repeater in markdown does not function correctly

Currently, I am utilizing angular 1 along with angular material. I am trying to incorporate md-subheader with multiple md-virtual-repeat-containers within an ng-repeat loop. The source code can be found on this codepen. The issue I am facing is slightly c ...

Applying ngClass to handle positive and negative numbers and adjust color in Ionic/Capacitor

I have data from my API that includes price and percentage data. I want to display negative numbers in red, and zero or positive numbers in green. After exploring Angular documentation, I found that ngStyle and ngClass can be used for this purpose. I chose ...

Show HTML form elements on the page using jQuery or JavaScript

Is there a jQuery or JS library that can perform the following task: If the user inputs 'x' in A01, then make A01_1 visible. Otherwise, do nothing. <form id="survey"> <fieldset> <label for="A01">A01</label&g ...

Can you explain the purpose of the behavior: url(); property in CSS?

While browsing the web, I came across a CSS property that caught my eye. It's called behavior, and it looks like this: #element{ behavior: url(something.htc); } I've never used or seen this property before. It seems to be related to Internet ...

Tips on making scrollable content within a static div element

I am currently working on designing a shopping cart layout for a website that allows users to order food from a restaurant. I want the shopping cart to remain fixed on the screen, but be scrollable when there is an overflow of items being added. This is a ...

Hide Details tag only on mobile view

How can I easily close the default opened <details> tag on mobile? I am working with Wordpress. Any suggestions on how to achieve this? <details open> <summary>Details</summary> Something small enough to go unnoticed. </ ...

When the browser is refreshed, jQuery will automatically scroll the window down

I created a div that matches the height and width of the window to simulate a "home screen." When scrolling down to view the content, everything works fine. However, after refreshing the browser, it automatically scrolls back to where you were before. I wa ...

Is it possible to retrieve the pixel color of a mesh by clicking on it in JavaScript?

On the current page, we have a mesh loaded with TreeJS and displayed in a canvas: https://i.sstatic.net/j8Ztj.png Is there a way to retrieve the color of the point where a click occurs? I attempted a method suggested in this thread: Getting the color val ...

Implementing translation text into a PHP database

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Translate and Save Text</title> </head> <body> <form action="" method="post" name="theform"> <table width="693" border="1" style="table-l ...

Incorporating HTML elements within VBScript within a single document

Here is a code snippet that mixes VBScript and HTML: IF (x.name="name") THEN n=x.value response.write("<tr>") response.write("<th>Name:</th>") response.write("<td><input name=""n2"" value=" & n & ">< ...