css - unable to achieve center alignment

Seeking help with adjusting the alignment of a centered div in this JSFiddle example. The goal is to have the text align vertically and horizontally within the div, but the current setup results in the top line being centered instead of the overall content. Any ideas on how to fix this?

Here is the HTML code:

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <title>Regret</title>
        <meta charset="utf-8">
        <link href='http://fonts.googleapis.com/css?family=Gloria+Hallelujah|Bowlby+One+SC' rel='stylesheet' type='text/css'>
        <link href='css/regret.css' rel="stylesheet">
    </head>

    <body>
        <div id="container">
            <div class="inner">
                <h1>Regret</h1>
                <p class="choice">Let it out</p>
                <p class="choice">Wallow in it</p>
            </div>
        </div>
    </body>
</html>

The CSS code used:

body { font-family: 'Gloria Hallelujah', cursive; margin:0; text-align:center; color: #5e7c88; }
h1, h2, h3 { font-family: 'Bowlby One SC', cursive; color: #4b5f6d; }
img { border: 0; }

#container { margin: 0 auto; }
.choice { font-family: 'Bowlby One SC', cursive; }
.inner {  position: absolute; top: 50%; }

Answer №1

This solution should meet your requirements (assuming I've understood them correctly): http://jsfiddle.net/7ZSmX/23/. The approach involved utilizing the CSS properties display: table and display: table-cell.

Answer №2

replace inside with the following

position:sticky; top: 50%; text-align:center; width:100%;

Answer №3

If you're looking for a solution:

http://jsfiddle.net/7ZSmX/13/
.inner {  margin-top: 50%; }

This is the code you should use instead of relative.

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

How can I adjust this button to match the size of the input field?

I'm in the process of creating a simple landing page and I've encountered an issue with the newsletter signup component. The button in the bootstrap input group template appears much larger than the input field. Here is the current code snippet: ...

Is there a way to trigger the opening of a jQuery-UI-Selectmenu dropdown using the 'ENTER' key instead of the 'SPACE' key as indicated in the documentation?

I'm currently working on implementing jQuery-UI-Selectmenu to create a dropdown feature. As per the API documentation for select menu available at https://api.jqueryui.com/selectmenu/, it mentions that the 'SPACE' key can be utilized to ope ...

Tips for retrieving formatted text layout from the database

I recently encountered an issue when adding text to my MySQL database using a textarea. The format of the text, including newlines and spaces, was saved in the database but not displayed as such when viewed directly. When I retrieve this string from the da ...

adjust the value of an attribute in a dynamic stylesheet using jquery

I'm trying to create a dynamic stylesheet using a combination of jquery, css, php, and html. My approach involves making an ajax request (using jquery) to pass the width of my screen to a php css file. However, I am facing an issue where the php css f ...

After refreshing the page, the ngRoute white page is displayed

I've encountered an issue with my Angular website. I built it using ngRoute, but when I click on a link, a white page appears. Only after refreshing the page does the content actually show up. Even in the browser's DevTools, you can see the html ...

Python Occasionally Gives Unexpected Output While Parsing HTML Content from a Website

I developed a function to retrieve HTML content from a specified URL. Here is the code snippet: def __retrieve_html(self, address): html = urllib.request.urlopen(address).read() Helper.log('HTML length', len(html)) Helper.log('H ...

Creating a bezel design in CSS or Vue: A step-by-step guide

Embedding: https://i.sstatic.net/YfvQP.png Is there a CSS property that can be used to create the same angle as shown in the layout? I looked everywhere in the program but couldn't find this specific property. Tried searching here !: https://i.s ...

Difficulty linking CSS to HTML in a Flask web application

My HTML/CSS file is pretty straightforward: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta charset="utf-8"> <meta name=&quo ...

What is the best way to transform a CSS linear gradient into JavaScript code for use in a React Native application

Struggling to convert my input data from Figma CSS into a format that works with react native. Are there any helpful libraries for this task? If so, how should I go about writing it out? The CSS code in question can be found here. ...

Is it detrimental to my search engine ranking if I utilize CSS display:none?

Imagine having valuable content that is initially hidden with CSS, and then using javascript to reveal it only when the user clicks on certain links. Even users without javascript enabled can access this content by following the links to a new page where i ...

Error TS7053 occurs when an element is given an 'any' type because a 'string' expression is being used to index an 'Object' type

When attempting to post data directly using templateDrivenForm and retrieve data from Firebase, I encountered the following type error message. Here are the relevant parts of my code: // Posting data directly using submitButton from templateDrivenForm onC ...

The text-center alignment in Bootstrap doesn't seem to be applying to buttons

After spending a considerable amount of time trying to center two buttons in Bootstrap, I came across the "text-center" class offered by Bootstrap. However, no matter where I include this class, it doesn't seem to have any effect on the alignment of t ...

Email communication not being successfully transmitted

I've been attempting to add a contact form to my website, but unfortunately, it's not functioning as expected. Following this tutorial, I replaced the $myemail variable with my email address and gave it a try. While I do receive the "thank you" m ...

Refreshing a div using JQuery/Ajax upon an update to a column in a database table

I am interested in checking for database column value changes and utilizing jQuery/Ajax to load a specific page into a designated div container. For example, let's say that on the main page, I have 1.php displayed within a div with the id "status." ...

What is the best way to adjust the square size using CSS on multiple divs with the same class?

Is it possible to adjust the image size of the second div in CSS while keeping only the square shape intact and using the same class for different divs? <div class="square"> <img class="square__img" src="square.png" ...

Exploring Python and Selenium to extract targeted text from a div that is not contained within a span or other

Upon stumbling upon a web page that I am eager to scrape, I found myself emotionally overwhelmed by the complex structure of the address details section. Let's delve into the specifics: The result structure on the page appears as follows: <div cl ...

Vue has the ability to automatically escape HTML characters

Take a look at one of the methods I have computed: filtered() { return this.groups.map(group => { return group.replace(this.search, '<span class="has-background-primary">' + this.search + ...

Trigger javascript function after clicking on two buttons

I am currently working on developing a web game inspired by Duolingo. In a specific scenario, I need a function to be triggered after two button clicks to progress further. However, I am facing challenges in finding solutions online or understanding it on ...

The storing of data in an HTML form input

Within my submission form, there are five distinct inputs that users can enter and submit. Currently, the entered data is being written to a .txt file successfully. Nevertheless, the objective is to organize and display the information in an easily readabl ...

What are the steps to clipping a canvas using CSS clip-path?

When it comes to clipping a canvas, there are multiple methods that can be used. One way is to create a path with getContext('2d') and set globalCompositeOperation. Another method involves using -webkit-clip-path or clip-path, though the latter m ...