What steps can I take to properly center and repair my web page that is currently a mess

This web page I'm working on is giving me a headache. The #titlediv just won't center and the navbar keeps disappearing randomly. It seems like a big issue that I can't wrap my head around. If anyone out there can help salvage it, here's the link:

http://jsfiddle.net/glenohumeral13/c604vbrn/

Here's the code snippet:

<body>
    <div id="parallaxish"></div>
    <div id="navbar">
        <nav>
<a href="#item1">Item1</a>

<a href="#item2">Item2</a>

<a href="#item3">Item3</a>

        </nav>
    </div>
    <div id="contentdiv">
        <div id="welcome">
            <div id="titlediv">

<h1>Title will go here</h1>

            </div>
        </div>
        <div class="barrier"></div>
        <div id="item1">

<h1>Item1</h1>

        </div>
        <div class="barrier"></div>
        <div id="item2">

<h1>Item2</h1>

        </div>
    </div>
</body>

CSS Styles:

* {
    margin: 0;
    padding: 0;
}
body {
    color: #fff;
    background-color: #000;
    font-family: Helvetica, Arial, sans-serif;
}
img {
    max-width: 100%;
    height: auto;
}
#parallaxish {
    background-image: url('http://24.media.tumblr.com/tumblr_m54j1nIYN21r0k830o1_500.jpg');
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: -1;
    background-position: center;
    -moz-background-size: cover;
    -o-background-size: cover;
    -webkit-background-size: cover;
    background-size: cover;
    width: 100%;
    height: auto;
}
#navbar {
    float:right;
    height: 30px;
    margin-right: 100px;
}
nav a {
    text-decoration: none;
    display: inline;
    list-style-type: none;
    padding-right: 15px;
    padding-top: 10px;
    float: left;
    -webkit-transition: color 1s ease-out;
    -moz-transition: color 1s ease-out;
    -o-transition: color 1s ease-out;
    transition: color 1s ease-out;
    font-weight: 100;
    color: #fff;
    -webkit-font-smoothing: antialiased;
}
nav a:hover {
    color: #16a085;
}
#welcome {
    height: 600px;
    width: 100%;
    text-align: center;
    text-transform: uppercase;
    background-color: black;
}
#welcome h1, #item1 h1, #item2 h1 {
    font-weight: 100;
    -webkit-font-smoothing: antialiased;
}
#titlediv {
    border: 2px solid #fff;
    width: 180px;
    margin: auto;
    padding: auto auto;
    position: absolute;
    left: 0;
    right: 0;
    overflow: auto;
}
.barrier {
    height: 120px;
    width: 100%;
    background: transparent;
}
#item1 {
    height: 600px;
    width: 100%;
    text-align: center;
    background-color: white;
    color: #16a085;
}
#item1 h1, #item2 h1 {
    padding: 5% 0;
}
#item2 {
    height: 600px;
    width: 100%;
    text-align: center;
    background-color: black;
    color: white;
}

Answer №1

Let's start with a demonstration!
http://jsfiddle.net/ImagineStudios/c604vbrn/10/
Your goal seems to be centered vertically and horizontally within the div, am I right?
There's a nifty CSS trick for achieving this that I find very handy:

<div id="welcome">
<div id="titlediv">
<h1>Your Title Here</h1>
</div>
</div> 

Firstly, we give position:relative; to the id="welcome" div:

/*Utilizing your current CSS*/
#welcome {
height: 600px;
width: 100%;
text-align: center;
text-transform: uppercase;
background-color: black;
position:relative;
}

Then comes the magic! The <div> with id="titlediv" is assigned position:absolute; along with a few other properties:

#titlediv {
border: 2px solid #fff;
width: 180px;
margin: auto;
padding: auto auto;
position: absolute;
width: 180px;
height: 76px;
left: 0;
right: 0;
top:0;
bottom:0;
overflow: auto;
}

This neat little hack only works if width and height are specified. Moving on to fixing the navigation bar effortlessly:

#navbar {
position:absolute;
top:0;
right:100px;
height: 30px;
z-index:10;
}

To tie it all together, here's a full-screen demo to showcase everything:
http://jsfiddle.net/ImagineStudios/c604vbrn/10/embedded/result/

Answer №2

is the solution you've been looking for!

//INCLUDE THE FILES
<script src="jquery.min.js"></script>
<script src="jquery.enhanced.js"></script>

//EXECUTE THE SCRIPT
<script>
$(document).ready(function(){
$("#header").enhanced({topSpacing:30});
});
</script>

Answer №3

When facing a similar situation, I would recommend building your webpage using a framework such as Bootstrap or Foundation. If you're looking for something lightweight, Skeleton is a great option that is easy to use and has plenty of snippets available online:


http://getbootstrap.com/ |


I hope this advice helps you, and in the future, consider starting with a quick search on Google.

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

Tips for placing a div within a curved div?

I've got a nested div situation, <div style="background-color: red; height: 100px; width: 100px; border-radius: 10px;" id="div1"> <div style="background-color: orange;" id="div2"> testing </div> </div ...

