The div height set to 100% and using display:flex is experiencing issues in Chrome

Bootstrap 3.0 is utilized in the design. My goal is to have uniform height for all boxes, with the "more" link on the right box positioned correctly. However, the box ends before reaching the more link.

Take a look at this JSFiddle example.

Here is the HTML structure:

<div class="container body-content">
    <div class="row categoryrow">
        <div class="col-md-6 categoryblock">
            <div class="category">
                <div>
                    India faces acute shortage of cancer specialists, only one doctor available for every 2,500 patients
                    India faces acute shortage of cancer specialists, only one doctor available for every 2,500 patients
                </div>
                <span class="morelink">
                    <a href="/Category/Health">More..</a>
                </span>
            </div>
        </div>
        <div class="col-md-6 categoryblock">
            <div class="category">
                <div>
                    Sensex, Nifty slightly up in early trade
                </div>
                <span class="morelink">
                    <a href="/Category/Business">More..</a>
                </span>
            </div>
        </div>
    </div>
</div>

The CSS styles are as follows:

.categoryrow {
     display: flex;
 }
 .categoryblock {
     margin-bottom: 10px;
     width: 100%;
 }
 .category {
     border-radius: 5px;
     border: 1px solid #2bbcef;
     height: 100%;
     padding: 2px;
 }
 .morelink {
     font-style: italic;
     float: right;
     bottom: 0;
     right: 0;
     position: absolute;
     margin-right: 20px;
 }

Answer №1

Minimizing HTML markup is crucial for efficient coding.

To ensure consistent block heights:

  • Use display: flex; on the wrapping row of content blocks.

  • Apply flex: 1; to both content blocks and remove height declarations.

For proper positioning of "read more" links:

  • Add position: relative; to content blocks so the links align correctly within their containers.

  • Adjust padding values for optimal link placement.

Ensure all content is placed within designated blocks using <h1> tags for headings and <p> tags for main text.

Note: Some browsers, like Safari, require prefixed flex properties. Use the -webkit prefix before the standard property.

Check browser compatibility here.

CSS / HTML / Demo

.row {
    display: -webkit-flex;
    /* Safari prefix */
    display: flex;
}
.content {
    -webkit-flex:1;
    /* Safari prefix */
    flex:1;
    border-radius: 5px;
    border: 1px solid #2bbcef;
    position: relative;
    margin: 10px;
    padding: 10px 10px 30px;
}
.more {
    font-style: italic;
    bottom: 10px;
    right: 10px;
    position: absolute;
}
<div class="row">
    <div class="content">
         <h1>Heading</h1> 
        <p>India faces acute shortage of cancer specialists, only one doctor available for every 2,500 patients India faces acute shortage of cancer specialists, only one doctor available for every 2,500 patients</p> <a class="more" href="/Category/Health">More..</a>

    </div>
    <div class="content">
         <h1>Heading</h1> 
        <p>Sensex, Nifty slightly up in early trade</p> <a class="more" href="/Category/Business">More..</a>

    </div>
</div>

Answer №2

To start, make sure to include position:relative; in the parent element of the one with position:absolute... like so:

.category {
position: relative;

}

Additionally, if you set a height of 100% on an element without specifying heights for its parents, it will be as good as setting 100% height of nothing which results in 0. Therefore, ensure you set 100% height (if necessary) for all parent elements. Here is your updated JavaScript code:

http://jsfiddle.net/je6qtkLn/3/

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

Trouble with the jQuery sliding animation speed

One of the challenges I'm facing involves two divs: left and right. I want to slide the left div, making the right div's width 100% when the left div is hidden. This setup works well, but when I try to adjust the speed (slow or fast), it doesn&ap ...

Is there a way for me to retrieve the data inputted into this form using JavaScript?

Having some trouble with this code. Can someone help me figure out what's going wrong? function displayData() { var userInput; userInput = document.getElementById(userInputs.firstInput); alert ("You entered: " + userInput); } <form ...

What are some methods for controlling a webpage? Is it through HTML, JavaScript, Xpath, or

Hey there, I could really use your expertise on untangling a question that has me completely stumped. What exactly is the mechanism for controlling a webpage? a. HTML b. JavaScript c. Xpath d. CSS ...

Instant webpage updates upon editing CSS/HTML live

