Vertical Centering Not Functioning Properly on IE and Firefox

I am currently working on setting up a temporary placeholder page for my website, but I've encountered some challenges with cross-browser compatibility. The page looks fine on Chrome and my iOS devices, such as my phone and iPad, but it doesn't display correctly on Internet Explorer or Firefox. I've experimented with various methods of vertical alignment, but none of them seem to work as expected. Is there something crucial that I'm overlooking, or is there a specific approach to ensure consistency across all browsers? Any advice or guidance would be greatly appreciated!

Live Site:

HTML:

<html>
    <head>
        <title>Radical Creation</title>
        <link rel="stylesheet" type="text/css" href="default.css"/>
        <link rel="shortcut icon" href="images/favicon.png"/>
        <link rel="icon" href="images/favicon.png" type="image/x-icon">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="jscript/s3Slider.js"></script>
        <script type='text/javascript' src='js/jquery-1.11.1.min.js'></script>
        <script type='text/javascript' src='js/jquery.particleground.min.js'></script>
        <script type='text/javascript' src='js/demo.js'></script>
    </head>
    <body>
            <div class="title">
            <div class="main-title"><span class="thin">Radical</span>Creation</div>
            <h3>Coming Soon!</h3>
            </div>
        <div id="particles">
        </div>
    </body>
    </html>

CSS:

html {
    height: 100%;
    overflow:hidden;
}
body {
    font-family: 'Lucida Console', Monaco, monospace;
    background-repeat: none;
    background-size: cover;
    background-position: center;
    background-image: url(images/stars.jpg);
}

h2, h3 {
    font-weight: lighter;
    color: #4EB4FC;
    position: relative;
}


.title{
    margin-top: -100px;
    top: 54%;
    text-align: center;
    position: relative;
    float: center;
}

.main-title .thin {
    font-weight: 200;
}

.main-title {
    top:10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 30px;
    color: #f9f1e9;
    font-family: 'Raleway', Calibri, Arial, sans-serif;
    transform : scale(1.0,0.8);
    -webkit-transform:scale(1.2,1.0); 
    -moz-transform:scale(1.0,0.8); 
    -ms-transform:scale(1.0,0.8); 
    -o-transform:scale(1.0,0.8); 
}

#particles {
    top: -5px;
    height:100%;
    opacity: .6;
}

Answer №1

A sleek solution using only CSS: (make sure the .title element has a specific height)

.title{
text-align: center;
width: 100%;
position: absolute;
top: 0%;
bottom: 0%;
height: 100px;
margin: auto;
}

View the implementation here: https://jsfiddle.net/svArtist/cn5fb6ua/

Answer №2

Mastering vertical alignment in CSS can be quite challenging due to the lack of implicit support. While there are hacks available, such as those discussed in this thread or this one, sometimes they may not produce the desired results. In such cases, resorting to javascript/jQuery might be the most straightforward solution. A potential implementation could involve adjusting the position dynamically along with absolute positioning for the .title element:

<script>
$(function () {
  $(window).on('resize', function () {
    var title = $('.title');
    var top = $(window).height() / 2 - title.outerHeight() / 2;
    $('.title').css('top', top + 'px');
  }).trigger('resize');
});
</script>

If you're unfamiliar with javascript/jQuery, simply copy and paste the provided code snippet into your webpage (e.g., within the head section), and don't forget to include the jQuery library:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

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

When using the if-else statement to check the typeof value, it is returning as undefined

update Hello, I conducted a test on your code and found that it breaks for another scenario when the mobileVersion is set as sample.pdf. In this case, I am getting skyCloudmageProfilePic as pdfProfilePic without removing the typeof condition. Here is the ...

Ensuring Input Integrity: Utilizing HTML and Javascript to Block Unfilled Form Submissions

Currently, I am working on developing a registration page using HTML and JavaScript. Although I have added the 'required' tag in HTML to prevent users from submitting empty input fields, I noticed that users can bypass this restriction by simply ...

Tips for changing the CSS pseudo class of an HTML element with JavaScript?

Here's a code snippet I have: const myDiv = document.querySelector("#myDiv"); myDiv.addEventListener("click", fct_Div); function fct_Div(ev) { console.log(ev); if (ev.altKey === true) { myDiv.style["background ...

Launching application from webpage

