Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

fixing an alignment problem

Featured Replies

I have a weird problem going on. When I first load up the site, everything seems to be fine. Then I hover over one of the nav buttons and 3 of the 4 main container elements seem to shift to the left a few pixels (well it looks more like a percentage rather than a fixed measurement). Once the first re-alignment happens. Nothing happens again till you refresh the page or go onto another page where the same thing will happen. All the elements are fine till you hover over a nav element where it will then shorten the width of 3 of the 4 elements.

 

I feel my inexperience has gotten me into a bit of a pickle and was wondering if someone could spot where my css conflicts with my idea of how the page should look.

 

Below is a pic giving you a visual representation of the problem. In the pic I drew some guidelines so you might see the problem.

 

 

alignmentproblem_zpsd473ebb8.jpg

 

 

Below are copies of actual HTML and CSS files if you need it to reproduce the error

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Celebrity Fireworks - cityscape - home</title>
<link rel="stylesheet" type="text/css" href="CSS/menustyle.css"
</head>
<body>
<div id="pagewrapper">
<header>
<h1>Celebration Fireworks</h1>
<figure>
<img id="headerBanner" src="RES/cityscape self original2.png">
</figure>
</header>
<nav>
<a id="navSelected" href="index.html">Home</a>
<a href="history.html">About</a>
<a href="displays.html">Displays</a>
<a href="weddings.html">Weddings</a>
<a href="events.html">Events</a>
<a href="media.html">Media</a>
<a href="info.html">Help</a>
</nav>

<main>
<content id="leftSideBar">
</content>
<content id="DYI">
<h1 class="contentHead">'Do it yourself'</h1>
<article class="DYI_main" id="DYI_1">
<h1 class="articleHead">Title of Topic 1<h1>
<footer class="articleFoot"><p>brief description of topic 1</p></footer>
<p>This is the text that will fill in on the page when the user clicks 'read more....' link. The page will have an opaque rectangle READ MORE...<span class="articleShrink"> that shades out the main site's page.Then in the middle of that rectangle a smaller more darker rectangle with more information about that topic with a picture to help aid understanding.</span></p>
</article>
<article class="DYI_main" id="DYI_2">
<h1 class="articleHead">Title of Topic 2<h1>
<footer class="articleFoot"><p>brief description of topic 2</p></footer>
<p>This is the text that will fill in on the page when the user clicks 'read more....' link. The page will have an opaque rectangle READ MORE...<span class="articleShrink"> that shades out the main site's page.Then in the middle of that rectangle a smaller more darker rectangle with more information about that topic with a picture to help aid understanding.</span></p>
</article>
<article class="DYI_main" id="DYI_3">
<h1 class="articleHead">Title of Topic 3<h1>
<footer class="articleFoot"><p>brief description of topic 3</p></footer>
<p>This is the text that will fill in on the page when the user clicks 'read more....' link. The page will have an opaque rectangle READ MORE...<span class="articleShrink"> that shades out the main site's page.Then in the middle of that rectangle a smaller more darker rectangle with more information about that topic with a picture to help aid understanding.</span></p>
</article>
</content>
<content id="LetMe">
<h1 class="contentHead">'Let me do it'</h1>
<article class="LetMe_main" id="LetMe_1">
<h1 class="articleHead">Title of Topic 1<h1>
<footer class="articleFoot"><p>brief description of topic 1</p></footer>
<p>This is the text that will fill in on the page when the user clicks 'read more....' link. The page will have an opaque rectangle READ MORE...<span class="articleShrink"> that shades out the main site's page.Then in the middle of that rectangle a smaller more darker rectangle with more information about that topic with a picture to help aid understanding.</span></p>
</article>
<article class="LetMe_main" id="LetMe_2">
<h1 class="articleHead">Title of Topic 2<h1>
<footer class="articleFoot"><p>brief description of topic 2</p></footer>
<p>This is the text that will fill in on the page when the user clicks 'read more....' link. The page will have an opaque rectangle READ MORE...<span class="articleShrink"> that shades out the main site's page.Then in the middle of that rectangle a smaller more darker rectangle with more information about that topic with a picture to help aid understanding.</span></p>
</article>
<article class="LetMe_main" id="LetMe_3">
<h1 class="articleHead">Title of Topic 3<h1>
<footer class="articleFoot"><p>brief description of topic 3</p></footer>
<p>This is the text that will fill in on the page when the user clicks 'read more....' link. The page will have an opaque rectangle READ MORE...<span class="articleShrink"> that shades out the main site's page.Then in the middle of that rectangle a smaller more darker rectangle with more information about that topic with a picture to help aid understanding.</span></p>
</article>
</content>
<content id="rightSideBar">
</content>
</main>

<footer><p>Copyright © Dennis Ross Tudor Jr</p>
</footer>
</div> <!-- END OF pagewrapper DIV -->
</body>
</html>

 