I recently watched a tutorial where a designer was updating CSS with live browser refreshes. What stood out to me was that the browser instantly showed any changes made to the CSS or HTML without needing to manually refresh the page. I am using a Mac with ...

Is there an issue with JQM plugin due to jQuery's append() function?

I am just starting to learn about jQuery mobile as I develop an app using it. Whenever I click on the Add_details button, I want to add dynamic input fields only once. After saving, if I click on the Add_details button again, I need to append more dynamic ...

Guide to make a loading animation button through the use of HTML, CSS, and JavaScript

"Hello, I am currently in the process of working on a project and am interested in implementing a button with a loading animation that can be displayed during actions like form submission or content loading. I'm seeking some advice or code sample ...

What is the process for fetching a specific image from a database folder by referencing its name?

We have a collection of images stored in the uploads folder within the root directory. Our goal is to display a single image for each user profile. Each user's profile image file name is saved in the database table called user under the field profile ...

Are the buttons appearing within a pop-up display?

I am having an issue with my Javascript popup buttons. Whenever the popup appears, the buttons that come after the one clicked appear on top of the popup container, and the previous buttons appear behind it. How can I ensure that the popup container displa ...

Utilize CSHTML Script to Show HTML Content When SQL Query Results in Null

I have a CSHTML Script that a friend has written, and I am currently making some changes to it. I have a SQL Query saved as a variable and if this query returns NULL, then I want to display different HTML compared to when it returns results. Below are the ...

Steps to halt webkit animation within a div located inside a circle:

I have a series of nested circle divs, and I want to give them a pulse animation. The issue is that the text container is within one of these circles, causing the animation to apply to the text as well. I am unable to move the text container due to potenti ...

Unusual behavior encountered while attempting to reset input text using AngularJS

I'm encountering an issue with what I assumed would be a straightforward scenario. Here is the form in question: <form class="form-inline" role="form"> <div class="form-group"> <input type="text" ng-model="customerInput" size="80 ...

Adjust the height of the list when including or excluding floated list items that are not in the final row

Within my ul are li elements with varying widths that wrap around inside a container into multiple rows. When removing an li element from the ul, I want the container's height to adjust dynamically in case a row is eliminated. If the removal happens ...

Error occurs when checkboxes are left unchecked in CherryPy web form

Currently, I am in the process of creating a straightforward web form using CherryPy in Python 3.5 to interact with an sqlite3 database, which requires input of various data types. I encountered an issue where leaving checkboxes unchecked resulted in an er ...

The anchor tag causes the tooltip to display outside of the td element

One of my requirements is to display the click percentage for each link in an HTML template that is dynamically fetched from a database. I attempted to show the click percentage for each anchor link by adding them to the `data-title` attribute using jQuery ...

Obtain the URL path for accessing URL links using PHP

To obtain the URL of an image, I typically use this code on the main websites: <a href="./index.html"><img src="./images/logo.png" class="" alt=""></a> However, for sub-sites, I need to use a slightly different approach: <a href=".. ...

What is the best way to convert this JavaScript iteration function into jQuery?

I recently encountered an issue with my JavaScript function that returns a list of elements with the class ".youtube", loops through them, and calls another function. The JavaScript logic is flawless, but I wanted to convert it into jQuery for better reada ...

The mobile navigation in HTML has a slight issue with the ::after pseudo-element, specifically within the

As I prepare to launch my website, I have made adjustments to the mobile layout by moving the navigation links to a navigation drawer. The template I am using included JavaScript scripts to handle this navigation change. However, I encountered an issue whe ...

Navigating Parent Menus While Submenus are Expanded in React Using Material-UI

My React application includes a dynamic menu component created with Material-UI (@mui) that supports nested menus and submenus. I'm aiming to achieve a specific behavior where users can access other menus (such as parent menus) while keeping a submenu ...

Tips for deactivating the double class with jQuery

I need to implement a feature where all classes on a button are disabled if a specific class is present. I attempted to disable all classes, but it seems like I made an error somewhere. Jquery: if ($('.lgi_btn_cta_toggle').hasClass('lgi_ct ...

Unable to retrieve the value of ng-model using $scope

Having some trouble getting the ng-model value when clicking a button that triggers a function to add each ng-model value to an object. Interestingly, when trying to get the value of $scope.shipNameFirst, it shows up as undefined in the second example. I& ...