For the longest time, I believed that opening a program on a local machine through JavaScript or HTML was impossible due to security concerns. However, in addressing issues with a browser-based POS system, we are considering launching a desktop application ...

Tips for customizing the base font size in a Bootstrap 4 template

My Java/Spring Boot webapp utilizes Thymeleaf HTML page templates and Bootstrap 4, with the foundation being a free Bootstrap 4 site template called 'Simple Sidebar': . The current setup is functioning smoothly for me. I am interested in adjusti ...

Instructions for inserting an anchor tag into the middle of a <p> element utilizing document.createElement("p")

When generating elements dynamically with JavaScript using document.createElement("p"), I am looking to create a paragraph element <p></p> that includes an anchor tag in the middle, creating a clickable link within the text. I aim to use JavaS ...

Ways to correct inverted text in live syntax highlighting using javascript

My coding script has a highlighting feature for keywords, but unfortunately, it is causing some unwanted effects like reversing and mixing up the text. I am seeking assistance to fix this issue, whether it be by un-reversing the text, moving the cursor to ...

Tips for showcasing the complete image within v-parallax

For my project, I decided to go with vuetify as the frontend framework. It's a great choice! Now, I have a question about v-parallax - how can I make it display the full image without cropping? Below is some code snippet, and you can find the full cod ...

What is the best way to ensure that text moves to the next line if it exceeds the boundaries of the parent div in either CSS or

I am looking to have the "remaining books count" and "remaining pens count text" automatically move to the next line below the numbers when they exceed two digits, causing an overflow in their parent div. Here is the code snippet I currently have: functi ...

Mobile display trapping Bootstrap navbar

Can anyone help me figure out why my navbar is stuck in its mobile display? Here is the link to the code: http://jsfiddle.net/enL35t1q/ Navbar <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul cla ...

Using JavaScript to empty input field when switching focus between input fields

I am experiencing an issue with clearing a input number field. Here is the code snippet in question: <input class="quantity_container" v-model="length.quantity" type="number" pattern="[0-9]*" inputmode="numeric" onfocus="if (this.value == &ap ...

Any ideas on how to present data in a card layout with two columns?

.card { box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s; } .card:hover { box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); } .container { padding: 2px 16px; } .card { width: 50%; heig ...

Having issues with the Page inspector and viewing in browser feature in VS2012?

I'm a beginner in the world of website development and I'm facing issues with viewing my webpage on a browser. Every time I attempt to open the page inspector or choose "view in browser," I encounter the following error messages: Page Inspector ...

What is the best way to adjust the dimensions of an image using CSS?

I've been struggling to adjust the dimensions of my image using CSS by specifying a width and height attribute. However, instead of resizing the picture, it seems to simply zoom in on the existing image. For instance, I have an image that is 90px by ...

Creating a custom Vue.js component for specific table cells within a table row - here's how!

My challenge is having related and neighboring table columns grouped within the same component in Vue.js. However, I'm facing a limitation with the template system where only one tag can be directly placed inside <template>. Typically, this wrap ...

Locate elements with Jquery after displaying HTML content

I am encountering an issue with the code snippet below: tblBody = $('#tbody'); tblBody.html(rowsStr.join('')); var lines = tblBody.find("tr"); The array rowsStr contains strings that create tr and td tags. Sometimes, when I use tblB ...

The alignment of list bullets is inconsistent across different web browsers

Check out this code snippet on JSFiddle: http://jsfiddle.net/PZgn8/8/. It's interesting to see how the rendering differs between Chrome 27 and Firefox 21. Despite the difference, I believe Firefox is actually displaying the desired outcome. <ul st ...

When the screen size is decreased, one card begins to appear behind another card

In my attempt to create a set of responsive cards using Bootstrap, I have written the following code for the cards: <div class="col-xl-4 col-md-6 col-sm-6 p-2"> <div class="card shadow" style=" ...

What is the syntax for implementing a for loop/for each loop in EJS?

I'm trying to figure out how to include this code snippet inside <% %>. I'm not sure if it's similar to a typical forEach/for loop. The documentation on EJS site is quite limited, so I've turned to this forum for help. <% incl ...

navigating through tab menus based on time intervals

I'm a beginner in the world of HTML and website building. I have all my content ready to display on my site, but I'm looking for assistance in automating tab switching. Is it feasible to alternate between tabs every 5 minutes? Can someone guide m ...