Content obscured by a div element

I've created a cloud using HTML/CSS and I'm struggling to position some text in the center of it. Unfortunately, I can't get it to overlap the cloud divs properly.

#cloud {
    height: 230px;
    margin: 40px;
    position: relative;
    width: 400px;
}

#cloud div {
    border: solid 5px black;
}

#bottom_c {
    background-color: #fff;
    border-radius: 100px;
    height: 150px;
    position: absolute; 
    top: 100px;
    width: 350px;
    z-index: 0;
}

#right_c{
    background-color: #fff;
    border-radius: 100%;
    height: 150px;
    left: 140px;
    position: absolute; 
    top: 40px; 
    width: 150px;
    z-index: -1;
}

#left_c{
    background-color: #fff;  
    border-radius: 100%;
    height: 100px;
    left: 50px;
    position: absolute; 
    top: 70px; 
    width: 100px;
    z-index: -1;
}

#cloud::before {
    background-color: white;
    border-radius: 50%;
    content: '';
    height: 100px;
    left: 55px;
    position: absolute; 
    top: 75px; 
    width: 100px;
    z-index: 1;
}

#cloud::after {
    position: absolute; top: 45px; left: 145px;
    background-color: white;
    border-radius: 50%;
    content: '';
    width: 150px;
    height: 150px;
    z-index: 1;
}

.text {
  overflow: hidden;
  position: absolute;
  z-index: -2;
}
<div id="cloud">
  <div id="bottom_c"></div>
  <div id="right_c">
    <p class="text">
      this is some unique text
    </p>
  </div>
  <div id="left_c">

  </div>
</div>

I'm not sure how to resolve this issue, as setting the z-index doesn't seem to be working as expected. Do I need to place the p tags inside another div? Any help or suggestions would be greatly appreciated!

Answer №1

Reorganize the structure by moving the text element to the same level as the border divs. This will keep them all within one main container.

#cloud {
    height: 230px;
    margin: 40px;
    position: relative;
    width: 400px;
}

#cloud div {
    border: solid 5px black;
}

#bottom_c {
    background-color: #fff;
    border-radius: 100px;
    height: 150px;
    position: absolute; 
    top: 100px;
    width: 350px;
    z-index: 0;
}

#right_c{
    background-color: #fff;
    border-radius: 100%;
    height: 150px;
    left: 140px;
    position: absolute; 
    top: 40px; 
    width: 150px;
    z-index: -1;
}

#left_c{
    background-color: #fff;  
    border-radius: 100%;
    height: 100px;
    left: 50px;
    position: absolute; 
    top: 70px; 
    width: 100px;
    z-index: -1;
}

#cloud::before {
    background-color: white;
    border-radius: 50%;
    content: '';
    height: 100px;
    left: 55px;
    position: absolute; 
    top: 75px; 
    width: 100px;
    z-index: 1;
}

#cloud::after {
    position: absolute; top: 45px; left: 145px;
    background-color: white;
    border-radius: 50%;
    content: '';
    width: 150px;
    height: 150px;
    z-index: 1;
}

.text {
  position: absolute;
  top: 40px;
  left: 135px;
  z-index: 2;
}
<div id="cloud">
  <div id="bottom_c"></div>
  <div id="right_c"></div>
  <div id="left_c"></div>
</div>
<p class="text">this is some text</p>

Answer №2

By making the following adjustments to your HTML:

<div id="cloud">
  <div id="bottom_c"></div>
  <div id="right_c"></div>
  <div id="left_c"></div>
</div>
<p class="text">
  this is some text
</p>

and updating the CSS for the text element like so:

.text {
  overflow: hidden;
  position: absolute;
  z-index: 2;
  top:200px;
  right:200px;
}

this should resolve the issue.

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

PHP response is blank when password_hash or password_verify functions are used

My application utilizes JavaScript to retrieve a string and send it via POST to a PHP file on the server for processing. The PHP receiver is responsible for parsing the string, performing tasks, and sending back status updates to JavaScript. However, after ...

"Revolutionary AJAX-enabled PHP social commenting system with multi-form support

Why is it that when I submit forms using these ajax functions in PHP, they only send to the first form on the page? I have multiple forms under each article and I want them to be submitted separately. What am I doing wrong? ...

Overlap one element entirely with another

Currently, I am working on a way for an element called overlayElement to completely cover another element known as originalElement. The overlayElement is an iFrame, but that detail may not be significant in this scenario. My goal is to ensure that the over ...

