Attempting to consistently place an element at the bottom of my div container

I am attempting to align my

<span class="fechar_fancy">Back/span>
at the bottom of my div, regardless of the height of my content. I want this element to always be positioned at the bottom.

Therefore, I tried using position:absolute and bottom:0 on the element I want to position at the bottom, relative to its container, but it is not working as expected.

Can anyone identify why it is not working?

Here is a link to my fiddle showcasing my attempts: http://jsfiddle.net/KHU7h/1/

This is my HTML:

<div id="janela_fancybox-container">
  <div id="janela_fancybox">
    <h2>Title</h2>
    <span id="data">Date time today</span> <br /> 
    <img class="img_principal" src="../image1.jpg"/>
    <p>
    (Content)
    </p>
    <span class="fechar_fancy"><strong>Back</strong></span>
  </div>
</div>

My CSS:

#janela_fancybox
{
    text-align:center;
    width:100%;
    margin:0 auto 0 auto;
    background:#fff;
    position:relative;


}

#janela_fancybox .img_principal 
{
    width:180px;
    height:200px; 
    float:left;
    margin-right:10px;
    border:5px solid #f3f3f3;
    margin-top:15px;
}



#janela_fancybox #data
{
    width:100%;
    color:#ccc;
    font-size:13px; 
    text-align:center;
    color:#7a7a7a;
}


#janela_fancybox h2
{
    width:100%;
    color:#004B97;
    font-size:16px; 
    text-align:center;  
}

#janela_fancybox p
{
    font-size: 14px;  
    text-align:justify;
    line-height:25px;
    height:25px;    
    word-spacing:-2px;
    width:96%;
    margin-top:15px;
}

#janela_fancybox .fechar_fancy
{
    float:left; 
    text-decoration:none; 
    font-size:15px; 
    color:#000; 
    width:100%;
    text-align:center;
    cursor:pointer;
    position:absolute;
    bottom:0;
} 

Answer №1

The issue that stands out to me is the CSS rule #janela_fancybox p with height:25px, preventing #janela_fancybox from adjusting its height based on text content. I have removed this height declaration:

#janela_fancybox p {
    ...
    /*height:25px;*/
}

Furthermore, for the absolutely positioned element, adding left:0 ensures it aligns to the left and expands to 100% width, eliminating the need for float:

#janela_fancybox .fechar_fancy {
    /*float:left; */
    ...
    left:0;
}

To prevent overlap with text content, I included a padding at the bottom of the container to accommodate the "back" link:

#janela_fancybox {  
    ...
    padding-bottom:25px;    
}

Example in action on jsfiddle


In this scenario, using position:relative instead of absolute positioning may suffice post-text. However, consider the wider context of your application before making changes.

View the demonstration here.

Answer №2

The issue at hand is that the div#fancybox is not properly clearing the floated elements inside it. One solution could be to apply the clearfix class and include it in the div#fancybox. Additionally, there seems to be a specified height on the p tag which is causing the text to exceed that limit (consider removing it).

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 Bootstrap modal will not appear when the parent container's position is fixed

I am having an issue with a bootstrap modal that I am using as an instruction guide. My goal is to keep it fixed at the top-right corner of the viewport, so I tried using the fixed position. However, when I do this, the modal turns grey. On the other han ...

How can line breaks be displayed in JavaScript text output?

I need assistance with creating a scrolling series of text messages that are separated by linebreaks. This is the current code I have: <script type="text/javascript" src="xbMarquee.js"></script> <script type="text/javascript"> <!-- ...

A table featuring an HTML select element that allows users to choose from preset options or manually enter

My goal is to incorporate a select box where users can either choose from a set list of options or input their own custom value. The select element is nested within a table. Unfortunately, using datalist is not a viable solution for me in this case. I have ...

I seem to be having a problem with CSS and Flexbox sizing. Does anyone have an explanation for what might be

Hey there! I'm currently in the process of building a Netflix clone, and everything seems to be working well except for one issue with the layout. No matter how I adjust the width of the div containing the images, they just won't change size. I&a ...

