Issue with content not properly aligning next to the vertical navigation bar

I've set my vertical navigation to be 10% width and my content to be 90%, but for some reason, I can't get them to align properly next to each other. I've experimented with float: left and display: inline-block, but so far nothing has worked. Any assistance would be greatly appreciated.

@import url(http://fonts.googleapis.com/css?family=Play);
/* CSS Reset */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
.clearfix:before,
.clearfix:after {
    content: "";
    display: table;
}
.clearfix:after {
    clear: both;
}

/* --------- */
.mainHeader {
background: rgb(255,50,50);
padding: 20px;
}
.mainHeader h1 {
font-family: "Play";
color: rgb(255,255,255);
font-size: 24px;
}
.mainNavigation {
padding: 12px;
width: 10%;
height: 900px;
font-family: "Play";
font-size: 18px;
background: rgb(255,50,50);
float: left;
}
.mainNavigation ul {
padding: 0;
margin: 0;
list-style-type: none;
list-style: none;
}
.mainNavigation ul li {
width: 100%;
padding: 2px;
}
.mainNavigation ul li a {
text-decoration: none;
color: rgb(255,255,255);
padding: 12px;
width: 100%;
-webkit-box-sizing : border-box;
    -moz-box-sizing : border-box;
    box-sizing : border-box;
display: inline-block;
border: 1px solid rgb(255,100,100);
}
.mainNavigation ul li a:hover {
background: rgb(255,255,255);
color: rgb(0,0,0);
}
.mainContent {
padding: 8px;
display: inline-block;
width: 90%;
margin: 0 auto;
-webkit-box-sizing : border-box;
    -moz-box-sizing : border-box;
    box-sizing : border-box;
}
.article {
background: rgb(222,222,222);
padding: 8px;
margin: 0 auto;
border: 1px solid rgba(222,222,222,0.5);
width: 90%;
font-family: "Play";
}
<!doctype HTML>
<html>
  <head>
    <link href="css/reset.css" type="text/css" rel="stylesheet"/>
    <link href="css/base.css" type="text/css" rel="stylesheet"/>
    <title>temp</title>
  </head>
  <body>
    <div class="mainHeader">
      <h1>Jackatron</h1>
    </div>
    <div class="mainNavigation">
      <ul class="clearfix">
        <li><a href="index.php">Home</a></li>
        <li><a href="index.php">Profile</a></li>
      </ul>
    </div>
    <div class="mainContent">
      <div class="article">
        <h1>Hello</h1>
      </div>
    </div>
  </body>
</html>

Answer №1

The #primaryMenu section is styled with a padding of 12 pixels. If the box-sizing property is not set to border-box, the width of #mainNavigation will be calculated as 10% plus an additional 24 pixels (2 times 12 pixels), causing it to not align properly with the 90% width of the #mainContent section.

Setting 'box-sizing: border-box' ensures that the element's width includes the specified padding or border (please note that this does not apply to margin).

Many developers nowadays opt for globally setting box-sizing:border-box as it is a more intuitive approach. Here is a code snippet that can be placed at the beginning of the main CSS file:

*,
*:before,
*:after {
    box-sizing: border-box;
}

Answer №2

To resolve the problem, try adjusting the max-width property for your navigation and content sections instead of just using width:

.mainNavigation {
  max-width:10%;
}

.mainContent {
  max-width: 90%;
}

There are other potential solutions depending on how you want the layout to appear. For example, you could leave the width of .mainContent unset.

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 use of DIV tags allows the element to be displayed in an inline

In my project, I decided to add three div tags. The first two are positioned next to each other with the third div tag placed below them. However, when I tried to insert a slideshow into the first div tag, all of the div tags ended up displaying as "block" ...

How can I prevent scrolling in a Vue mobile menu?

In this scenario, the toggle for the menu is controlled by a checkbox with the id "check" below. I attempted to bind v-bind:class="[{'antiscroll': checkboxValue}]" to the body in HTML, and also in the main App.vue file, but it did not work as exp ...

Is there a way to apply a custom CSS to Bootstrap without altering its appearance?

Check out this code snippet <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/sub-cat.css"> I am having trouble with my CSS. I tried to modify the "Caption" class in Bootstrap by adding some new styles in "sub- ...

Configure UL element as a dropdown on mobile devices and expand it to full width on desktop screens

Circumstances This HTML code is intended to create a horizontal <ul> element that spans the entire width of the <div class="list__wrapper"> container on desktop screens with a minimum width of 1024px. However, for mobile devices with a maximum ...

Creating PNG images in a scripting language for web applications

Imagine giving your website user the ability to specify a radius size, let's say 5px, and in return receiving a PNG file with a circle of that radius. This question can be divided into two sections: In what language and using which technologies can ...

Enhancing TextFields with React Material Margins

I am facing a simple issue where I attempted to add marginButtom to the TextFields but for some reason, it is not applying any margin. Please take a look at this codesandbox link CLICK HERE CODE <label>Schedule</label> <Te ...

Applying a margin to a CSS div at the bottom may cause it to not

I'm struggling to achieve the desired outcome with my layout: https://i.stack.imgur.com/CvLFl.png I have successfully replicated the image, but only when my div is not floating on the page (without margin applied and without using position: absolute ...

Using jQuery to control mouseenter and mouseleave events to block child elements and magnify images

My objective is to create a hover effect for images within specific div elements. The images should enlarge when the user hovers their mouse over the respective div element. I plan to achieve this by adding a child element inside each div element. When the ...

Issue with Safari not displaying properly when using float:left and float:right (works fine in Firefox and Chrome)

My website has a left side column and a right side column, which display correctly in Firefox and Chrome. However, I am experiencing issues with Safari. Any insights on what could be causing this problem and why it only occurs in Safari? View the code on ...

Enhanced Organic Draping/Drifting

Currently working on creating a basic thumbnail gallery where clicking on a thumbnail expands it to one of three sizes (square, vertical, or horizontal). However, facing the issue where expanded pictures maintain their original order instead of filling emp ...

Is there a way to trigger both the link and the div element simultaneously?

Is there a way to make both the button and the link light up simultaneously when hovering over the div element, instead of just the button lighting up first? <div id="b1"; class = b> <a href="test.html">BUY</a> < ...

What is the best way to avoid using ng-repeat for the last item being shown?

I currently have an ng-repeat loop that is dependent on an ng-if condition. Here is the specific code block: <div class="fav-prod-customised> <p ng-repeat="ingredient in product.options" ng-if="ingredient.default_quantity == 0 & ...

Updating user credits through the Model::factory() method is a common practice in my workflow

I need to update the UserCredits after a purchase. For example, if a user currently has 10 credits and purchases 10 more, I want to add the purchased credits to their existing total. The goal is to increment the current credit score with the new credits ...

Reducing the amount of text displayed on ion-text to a minimum

HTML: <ion-list *ngFor="let message of messages"> <ion-item lines="none" type="button" button="true"> <ion-grid> <ion-row> <ion-col class="message"> <ion-text> ...

Adjust the size of the iframe image to fit seamlessly within the design

Is there a way to adjust the size of the image on the right without altering the layout design? The current GIF is 500x500px, but it is only displaying as 100x100px. Any assistance would be greatly appreciated! To see what I currently have (Demo with code ...

How can I use jQuery to set a background image and position on a website?

I am trying to incorporate a background image fade effect along with the color fade in and out when hovering over a link using my current code. However, I am unsure of how to set the background image and position within the code. $(document).ready(funct ...

Guide on integrating materialize-css npm package into webpack

I'm currently developing a client-side application with Webpack and facing challenges when trying to incorporate the materialize-css package. Using Henrik Joreteg's hjs-webpack package, I was able to include the yeticss npm package by importing i ...

Adjustable height and maximum height with overflow functionality

Currently, I am in the process of developing a task manager for my application and facing an obstacle when trying to calculate the height of a widget. My goal is to determine the maximum height (assuming a minimum height is already set) by subtracting a ce ...

A div element featuring a border with transparent edges on the top right and bottom left corners

Does anyone know how to code the border for the upper right corner and lower left corner of the box (as shown in the image below)? I would really appreciate some help. Thank you in advance! This is the HTML <div class="carouselle"> <div clas ...

Adaptable arrow-shaped progress bar featuring sleek transparent borders

I am currently working on creating a progress bar similar to those commonly found in checkout processes. One issue I have encountered is that the borders between the arrows appear transparent, and the entire design needs to be responsive. So far, I have m ...