Position the div at the center of its parent container, disregarding any floating

I am attempting to generate a 'section' division with a header. The goal is for this header to have a centered title and the possibility of including a jquery UI button on its right side. The width of the 'section' division will be determined by its containing element.

My issue lies in achieving proper center alignment of the title when there is also a button present.

HTML:

<div style="width: 600px;">
    <div class="section purple">
        <div class="sectionHeader">
            <div>Normal Title</div>
        </div>
        <div class="sectionContent"></div>
    </div>
    <div class="section blue">
        <div class="sectionButtonIcon"> <a id="btnExample">Jquery UI Button</a>
        </div>
        <div class="sectionHeader">
            <div>Title With Button</div>
        </div>
        <div class="sectionContent"></div>
    </div>
</div>

Check jsFiddle for css styling: http://jsfiddle.net/agAgeas50/uL9Uc/8/

Please note: This query is distinct from Center inline-block div in parent while ignoring floating elements. In that post's jsfiddles, if you wrap the parent in another container with a fixed width, the right-hand element extends beyond the parent.

Answer №1

make changes to the code below

.section.blue {
   position:relative;
}

.sectionButtonIcon {
     position:absolute;
    right:0px;
}

http://jsfiddle.net/uL9Uc/9/

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

Is there a way to show a loading icon during the image change process without using jQuery?

How can I add a loading icon to an image change event without using jQuery? I'm new to the coding world and Stack Overflow community, so please bear with me. I've been searching for a solution to my specific situation but haven't been able ...

Issue caused by overflowing content and resizing the display

I am facing a challenge with my website. Essentially, my webpage has the <html> set to overflow:hidden, with two horizontal navbars, a fixed vertical sidebar on the left, and a central div with the height: 90% property. Edit: The container div now ...

Display function not functioning properly following AJAX request

I'm working on a functionality where I want to initially hide a table when the page loads, and then display it with the results when a form is submitted using Ajax. The issue I'm facing is that the code refreshes the page and sets the table back ...

The background of the ACTK Modal Popup vanishes after multiple instances of scrolling up and down

The issue I'm facing is with the AJAX Control ToolKit Modal Popup's background (the blind curtain) disappearing after scrolling up and down several times. I have attempted to resolve this by applying various CSS styles, but unfortunately, none of ...

What is the method for showcasing an h1 heading and an unordered list link side by

Can you help me align my h1 and ul elements on the same line in my header? I want to have my logo and navigation links next to each other (This extra text is just filler) Below is the code snippet: HTML: <div id="header"> <h1>Logo</h1> ...

Maintain the proportional scale of images set to a percentage with window resizing

Currently working on developing a web application. The images in the app are sized using percentages, with three overlapping another image that functions as a toolbar. Everything looks great when viewed in fullscreen mode, but the problem arises when the s ...

I am looking to implement user authentication using firebase, however, the sign-in page is currently allowing invalid inputs

<script> function save_user() { const uid = document.getElementById('user_id'); const userpwd = document.getElementById('user_pwd'); const btnregister=document.getElementById('btn-acti ...

Crafting a stylish vertical timeline using Tailwind and CSS: Step-by-step guide

I am attempting to design a timeline for a react app where odd children are displayed on the left side of the timeline and even children on the right side. Here is an image for reference: https://i.sstatic.net/YnNFU.png The issue I am facing is that I am ...

Preventing the collapse of the right column in a 2-column layout with Bootstrap 3

I've recently begun exploring Bootstrap and am attempting to achieve the following: (Left column - larger) Heading Heading 2 Heading Image Heading Image Heading Address (Right column - smaller) Heading Paragraph List items My issue ...

Tips for automatically redirecting a webpage to another webpage upon submission of form elements:

I'm currently working on a website where I want to integrate radio buttons as part of a form. Below is the code snippet I've been using... <form action="glitter.php" method="post"> <input type="radio" name="font" value="fonts/darkcrysta ...

Switch the navbar background color from see-through to black

On my website, I have set up a navbar navigation that transitions between a transparent background and a black background as the user scrolls down. However, I would like the black background to be present at all times for the navbar. I built the website us ...

Expand the <div> to match the complete height of its containing <div> element

There are multiple div blocks within a parent block: one for the menu on the left, and one for the text on the right. How can you make the right inner block stretch to the full height of the parent block like the left one? The parent block has a minimum he ...

Ensuring the custom element receives focus only when the necessary hidden field remains unfilled

I have a form that includes a hidden required input element. The value of this input will be dynamically set using JavaScript based on certain calculations. If the value is empty and the form is submitted, I want the .focusable div to receive focus instea ...

Having trouble with loading images in Bootstrap 5 framework

I am currently developing a website using HTML in Visual Studio Code with Bootstrap 5. However, I am facing an issue where the images I have inserted into a new section are not loading, while the ones in previous sections are displaying perfectly fine. < ...

Using JQuery to dynamically change className based on specific logic conditions

I am struggling to dynamically change the class name of a div based on the text inside another div using jQuery. Here is an example of the HTML structure: <div class="div-overlay"> <a class="image" href="https://www.e ...

Scroll overflow can be hidden

I'm working on a project with a div containing scrollable content, but I'm struggling to get the header to overflow its parent element. It seems that using overflow: scroll is causing the element to have overflow: hidden as well. Any assistance ...

Extended sticky navigation bar reaching beyond right margin

My website features a navigation bar that is created using the following code: body { margin: 3em; } #navbar { overflow: hidden; background-color: #333; } .sticky { position: fixed; top: 0; width: 100%; } <div id="navbar"> &l ...

Breaking down a string and then retrieving elements from an array

Just diving into the world of Javascript and jQuery, so I have a simple query. I've got a date that I need to break down into a string and then display it as an array. var date = "12/10/2010"; var dateArray = date.split(/); $('#printbox') ...

Moving objects from one container to another and organizing them

I have multiple small divs (referred to as "inner-div") and several container divs. My goal is to be able to drag the inner-divs to different container-divs and have them automatically rearrange within the new container. I have already set up the divs an ...

Is CSS the only way for Python Selenium to locate an element?

My attempt to log in to the Apple website using Selenium has hit a roadblock. When I try to locate the 'sign-in button' using find_element_by_id, an error pops up indicating it's actually a CSS selector. What exactly does that imply? I was ...