Is it possible to use JavaScript to toggle the visibility of the date picker when using the HTML5 input type=date?

Looking to personalize the HTML5 input type="date" element by integrating a separate button that triggers the visibility of the date picker dropdown. Struggling to find any information on this customization. Any assistance would be greatly valued! ...

"960-css: Building a Unique Framework for Sty

Considering the 960 gs CSS framework for implementation on my website. Is there any notable company utilizing this framework for their websites? Appreciate any insights. ...

Enhance Vaadin 14: Automatically adjust TextArea size when window is resized

Using Vaadin 14.1.19 in a project called "My Starter Project," I attempted to create a TextArea that supports multiple lines. Initially, everything seemed fine, but upon resizing the TextArea, it failed to adjust the number of visible lines. Here is the co ...

Repeated tweets detected within real-time Twitter stream

I've been working on developing a live update Twitter feature, but I've noticed that it sometimes duplicates tweets and behaves erratically. Did I make a mistake somewhere in my code? http://jsfiddle.net/JmZCE/1/ Thank you in advance (note: I p ...

Center both vertically and horizontally in Bootstrap UI Modal

I'm attempting to create a Bootstrap UI Modal that is centered both vertically and horizontally. While I found this solution that successfully centers the modal vertically, it loses its horizontal centering when applied to my own template with 800px ...

Dynamically generated table causing issues with Jquery functionality

Currently, I am facing an issue with my webpage that utilizes the jquery template plugin for dynamically loading data into a table via a json call on page load. My goal is to include clickable elements like buttons or divs within the table columns, which w ...

Ensure that the following div remains positioned beneath the current one

After reading through this question on Stack Overflow, about creating a responsive table with both vertical and horizontal headers, I came across this particular issue, demonstrated in this codepen example: Currently, the second table appears directly bel ...

A critical issue occurred: array length is invalid. The attempt to include EJS in the template failed due to

Currently, I am attempting to loop through my JSON data using EJS from Node/Express. However, I need to insert a different pin into the flexbox when it reaches the 6th iteration. Whenever I try to implement this logic, I encounter a severe error that disr ...

Fixed Container housing a Child Div with Scrollbar

I am faced with a challenge involving a lengthy navigation menu (.nav-main) nested within a fixed header (header). When the navigation menu is toggled using jQuery .toggle(), the content extends beyond the window height and does not scroll. I am looking fo ...

Is there a way to showcase the uploaded file contents on the current page without the need to refresh?

Is there a way to display the contents of an uploaded file on the same HTML page without opening a new tab or refreshing it? I have the following HTML and PHP codes for reading an uploaded file in a separate page, but I want to integrate it into the same H ...

VueJS is utilized to duplicate the innerHTML output value

Currently diving into the world of Vue, I encountered an issue while rendering an HTML text. My component template is a WYSIWYG editor. <template> <div id='editor_container'> <slot name="header" /> <div id='editor ...

Unable to utilize the full column space provided by bootstrap

I need assistance in making three buttons span the entire width of a column. The grid consists of 3 sections for the buttons and 9 sections for other components. Here's a visual reference. Essentially, the buttons should take up the space highlighte ...

Tips for keeping a reading item in place while scrolling

To enhance the user experience, I would like to improve readability without affecting the scroll position. Question: Is there a way to fix the scrolling item at a specific position (item with the .active class)? I am looking to maintain a consistent read ...

Regular expression to identify items containing `href=""` within a specific set of tags

After using a Regex pattern to check for every href="" in my document, I now want it to specifically target all hrefs located between <a and </a> tags while still allowing other parameters within. Do not include in the match: <base href="http ...

The Bootstrap 4 Toggler Dropdown lacks a background color

Struggling to style the toggle dropdown on smaller screens to match the regular navbar background? Can't seem to figure out how to target it. Is there a missing bootstrap class or an error in the code? Initially suspected the border might be causing i ...

Elevate the index of the name attribute for an input field within a dynamically generated form

In my scenario, I have created a form that includes indexed input fields for username and level: <form> <table> <tr class="trToClone"> <td> <label>Username:</label> <input type="text" name="usernam ...