Placing a division inside another division element

I am currently having trouble containing a color wheel element within the boundaries of its parent div (speech_bubble_middle_bar).

I understand that the correct approach is to use absolute positioning within a relative positioned div, so I attempted to create a parent container. However, I am facing difficulties in keeping any relative positioned div centered on the screen, and when the div is absolutely positioned, it does not stay within the constraints of the relatively positioned parent div.

Here is my current code snippet. Can anyone assist me in positioning this div so that it remains within the grey colored div? I have other elements within speech-bubble-middle-bar in my actual code, so I need to avoid making changes that would impact other elements. However, I can create a container div for the color_wheel if necessary.

For reference, here is a link to a working code-pen with the complete code: https://codepen.io/TheNomadicAspie/pen/dyWVLyx

<div id="speech_bubble_middle_bar" class="speech-bubble-middle-bar">
    <div id="color_wheel" class="color-wheel"></div>
</div>
.speech-bubble-middle-bar {
  grid-row: 2/3;
  padding-left: 1%;
  padding-right: 1%;
  padding-top: 1%;
  padding-bottom: 1%;
  height: 100%;
  background-color: grey;
}

.color-wheel {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
}

Below is how it currently appears.

https://i.sstatic.net/7Yf8p.jpg

Answer №1

It's a bit of a challenge because two conflicting factors are at play here:

  • On one hand, you want the entire layout to fit on the screen without scrolling, which means everything is sized in relation to the screen's height.
  • On the other hand, the Iro ColorPicker tool appears to have set dimensions in pixels (as per a quick look at the Iro API). This makes the colorpicker's size fixed and independent of the screen or parent height.

The colorpicker's height exceeds 300px. On smaller screens, the grey box will adjust and shrink below 300px, while the Iro ColorPicker will remain static and overflow outside the box. So, there are two choices:

  1. Accept that the colorpicker has a fixed height of 300px and let the grey box resize naturally based on its content. This might mean allowing for scrolling if the bubble's content is extensive.
  2. Make the ColorPicker responsive by setting the width parameter during creation.

To achieve option 2, you can use the provided code snippet, but you may need a more sophisticated solution depending on your requirements.

var background_color_wheel = new iro.ColorPicker(color_wheel, {
   width: 0.12 * window.innerHeight // 12% of the window's height
})

The details of implementing either option may be intricate, as it involves balancing a fixed element with a flexible layout.

There's also a third option which, while less extravagant, is quite effective:

  1. The input tag can use type="color", triggering the user's native color picker. It offers flexibility, semantics, and accessibility. For more information, refer to MDN: Input Color Type

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

The CSS JSON code I have written is not having any impact on the appearance of my div

<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="styles/common.css"> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <script type='text/javascript'> ...

What exactly does the "data-effect" attribute refer to?

After downloading a code, I came across the following line: <button data-effect="st-effect-4">Slide along</button> I noticed that "st-effect-4" is a class name in the code, but I am curious to know what exactly this data-effect attribute is u ...

Experience Image in an inverted carousel or Virtual Reality/Spherical environment

My goal is to create a virtual reality experience similar to this: https://i.sstatic.net/8pZx0.png However, my background image is 4096x1024 and I want it to have a VR effect where the center appears further away from the screen and the edges are slightl ...

Ways to position a div at the center of a page

I've encountered a challenge while creating a mobile website. Within the main div, there are three nested divs. Initially, I aimed for left alignment but now desire to center-align these three divs on the page. Essentially, if the device screen is wid ...

Ways to incorporate a background image using CSS