CSS:

@charset "utf-8";
*{
    margin: 0;
    padding: 0;
}
body{
    font-family: "Trebuchet MS", Helvetica, sans-serif;
    font-size: 18px;
    background-color: #1D201E;
    width: 1640;
    height: 1200;
}
#pagewrapper{
    margin: 15px auto;
}
header{
    width: 90%;
    height: 178px;
    margin: 0 auto;
    margin-bottom:10px;
    background-color: #554F4D;
    border: 3px solid #A7ABA8;
    border-radius: 8px; 
}
header h1{
    color: #EEE;
    text-align: center;
    font-size: 3.5em;
}
#headerBanner{
    width:100%;
    height:100px;
}
nav{
    width: 742px;
    height: 135px;
    margin: 0 auto;
    border:3px solid #A7ABA8;
    border-radius:10px;
    padding: 10px;
}
nav a{
    border-radius: 10px; 
    text-decoration: none;
    border: 3px solid #CCC;
    margin-right: 10px;
    display: block;
    float:left;
    width: 90px;
    text-align: center;
    color: #EEE;
    height: 90px;
    line-height: 12em;
    background-color: #554F4D;
    transition: all 250ms linear 50ms;
}
nav a:hover{
    text-shadow: 2px 2px 2px #000;
    color: #FFF;
    height: 125px;
    line-height: 12.5em;
    background-color: #DDD;
}
nav #navSelected{
    text-shadow: 2px 2px 2px #000;
    color: #FFF;
    height: 125px;
    line-height: 12.5em;
    background-color: #DDD;
}
main{
    width:100%;
    height: 465px;
    margin: 0px auto;
    clear:both;
    padding: 10px;
}
content{
    display:block;
    float:left;
    width: 450px;
    height: 475px;
    border: 3px solid #A7ABA8;
    padding: 5px;
    margin-left: 15px;
    margin-bottom: 10px;
    border-radius: 16px;
    background-color: #554F4D;
    transition: all 150ms linear 50ms;
}
#leftSideBar{
    margin-left: 75px;
    width: 250px;
}
#rightSideBar{
    width: 250px;
    margin-right;0;
}
.contentHead{
    font-size: 42px;
    color: #D3D5D3;
    text-align:center;
    margin-bottom:35px;
}
content article{
    height: 120px;
}
content article p{
    clear:right;
    color: #A7ABA8;
    text-align:left;
    font-size: 14px;
}
.articleHead{
    font-size: 18px;
    text-align:left;
    color: #CCC;
}
.articleShrink{
    visibility:hidden;
}
.articleFoot {
    background-color:inherit;
    border: none;
    width:100%;
    height: 20px;
    /* margin:5px; */
}
.articleFoot p{
    text-align:justify;
    line-height:8px;
    font-style: italic;
    font-size: 12px;
    color: #A7ABA8;
}
footer{
    clear: both;
    width: 90%;
    height: 20px;
    border: 3px solid #A7ABA8;
    margin: 0 auto;
    background-color: #554F4D;
    border-radius: 4px;
}
footer p{
    margin-left: 25px;
    font-size: 14px;
    font-style: italic;
    color: #D3D5D3
}

 

Hello the first thing I can see is that you don't have any units for your body width and height.

 

body{
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 18px;
background-color: #1D201E;
width: 1640; <!-- this should be 1640px -->
height: 1200; <!-- this should be 1200px -->
}

 

Try changing that first and see if your problem still persists.

 

It's also worth noting that you usually apply width and height dimensions to a container wrapper (#pagewrapper) instead of the body directly.

Edited by OliverB

I put it in codepen and couldn't replicate it. If Oliver's help doesn't solve your problem, can you provide a little more information? What browser it is happening in, perhaps give a live example?

I couldn't replicate it in codepen either, so not 100% sure what's happening, But my first suggestion might help.

  • Author

Thx Oliver. I actually went and tried to validate my css and came up with the 'px' error. When I put it in and reloaded the page it seemed to have fixed the problem. :) Thank you again.

 

Edit: Thank you for the advice about putting the dimensions on the div. :)

Edited by drt_t1gg3r

drt_t1gg3r,

It's worth pointing out that there's currently no <content> element in the HTML spec, it was proposed a few years back but rejected.

You can find the current draft here (elements start at section 4), good idea to bookmark for reference :)

  • Author

To Wynn: thx so much for that. I wonder, first, why I used 'content' as a tag in the first place and, secondly, why did the tag actually work when, at least, the CSS shouldn't have due to how tags, classes, and other elements are handled. I have been brushing up on my education with tons of videos and site copy and some how it got stuck in my head. But all changed now but, I wonder why it worked with <content> as an element. =?

Edited by drt_t1gg3r

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.