A step-by-step guide on uploading a CSV file in Angular 13 and troubleshooting the error with the application name "my

I am currently learning angular. I've generated a csv file for uploading using the code above, but when I try to display it, the screen remains blank with no content shown. The page is empty and nothing is displaying Could it be that it's not ...

specified variables and functions within jquery

There is a jQuery file with all methods and properties defined at the top. I want to make changes in the file for study purposes. Can you tell me what this type of file is called? function ImageFlow () { /* Setting option defaults */ this.de ...

The CSS for selecting the input[type="submit"] element is not functioning as expected

I apologize but I am encountering an issue with my .css stylesheet that covers styles for my input type buttons as shown below. input[type="submit"] input[type="submit"]:hover input[type="submit"]:focus The first three selectors are functioning well, how ...

Exploring the functionalities of radio buttons and arrays in a Javascript experiment

Currently delving into the world of Javascript and struggling to wrap my head around creating a test using only pure Javascript (no jQuery). The goal is to: Present users with a question and provide radio button options for selection. Allow users to cho ...

How can you center two inline form buttons using HTML and CSS?

I am completely new to HTML and CSS. I am currently attempting to center two form buttons on a page. Below you'll find the code snippet that I have been working with: * { font-family: arial, sans-serif; } body { display: flex; align-items: c ...

Trouble with background image displaying on meteor platform

Hey there! I'm in the process of replicating the HBO login page without functional links, but for some reason, the background image isn't loading properly. I suspect it might be an issue with resizing the image, but I can't pinpoint the exac ...

Utilizing the Bootstrap grid system allows for input fields to automatically expand to 100% width once they reach

I am encountering some challenges while attempting to develop a responsive form using bootstrap grids. The issue seems to arise when resizing the browser window, as the grid classes behave unexpectedly by expanding and taking up the entire page width at ce ...

Steps for creating a two-dimensional arc

I want to input some pre-determined acr values from another program and replicate them in three.js Currently, I'm using code I found on this site to draw the arc, although it might not be the most optimal solution. function DRAWarc(){ ...

Showing a DIV container upon hovering over a different element

Having trouble with a hidden div container not displaying properly upon hovering over a visible div container. When d1 is hovered over, d2 appears but with a blinking effect. Here is my code: Note: I want d1 to remain visible and use d2 for displaying te ...

"Freezing issue with Angular big table causing web page to lock up during

Looking for a way to improve the performance of an HTML table search function that is currently running very slowly and freezing the web page upon loading and searching. The table needs to be within the HTML file itself, not pulling data from a server. Any ...

What is the best way to implement an Android-style tab bar using Bootstrap for web pages?

Can you provide guidance on using Bootstrap to create an Android tab bar similar to the one seen in the WhatsApp application for web pages? Thank you for your assistance. ...

Showing the value of a JavaScript variable within an HTML input field

Here is an interesting HTML structure that includes a list and input field: <li> <span>19</span> </li> <li> <span>20</span> </li> ...

In need of assistance with filtering lists using JQuery

Hi there! I'm looking to modify a list filtering function by targeting multiple ul tags within the same div instead of just filtering li elements. Any ideas on how this can be achieved? Below is my JavaScript code: $( document ).ready(function() { ...

Enhance your Razor Pages with Bootstrap 5's floating control for input groups featuring buttons and datetime pickers

I don't have expertise in Bootstrap or CSS. I'm attempting to build an input for DateTime with arrows on the sides using Bootstrap 5 and Razor Pages. My initial tries did not yield satisfactory results. I want an ItemGroup that includes a DateTi ...

Hey there, I have a header.css file!

My React project is experiencing issues with the CSS file. The first header in the CSS file works fine, but the second header and every other class created after it are not responsive. Only the 'header' class is properly linked to Header.css file ...

Modify the bootstrap dropdown background to display only an image

I am looking to make the image in a dropdown/dropup menu fill the entire background of the dropdown. Currently, there is still white space visible around the image. How can I ensure that the dropdown shows only the image and includes a scroll wheel? Addit ...

Choose all the alternative A radio buttons utilizing JavaScript

If the "4 stars" option is selected at the top, I want all corresponding "4 stars" options in the form to be automatically selected. Similarly, if "3 stars" is chosen, I need all the "3 stars" options to be selected. I attempted to achieve this functionali ...