Exclude certain labeled posts from appearing on the homepage of a Blogger website

I am managing a website dedicated to the best WhatsApp status on my blogger blog. I am in search of a way to conceal certain category posts from appearing on the homepage using coding techniques. Despite extensive research, I have been unsuccessful in fi ...

The Google Map is not showing all the details

Our app is developed using ReactJS on Rails API, with a Google map integrated. However, when visiting this link and clicking "Map View", some grey space appears under the Google Map. An example image can be found here: example We are having trouble findi ...

Is there a way to retrieve values from a different menu without the need to refresh the page?

Whenever a radio button is clicked on a form, a popup menu is displayed. The popup menu is implemented using the Bootstrap module. However, there is an issue where selecting an option from the popup menu causes the form to reset, resulting in the loss of ...

:Incorporating active hyperlinks through javascript

Hey there, I've encountered a little conundrum. I have a header.php file that contains all the header information - navigation and logo. It's super convenient because I can include this file on all my pages where needed, making editing a breeze. ...

Copying text from an iframe using HTML and JavaScript

As someone who is relatively new to web development, I am currently attempting to transfer text from an iframe to a textarea located on a Bootstrap-html webpage. You can view an example of the code I am working with here: https://jsfiddle.net/fe5ahoyw/ J ...

Troubleshooting problems with printing HTML divs and page breaks caused by using float and position styles

Look at this class: .divDutySlip { width: 90mm; min-height: 120mm; padding: 2mm; /*float:left; position: relative; */ margin: 2mm; border: 1px solid #000000; page-break-inside: avoid; } I've modified two styles. Dis ...

display information in a structured table format

I am in need of HTML code that will render headers aligned above corresponding values when displayed. header1 header2 header3 List item 1 value111 value112 value113 value121 valueb122 valueb123 List item 2 value211 value212 value213 value221 valueb2 ...

Tips for adjusting UI size in CSS based on viewport dimensions and accommodating image content

The elements E1, E2, E3, E4 are all part of the user interface (UI) and are intended to have a hover effect. Additionally, there is a background image included in the design. Currently, this is the progress made on the project: <div class="bg"> ...

Title Divider Right

I am looking to add a divider to the right of a section title on my webpage. Here is what I have tried: I attempted this code, but here is the result: Here is the code snippet: <h4 class="section-title">Lastest From Blog</h4> .section-title ...

Utilizing CSS3 Columns to control the flow of elements and enforce breaks

Struggling to articulate my question, but I'll give it a shot :D Let's talk about the images: I'm having trouble explaining, I want to align the elements like in the first image, but all I'm getting is the second and third pictures. C ...

What is the best way to modify a date and time within an <td><input> element using jQuery?

I am looking to automate the updating of the datetime in a <td> tag, but I am struggling with implementing jQuery within tables. I also plan on resetting to the default datetime value if the checkbox is unchecked, although I will attempt to tackle t ...

Struggling to get a price calculator up and running efficiently

The code I have should be functioning, however, when I insert it into the code module in the Divi theme on WordPress, it doesn't work. Interestingly, when I try it in a notepad, it works perfectly fine but fails to function on the website itself. () ...

Transferring MySQL information to web pages using hyperlinks within a table

We have encountered a challenge while working on our game shop website, specifically related to the purchase link. The link is displayed within a mysql table and currently directs users to the same page. Our goal is to optimize efficiency by adding new gam ...

What specific CSS property creates the distinction in text vertical alignment between a <button> and a <div>?

I recently discovered that the text inside a <button> is automatically vertically centered, whereas the text inside a <div> is aligned to the top. Despite my best efforts, I couldn't determine which CSS rule was responsible for this disti ...

Completely place one element with respect to its sibling element

I am currently facing a situation where I have implemented a Navigation bar wrapper that reveals an overlay across the entire page when clicked. In order for this setup to function correctly, all the elements that the overlay covers must be sibling elemen ...

Implementing the class "col-xxl" is creating additional padding within the fluid container in Bootstrap

After playing around with the bootstrap grid system, I ran into a problem with the "col-xxl" class. Can anyone help me figure out why this issue occurred and how to fix it? <style> [class*="col"] { padding: 1rem; background ...

Switching up the image using a dropdown selection menu

I am struggling with updating an image based on the selection made in a dropdown menu. I am quite new to javascript, so I believe there might be a simple issue that I am overlooking. Here is my attempt at doing this: JS: <script type="text/javascript" ...

Background of jQuery-UI Slider

Can the background color of a jQuery-UI Slider widget be set using JavaScript? This is the default setting: What I am trying to accomplish is the following: The green range should be determined based on historical data. I want to visually show the user ...

Improper Placement of Bootstrap 5 Modal

I seem to be facing an unexpected issue where the Bootstrap 5 Modal and other components are displaying inside the sidebar menu instead of the main content area. Has anyone encountered this problem before? How can it be resolved? Here is a test example: ...