What is the best way to maintain the standard height behavior of a fixed element?

I'm new to web development and currently working on my first website using only HTML, CSS, and JavaScript. I encountered an issue with the height of a fixed block element. When the user clicks on the "Contact us" link, a box containing contact information should open in the center of the screen. I set the position property to fixed, hoping that the height would adjust based on its content, but it's displaying as 100% of the screen height instead. The website is in Spanish, and you can access it at this link:

As I mentioned before, this is my first web page, and I'm still working on the navigation bar.

EDIT: I apologize for not providing any code initially:

div#contacts1{
font-family: "Ubuntu Medium";
padding: 3.5em;
width: 50%;
border: solid 2px;
border-radius: 20px;
background-color: white;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
overflow: auto;
}
// Add more code here
<!DOCTYPE html>
<html>
<head>
<title>Bordaos y algo mas</title>
<style type="text/css">
@import url("index.css") screen;
</style>
</head>
<body>

<div id="contacts">
</div>
<div id="contacts1">
// Add more code here
</div>

Here is a picture illustrating the problem

Answer №1

To fix the issue, you should eliminate the bottom: 0; property as it along with top: 0; is causing the div to stretch to 100% height.

Instead, try setting:

top: 50%; // shift popup down by 50% of window height
transform: translateY(-50%); // reposition it up by 50% of popup height

UPDATE: It's also advisable to include max-height: 100%; to enable the use of overflow: auto; in case the window's height is shorter than that of the popup.

Answer №2

Here is an easy demonstration of a Modal that can be utilized without the need for custom CSS, particularly in terms of height and width adjustments. Let it adjust its height automatically based on your content!

Check it out here - https://getbootstrap.com/docs/4.0/components/modal/

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

Positioning two social media share plugins (Facebook and Twitter) side by side on a single line (vertically aligning them

Having implemented Twitter and Facebook share plugins on my site, showcased in this example, I'm facing the challenge of aligning the buttons vertically. Despite attempting to adjust margin-top and padding-top attributes, the alignment issue persists. ...

Tips for effectively redirecting multiple links on a website

Can anyone advise me on how to redirect certain HTML pages to corresponding PHP pages? For instance, if a user lands on www.example.com/sample.html from another website, I want them to automatically be redirected to www.example.com/sample.php without seei ...

Can someone provide instructions on how to make a header with Bootstrap?

As a react native developer, I am currently working on a project that involves exporting PDF files from mobile devices. The challenge lies in my lack of expertise in web development and the requirement for the file to be in HTML format. The design I am aim ...

Keeping information saved locally until an internet connection is established

I have a vision to develop a Web app focused on receiving feedback, but the challenge lies in the fact that it will be utilized on a device without an internet connection. The plan is for it to save any user input offline until connectivity is restored. Th ...

Select only the top-level items in a dropdown menu using jQuery

Wondering how to create a fade effect that only triggers when hovering over the parent LI's without affecting the items in the dropdown menu? Any suggestions or solutions? Tried numerous examples with no success, struggling to make it work and gettin ...

Redirecting to the personalized 404 error page

I searched high and low for a simple answer to my question, but came up empty. I currently have two additional websites, website 'A' and website 'B', within the structure of my main website (www.xyz.com). Each of these websites is locat ...

Tips for keeping a div element at the top of the page

I am looking to have a div stick to the top of the page when someone scrolls down When the page is scrolled, the green div with class stickdiv should automatically stick to the top var left = document.getElementsByClassName("stickdiv"); for( var i = 0; ...

Using jQuery to create radial-gradients with the background-css feature

I'm a newcomer to this online community and English is not my first language. Despite that, I will do my utmost to clearly explain the issue at hand. Recently, I utilized the .css function in jQuery to create a design element successfully. However, I ...

In Angular2, you can dynamically show or hide previous and next buttons based on the contents of the first and last div

I need a solution to dynamically hide or show previous and next buttons based on the div tags created. Each value in a list is being used to generate individual div tags using ngFor loop in Angular 2. The list being utilized is: appUlist:string[] = ["Cal ...

CSS-exclusive dropdown menu elements peeking out

I have been working on a CSS-only drop-down menu and I am encountering an issue where other content seems to be showing through. Despite my efforts, I can't figure out why this is happening. If you would like to take a look, here is the link: http:// ...

Creating a visualization tool for Pareto analysis with Javascript, Html, and JSON

Currently, I am on the lookout for plugins, examples, or any related resources that can assist in creating a Pareto Chart for an HTML page. My goal is to construct it using HTML, style it with CSS, and populate data through JSON. While I am open to buildin ...

The content spills over the edges, yet a scrollbar emerges to guide the way

I have created an Image Slideshow using HTML5 and CSS. The slideshow consists of a div with the property overflow:hidden. The images are animated to move from right to left within the div. While this functionality works smoothly in Chrome, I am facing an ...

Automatically adjust height directive to fill up the remaining space

Is there a way to dynamically adjust the height of an element to fill the remaining space within its container? In my current layout, I have a fixed-height header (or menu) in pixels, a content area that may overflow the window height and require scroll b ...

Creating a Sudoku puzzle grid with HTML and CSS - a step-by-step guide

Apologies for the basic inquiry, but I have created a sudoku grid with the following structure. Modified(Using Tables): <table id="grid" border="1" style="border-collapse: collapse;"> <tr class="row"> ...

Navigate through elements in jQuery by scrolling both up and down

Is there a way to create a scroll function similar to WhatsApp's search feature? When the user clicks on the search (located at the bottom), I want it to automatically scroll to the last element. For example, if the user clicks the up button, it sho ...

Alter the size of an element's width dynamically while maintaining a predetermined width

Having a fixed width div: // CSS @media only screen .column.small-centered:last-child, .columns.small-centered:last-child { float: none; } .lesson_lt_mc_div .small-centered { margin-top: 15px; margin-bottom: 15px; width: 296px; } foundation.css:1 ...

Guiding user to their destination after signing in

Having trouble showing different headers based on user login status? Users can log in using login.php, but you're struggling to display header.php when a user is not logged in or logged in. You want the page to show profile form content when they are ...

How can I add an active CSS class to an li element depending on the href attribute of its child <a> tag?

Looking for a way to dynamically add an 'active' class to a navigation menu item based on the current URL? Here's what I have so far: <ul class="nav sf-menu"> <li><a href="@Url.Action("Index","Home")">Home<span>& ...

Enhance the impact of "dialogs" to the fullest extent or minimize it to achieve the

How can I position the minimized dialog on the bottom of the div when appending dialogs next to each other in a FB messaging system? To achieve a Facebook messaging effect, the titlebar must go down when minimizing/maximizing the dialog. Perform the follo ...

Access Information within live tabs

When attempting to click on any tabs in order to retrieve their respective data, I am successfully able to do so. However, I'm only able to retrieve the data of one row at a time. Can anyone provide assistance with this issue? <div class="col-lg-1 ...