Switching from fixed positioning to fluid

After hastily creating a web widget in jsFiddle with absolute positioning for prototyping purposes, I now find myself struggling to convert it to relative positioning. In addition, I am working on transforming it into a jQuery UI widget and need everything to seamlessly integrate onto the page without any complications.

You can view the widget HERE. Essentially, it is a search box that allows for filtering with the left-most button.

The key components are:

  • #refine: The left-most button.
  • #refineDropdown: The dropdown menu that appears when you click on the refine button.
  • #search: The input box.
  • #dropdown: The live-type search filtering box.
  • #submit: The right-most search button.

Question: When developing a widget, should positioning be relative or absolute? If there are multiple instances of this widget on a page, the position of the dropdowns should be independent of their location on the page. However, I am struggling with understanding how to achieve this using positioning and HTML structure.

CSS Code:

(CSS code will not be displayed here)

Answer №1

It is commonly believed that relative positioning is preferred over absolute positioning because absolute positioning is thought to always be based on the page itself. However, this is not true.

In reality, absolute positioning is determined by the first parent element with a set position attribute. To address this, one simple solution is to enclose your widget within a div and specify that div's position as relative.

For instance:

<p>adsadds
   <div class='container'>
       <div class='absolutelyPositioned'>BlaBla</div>
   </div>
sddasda</p>

Using the following CSS:

.container
{
    position: relative;
}

.absolutelyPositioned
{
    position: absolute;
    top: 100px;
    left: 100px;
}

The inner div containing "BlaBla" will now be positioned relative to the container div rather than the web page coordinates, adjusting accordingly if the content layout changes.

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

Intermittent rendering problems in Chrome due to CSS printing with a fixed header and footer

I am attempting to customize the format of an e-commerce receipt for printing, including a fixed header and footer that will appear on every printed page. However, I am encountering intermittent issues. Sometimes, the layout works correctly, while other ti ...

Challenges with styling DIV elements using CSS

Currently working on a website and I've been dividing it into columns with the property: float: left; However, when viewed on a smaller resolution or if I resize the browser window, the div cells collapse on top of one another like boxes stacking up ...

The CSS3 animations are lightning quick and the background image appears slightly unsteady

Is there a way to slow down the background change and stop it from shaking too fast? If so, please help me with this. HTML <!-- Banner --> <section id="banner"> <div class="inner"> <h2>Enhancing Your <br />Ways&l ...

Switching downlink to top link when scrolling downwards

I have a downward scrolling link on my homepage that moves the page down when clicked by the user. However, I am struggling to make it change to a "back to top" link as soon as the user scrolls 10 pixels from the top. Additionally, I am having trouble with ...

Examples of how to specify a child class in CSS

Presented here is the following structure: <article class="media media--small 48"> <a href="#"> <img src="" class="media__img" alt=""> <i class="s s--plus"></i></a> <div class="media__body"> < ...

Expand the object by clicking on it, causing the surrounding objects to move outside the viewport instead of appearing below

I'm facing a challenge with 3 squares inside one container, each occupying 33.33% of the viewport and placed next to each other. When I click on one square, it should expand to full viewport width and reveal hidden content, while the other two remain ...

Ways to style the horizontal div using CSS

I am looking to create a horizontal div using CSS that looks like the one shown in the image below. image reference ...

What's causing Angular to not display my CSS properly?

I am encountering an issue with the angular2-seed application. It seems unable to render my css when I place it in the index.html. index.html <!DOCTYPE html> <html lang="en"> <head> <base href="<%= APP_BASE %>"> < ...

Obtaining the Initial Values of a jQueryUI Slider

I have integrated the jQueryUI slider into my project and need to show the minimum and maximum values of the slider in two separate div elements. These divs should update as the user interacts with the slider, and also display the initial values of the sli ...

Leveraging the ng-hide property of one controller to adjust the ng-style attribute of another controller through a centralized global controller

Seeking assistance with accessing the boolean value of ng-hide from one controller in order to alter CSS properties of another controller utilizing a global controller. Here is the jsfiddle link: https://jsfiddle.net/dqmtLxnt/ HTML <div ng-controller= ...

Assistance with CSS Selectors in Selenium WebDriver for Date Selection

Could someone assist me in selecting a date from the small window using CSSSelector or any other method? Below is an example of HTML code for reference. <td class=" " onclick="DP_jQuery_1468593787056.datepicker._selectDay('#dp1468593787059',1 ...

Update the picture and assign a class for the currently selected menu or button

I am currently working on creating interactive buttons that change an image when hovered over and clicked. The active button should have a specific class applied to it, which will be removed once another button is clicked. However, I have encountered some ...

The picture does not occupy the entire page

Here is a simplified version of my HTML and CSS: @keyframes animatedBackground { from { background-position: 0 0; } to { background-position: 100% 0; } } *{margin:0;padding:0;}/*added as requested*/ .background-image { background-im ...

I need either XPATH or CSS to target a specific checkbox within a list of checkboxes wrapped in span tags

I'm trying to find the XPATH or CSS locator for a checkbox in an HTML span tag that has a label with specific text, like "Allow gender mismatch". I can locate the label using XPATH, but I'm not sure how to target the input tag so I can click on t ...

Glass-pane or angular/HTML overlay on a designated element

Is there a way to create a glass-pane effect, like an hourglass symbol on a semi-transparent layer, within the boundaries of an HTML element E? The goal is to have the glass-pane only overlap the area within E's boundaries. When the glass-pane is ac ...

Encase a table cell containing a lengthy word

I attempted to implement the solution outlined here: How to wrap table cell at a maximum width in full width table However, I am facing difficulties in wrapping the line containing "xxxxxxxxxxxxx". <table class="my-list table table-bordered table-hove ...

positioned absolutely with a margin of 0 auto

Struggling to find a way to center the text in the wrapper? I have a responsive slideshow that requires text to be on top of it and centered. ul.bjqs { position:relative; list-style:none; padding:0; margin:0; z-index: 1; overflow ...

When using WYSIWYG editors, be on the lookout for empty paragraphs and incorrect code in CSS, JavaScript, and

I am currently in the process of redesigning a website for a client. The site is already built using Joomla 1.7, but I am facing an issue with the articles section that was created by the client using a WYSIWYG editor. The problem lies in the messy code st ...

when an element is hovered over, it activates a reaction on a different element

I've been struggling with the Events assignment we were given. I tried writing my own code, but it had so many errors when I got it checked. I couldn't quite grasp all the explanations of what went wrong, so now I feel a bit embarrassed to share ...

Struggling to ensure buttons on my page respond and resize properly alongside the other elements

Despite making most of this page responsive, I'm having trouble getting the two buttons to scale appropriately. They are utilizing javascript for a mouseover effect, and I suspect that might be causing some issues. Ideally, I would like the images to ...