I tried to add a background image using CSS, but unfortunately, I was unsuccessful in my attempts. body { font-family: Arial, Helvetica, sans-serif; } /* .login-form{ width: 400px; } */ /* Full-width input fields */ input[type=text], input[type ...

Box containing text going in both directions

I am trying to recreate a div structure that features a circle emoji at the top and two text elements at the bottom. However, my attempt is not producing the desired result. Here is my current code: .container { width: 70px; height: 400px; backgroun ...

Is there a method to exclude children objects from spring animations during application?

Is it possible to create a fading in and out effect for a div (for example, to cycle through different backgrounds) while keeping its children (such as text) visible at full opacity at all times? {transitions((style, <animated.div class={ bg[i] + ...

Does the Sass default compiler have built-in autoprefixing capabilities?

Suppose I have the following sample code: :fullscreen a { display: flex; } Is it possible for the default sass compiler to transform it into this: :-webkit-full-screen a { display: -webkit-box; display: flex; } :-moz-full-screen a { display: fle ...

Just FYI - Only the Validation Styles are absent in Bootstrap

Bootstrap CSS (bootstrap.min.css) is successfully referenced and functioning properly. The form-group, btn btn-important, and many other Bootstrap CSS classes are displaying correctly. However, it appears that my validation classes, such as field-validatio ...

The utilization of the <span> tag featuring a {float:right] property causes container expansion in Internet Explorer 7

Within my HTML code, I have an A tag button that contains a Span element to hold icons. This setup functions correctly in most browsers, except for IE7. When I attempt to float the Span to the right side using CSS, it causes issues specifically in IE7, cau ...

Tips for displaying lower quality images while initially downloading higher quality versions

I need to download and display a large image in an img tag. Since the image is not Progressive JPEG, it will render as it downloads. Is there a way to show a low-resolution version of the image while it fetches from the server using only CSS or an HTML p ...

Having trouble finding a hyperlink with CSS selectors

I am attempting to utilize Selenium to retrieve some data from Google, but the CssSelector I have implemented is consistently returning "No element found". Below is my code snippet: //Open google page IWebDriver driver = new FirefoxDriver(); WebDriverWai ...

Creating a Hidden Div That Appears When Clicking a Button in HTML

Currently, I am experimenting with creating a collapsible button solely using HTML and CSS. Below is the code snippet that I have been working on: #hidden { display: none; height: 100px; background: red; } :checked+#hidden { ...

The navigation bar logo on my website has mysteriously vanished

Even though my main website is built with Wordpress, I decided to start a blog using Tumblr. You can visit my website here: And here is my blog: I tried to replicate the same structure of my website on my Tumblr theme. However, I encountered an issue w ...

Is it necessary to capitalize the first letter only when it's not at the beginning of a sentence?

To separate a lengthy string, I followed the approach outlined in this post: .line { display: inline-block; } <p> <span class="line">This text should break</span> <span class="line">after the word "break"</span> </ ...

Is it possible to maintain tab focus instead of visual focus when navigating past the skip navigation menu for improved accessibility?

My website features an accessibility skip navigation menu that utilizes named anchors to navigate to different content areas. These content areas, including the top menu, left menu, main body content, and footer menus, contain links within them. When I u ...

Purchasing a Checkbox alongside its corresponding label

I have been working with the Oracle CPQ tool and am faced with the challenge of creating a checkbox attribute within it. Upon inspecting the UI, I came across the following: https://i.sstatic.net/xE5aH.png Upon examining the browser source code (generat ...

QuickSearch displayed at the center with a floating left alignment

I have been trying to center a QuickSearch div with multiple Q & A sections, but I am having no success. The div is floated to the left and has a background image. HTML <div class="l-row"> <div class="QuickSearch"> <div class="loop"& ...

Using SVG background images in Internet Explorer versions 7 and 8: a guide to HTML, CSS,

I have created a unique SVG image to use as a background, but it's not displaying in Internet Explorer 8 and earlier versions. I tried using tools like or http://code.google.com/p/svgweb/, but they only support SVG for IMG and Object elements, not ba ...

CSS Hack for Internet Explorer 7 Fix

Dealing with styling in IE7 can be quite challenging, especially when working within a WebCenter Portal application where conditional statements cannot be used to load specific stylesheets. Instead, skins are utilized, which are essentially CSS files. Is ...