Ways to align multi-line text at the center within a concealed Division

Struggling with aligning a paragraph in a div vertically. The paragraphs are within sliding boxes triggered by hovering over an image. Unable to use display: inline-block due to the default state being set to display: none;. Seeking guidance on the best approach to solve this issue, hoping for a simple solution that will make me feel silly. Thank you in advance.

Link to code example

Below is the CSS for the textbox divs:

.textbox {
    max-width: 610px;
    height: 155px;
    padding: 10px;
    display: none;
    overflow: hidden;
    background: linear-gradient(to bottom, rgba(5, 58, 24, 0.65) 10%, rgba(0, 0, 0, 0.13) 83%, rgba(0, 0, 0, 0) 100%);
    border-radius: 0 10px 10px 0;
}

Previously posted similar code, but unsure of proper questioning process or etiquette. Not a jQuery issue this time, as it's functioning correctly. Reposting due to CSS-related problem. (previous question link below)

How to handle a hide/show queue with multiple hidden divs smoothly

Answer №1

If you apply display: table-cell to the .textbox divs, you can vertically align them by using vertical-align:middle. When the page loads, hide the divs with display: none on dom ready.

See it in action: http://jsfiddle.net/abhitalks/rBsLx/15/

CSS:

.textbox {
    max-width: 610px;
    height: 155px;
    padding: 10px;
    display: table-cell; /* set as table-cell */
    vertical-align: middle; /* allows for vertical alignment */
    ...
}

JS:

$(document).ready(function () {
    $(".textbox").hide(); // initially hide the divs
    ... // your custom code
});

I hope this explanation is helpful.

Answer №2

If you're looking for a solution, you might find the following link helpful:

Check out this code snippet on Fiddle

.textbox {
max-width: 610px;
height: 155px;
padding: 10px;
display: none;
overflow: hidden;
background: linear-gradient(to bottom, rgba(5, 58, 24, 0.65) 10%, rgba(0, 0, 0, 0.13) 83%, rgba(0, 0, 0, 0)    100%);
border-radius: 0 10px 10px 0;

}

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 alignment of h2 headings becomes disordered beyond a specific viewport width

Can someone help me with an issue I'm facing regarding the placement of my "rightside" navigation? The problem arises when the viewport width drops below 767px, causing the h2 elements in the rightnav to align themselves directly next to the #leftnav. ...

Attempting to enhance my show/hide DIV code to efficiently target multiple divs

Currently, I am faced with a challenge involving a lengthy case study that includes numerous images. The loading time for the page is exceptionally long due to the high number of images. To address this issue, I have implemented a method using show and hid ...

What is the best way to stop the max-height transition from automatically scrolling to the top of the page?

Initially, I have a div with a max-height of 0 to hide it. When an anchor is clicked, the div's max height changes to 800px, revealing its content. However, every time this transition happens, the page automatically scrolls to the top instead of maint ...

Obtaining every PDF file linked within a designated div/table section of a website

Is there a way to download all PDFs linked in a table on a webpage using javascript? Edit: To clarify, I am trying to find a solution where Javascript can automatically download all the PDFs contained within a specific table on a webpage viewed in a brow ...

Guide on incorporating a "choose file" button to store an image in a mongodb database for a meteor application

I recently created a form for my project which includes typical text inputs like "First Name", "Last Name", and "Address". However, I am currently facing a challenge due to my limited knowledge in Meteor, as well as HTML and Javascript. Despite searching e ...

What is causing this image to be off-center both vertically and horizontally on the table?

Currently, I have a small 20px by 20px image displaying in the top left corner of an empty table: <table width="100px"> <tr> <td width='100%' align='center' valign='center'> <img i ...

Code to dynamically add a div to an HTML template using JavaScript logic

A simple web application was developed by me to retrieve recipe data from an API. This data is then displayed by inserting it into an HTML template specified in the JavaScript file. The layout is managed using a float grid in CSS. Here is the code snippet ...

Python code using Beautiful Soup to crawl web pages and extract JSON data

Currently exploring the world of beautifulsoup in Python and attempting to extract specific details from a website, particularly the deeplink and title. Utilizing beautifulsoup to gather json data has produced a variable named `soup` of type beautifulsoup ...

The drop-down menu does not maintain its selected option after the window is refreshed

I am struggling with a dropdown list as shown below: <select class="span2" id ="sort" name= "order_by"> <option >Default</option> <option >Price</option> <option >Color</option> ...

Storing complex data using AJAX and HTML techniques

Consider this scenario. I have a table (<table>) where users can input the time spent on a project in a specific week. For example: -------------------------------------- |Project ID: | Monday | Tuesday | ...| | 123 | 7:15 | 3:45 | ... ...

The use of a Bootstrap row is leading to incorrect dimensions for FullPageJS

Within the body tag, I have included the following code snippet: <div id="container"> <div class="section profile"> <div class="row"> <div class="col-sm-6"> A </div> ...

React component causing footer overlap

Currently, I'm facing a challenge in creating a footer that stays at the bottom of the page without overlapping any other components. In my index file, I've included the following code: .footer{ margin-top: 1rem; padding: 1rem; background- ...

What changes do I need to make to improve the responsiveness of my website?

What changes do I need to make to my website's responsiveness for viewing on phones? You can view my website here, and the link to the responsive code here. I'm hoping someone can help me with the correct code so I can update my website's r ...

Similar to the :has() in jQuery, the equivalent in CSS

Consider the code snippet below: <div class="section"> <div class="row">...</div> <div class="row"> <!-- bottom margin here needs to be 0 --> <div class="section"> &l ...

Issue with Bootstrap margins and padding

While creating an application form from scratch with Bootstrap, I encountered a peculiar issue. The element with ID officeaddress is missing from the HTML page upon loading. I've experimented with the my class in Bootstrap and attempted to add line br ...

Using z-index to position a paragraph element behind other elements in a webpage

I am facing a challenge where I want to hide a paragraph within an element, and layer it behind another element. Despite my attempts with z-index, I have been unsuccessful in achieving this effect between the elements. Could someone shed some light on why ...

What exactly happened to my buttons when I transition to the mobile display?

Due to time constraints, I decided to save some time by utilizing a CSS template called Horizons created by Templated. This particular CSS template uses Javascript to adjust the layout for mobile devices, causing buttons to switch from inline to block for ...

What is the best way to make SVGs of varying sizes appear uniform in height?

I am encountering an issue with a RestAPI that provides SVG images of different sizes. While some images fit perfectly, others do not. You can check the examples using this link: https://i.sstatic.net/XJwKU.png The main challenge is that I do not have inf ...

What is the method for using jQuery to retrieve hidden fields with the visible attribute set to "false"?

How can I access a control with "visible = false" attribute using jQuery? Some code examples would be appreciated. <tr>   <td class="TDCaption" style="text-align: left">     <asp:Label ID="lblMsg" runat="server" EnableViewState="False" F ...

Execute code after the page has finished loading, excluding instances of page refresh

I have a specific jquery function that I need to execute only the very first time a page loads, not upon refreshing the page. Here is the code snippet: $(window).on("load",function() { $("#logo-black").typed({ strings: ["Nothing^450&Co^25 ...