CSS properties for a div element resembling a button

I am attempting to add a popup window feature to my project in order to simulate a pop-up window where I can later incorporate content from other pages within my application. The code I currently have is as follows:

html

<div id="box">
    <div id="title">Title <span id="button">X</span> </div>
    <div id="text">Content</div>
</div>

javascript/jquery

$('window').load(function(){
    $('#box').draggable();
});

css

#box {
    box-sizing: padding-box;
    box-shadow: 10px 5px 5px black;
    border-style: solid;
    position: absolute;
    width: 320px;
    height: 640px;
    min-width: 160px;
    min-height: 500px;
    max-width: 500px;
    max-height: 750px;
    top: 200px;
    left: 200px;
}

#button {
    background-color: red;
    padding: 0px 0px 0px 95%;
    min-width: 32px;
    max-width: 5%;
    position:absolute;
}

#title {
    background-color: black;
    text-decoration-color: white;
    font: 32px/36px arial;
    position: relative;
}

#text {
    background-color: white;
    text-decoration-color: black;
    font: 24px/28px sans-serif;
    position: relative;
}

In summary, I would like the element identified by id=button to be positioned in the right corner of the title bar within my "window". However, in its current state, this is what I am seeing:

https://i.sstatic.net/x7xPX.jpg

How can I improve this to achieve the desired positioning?

P.S.: I am open to suggestions using jQuery/jQuery-UI. I previously tried BootstrapDialog but found it unsuitable for my project as it does not adjust according to loaded content and blocks other content on my page when opened.

Answer №1

After reviewing your request, I have made the necessary adjustments to meet your specifications. The padding has been reduced for a cleaner look, and I added text-align:center; to ensure proper alignment of the 'X'. To align the button to the right when position is absolute, simply add right:0px; to your #button css style:

    #button {
             background-color: red;
             min-width: 32px;
             max-width: 5%;
             position:absolute;
             right:0px;
             text-align:center;
             padding-left:10px;
             padding-right:10px;
    }

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

Current page with animated CSS3 menus

I found a cool menu example on this webpage: http://tympanus.net/Tutorials/CreativeCSS3AnimationMenus/index10.html. I want to modify it so that the current page's menu item has a different color from the others. For example, when I'm on the home ...

How to Toggle Div Visibility with AngularJS ng-show and ng-click

In order to eliminate error messages, I decided to clear the field with a button click. This approach successfully removed the error in my initial test. <div class="errorPopup" data-ng-click="runner.Name = null" data-ng-show="mainForm.name.$error.pat ...

Is jQuery .serialize not sending data to PHP correctly, or could it be an issue with the PHP code

Regarding the question I asked yesterday: I have two radio buttons that are supposed to change prices when clicked: <form id="f-p" method="post" action="forms.php"> <label for="exkl">Exkl. moms</label> <input name="m ...

Steps to create a button that moves along with a div slider using toggle functionality

I have successfully created a navbar that toggles when a button is clicked. However, the button remains fixed in one position and I would like it to move along with the sliding navbar. How can I achieve this? $(document).ready(function() { $("#flip"). ...

Tips for adjusting the hue of a single color in a JPEG image

Is there a way to transform white color to red using only CSS, while leaving the rest of the colors unaffected? This should be accomplished without changing any other elements. ...

Cannot populate Kendo Menu with images due to dataSource imageUrl not recognizing the content

I have integrated Kendo controls into my application, specifically a Menu control with a datasource in my controller. Currently, I am passing the relative path of URL for imageUrl. However, as the application has grown, there are multiple calls being made ...

Total sum of calories, protein, and additional attributes of products in Woocommerce

Currently, I have implemented a plugin in my WordPress website that utilizes JQuery to showcase products. As illustrated in the image below, the display includes the product name, price, and below in grey, the attributes such as Kcal and protein amount. ...

Adjust the size of the password input characters without changing the appearance of the placeholder

Is there a way to enlarge the font size of an HTML password input without changing the placeholder text as well? Specifically, I am looking to increase the size of the password symbols (bullets). I attempted to adjust the font-size property of input[type= ...

What is the best way to eliminate all padding from a bootstrap toast notification?

I'm attempting to display a bootstrap alert message as an overlay toast (so it automatically disappears and appears above other elements). Issue: I am encountering a gap at the bottom of the toast and struggling to remove it: https://jsfiddle.net/der ...

using jQuery to eliminate an HTML element based on its attribute

How can I remove an element with the attribute cursor = "pointer"? I want to achieve this using JavaScript in HTML. Specifically, I am looking to remove the following item: <g cursor="pointer"></g>. It's unclear to me why this element has ...

IE does not encode single quotes/apostrophes in URLs

Encountering an issue with an AJAX call using jQuery on IE11 specifically when the parameter contains a single quote or apostrophe. According to the jQuery documentation found at https://api.jquery.com/jquery.getjson/ Data sent to the server is added t ...

Looping with asynchronous AJAX calls

Using dbase.dll in PHP to migrate data from dbase files to MySQL has been quite the task for me. I have a total of 150 files that I need to transfer, each file with a name ranging between 1000 and 5000. To handle this transfer, I utilize PHP. However, in ...

Adjust the size of an element using the jQuery library's knob.js

There is a page Once the button is pressed, a circle element from the library jquery.knob.js appears. I am trying to change the size of the circle and have written this code: <div style="float:left; width:255px; height:155px"> <input ...

What is causing the SVG element to malfunction on iOS devices?

I am facing an issue with the <h1> tag in my design. The SVG element within it is not appearing on mobile phones when I write a media query for devices with a minimum width of 400px, even though it works fine on screens with a minimum width of 800px. ...

invoke function upon element instantiation

Is it possible to invoke a function on a specific selector that would be applicable to all elements matching that selector currently as well as in the future? Similar to how the 'live' method used to work before it was deprecated. For instance: ...

Creating a unique look for SELECT (Option) tags using gradients and a personalized arrow design

Feel free to check out my full HTML code here. You can simply copy and paste it into a demo document on your local machine to see exactly what I'm talking about. My goal is to style the boxes to include both a gradient background AND a unique arrow o ...

The functionality of jQuery binding is not functioning properly

I've been playing around with jQuery and have a code snippet that includes: // buttons for modifying div styles by adding/removing classes <button class="size" id="switcher-large"> Large Print </button> <button class="size" id="switche ...

Uncertainty surrounding the application of class selector within CSS

Currently, I'm deep into my CSS learning journey on Progate.com. I've been cruising through the exercises, but I hit a roadblock when it comes to a specific class selector in the CSS code. The task at hand is simple: I need to tweak the CSS so th ...

Pause and resume the jQuery Slideshow

Utilizing the jQuery Cycle plugin to design an image slideshow has been quite the adventure. My goal is to have a slideshow of 10 images within a container div, with the ability to pause and restart the slideshow with the click of a button. Here is the cod ...

Dynamic header following the scroll position

I'm experiencing an issue where my background moves with the scrollbar, causing the header of the page to scroll along. I've included my code and a screenshot for reference. Any assistance would be greatly appreciated. Thank you. Here's my ...