Containers situated at the core

Seeking assistance with centering two containers horizontally on the site. Specifically, I would like the menu with the logo on the right side and the content block to be centered. Despite trying various methods, nothing seems to work for me. Previously, I utilized frames but now wish to use containers instead. Any help would be greatly appreciated.

Thank you!

Best regards, Ronny

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Containertest</title>
<style type="text/css">

body { margin:0; background-color: #333333;}

.wrapper{
    min-height: 100%;
    height: auto !important;
    height: 100%;
    position: relative;
    /* background: url("ronny_logo.jpg"); */
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    z-index: 0;
}

/* MENU */
#main_menu{
    margin:0px;
    padding:0;
    height: 150px;
    /* width: 100%;      /* Breite vom Hauptmenü Container */
    padding: 0px 0;
    /*overflow: hidden; Remove this*/
    position: fixed;
    background-color: black;
    z-index: 2;
}
#main_menu li{
    list-style: none;
    float: left;
    line-height: 30px;
    margin-left: 10px;
    width: 130px;
    text-align: center;
    margin-top: 120px;
    position: relative;
}
#main_menu li a, #footer_menu li a {
    color: #FFFFFF;
    text-shadow: 0px 1px 1px #000;
    display: block;
    font-family: 'PT Sans', sans-serif;
    text-decoration: none;
    font-size: 12pt;
}
#main_menu .logo{
    background: none;
    width: 445px;
    margin: 0;
}
#main_menu li a:hover, #footer_menu li a:hover{
    text-decoration: underline;
}
#main_menu li .submenu{
    display: none;
    margin: 0;
    padding: 0;
    z-index: 10;
    position: absolute;
    left: 0;
    top:100%;
}
#main_menu li .submenu:hover{
    display: block;
}
#main_menu li a:hover + .submenu{
    display: block;
}
#main_menu li .submenu li{
    margin: 0;
    padding: 0;
}
#main_menu li .submenu li a{
    font-size: 9pt;
}
/* COLORS */
.red, .red .submenu{ background-color: #ed3327; }
.blue, .blue .submenu{ background-color: #9dbdd5; }
.green, .green .submenu{ background-color: #6fb145; }
orange, .orange .submenu{ background-color: #f5832e; }
yellow, .yellow .submenu{ background-color: #f6ec35; }

/* CONTENT */
#content{
    padding: 20px 0;
    overflow: hidden;
    margin:  0;
    padding: 20px;
    font-size: 9pt;
    color: #FFFFFF;
    background-color: #555555;
    width: 965px;
}

</style>
</head>

<body>
<div class="wrapper">
    <div class="patterned">
        <div class="container">
            <ul id="main_menu">
                <li class="logo">
                    <a href="#">
                        <img src="ronny_logo.jpg" alt="Logo"/>
                    </a>
                </li>
                <li class="red">
                    <a href="#">Home</a>
                </li>
                <li class="green">
                    <a href="#">Events</a>
                    <ul class="submenu">
                        <li>
                            <a href="#">Item</a>
                        </li>
                        <li>
                            <a href="#">Item</a>
                        </li>
                        <li>
                            <a href="#">Item</a>
                        </li>
                    </ul>
                </li>
                <li class="blue">
                    <a href="#">Bus</a>

                </li>
                <li class="orange">
                    <a href="#">Contact</a>
                </li>
            </ul>
        </div>
    </div>
    <div class="container">
        <div id="content">
            <p>fadsfdsfdas</p>
            <p>dfsadfaf</p>
            <p>d</p>
            <p>d</p>
            <p>d</p>
            <p>d</p>
            <p>&nbsp;</p>
            <p>gg</p>
            <p>&nbsp;</p>
            <p>g</p>
        </div>
    </div>
</div>



</body>
</html>

https://i.sstatic.net/v4Q63.jpg

Answer №1

To make positioning easier, assign a specific width to your container and set the margin to 0 (top/bottom) auto (left/right). Also, include position: relative to allow the browser to position it relative to the parent container, in this case, the .wrapper class.

.patterned .container{width: 960px; margin: 0 auto; position: relative;}
.container{width: 960px; margin: 0 auto; position: relative;}

By specifying the parent class before the child class, you can target a specific container individually. This is helpful when dealing with multiple containers sharing the same class but needing different styling.

Answer №2

Try this alternative approach utilizing the flex property:

<style>
    body { 
      width: 100%;
      margin: 0;
      padding: 0;
      background-color: #333333;
    }
    .wrapper{
      min-height: 100%;
      height: auto !important;
      height: 100%;
      position: relative;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
      z-index: 0;

      display: flex;
      align-items: center;
      justify-content: center;
    }
    #main_menu{
      margin:0;
      padding:0;
      height: 150px;
      padding: 0px 0;
      position: fixed;
      background-color: black;
      z-index: 2;

      width: 965px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    #main_menu li{
      list-style: none;
      float: left;
      line-height: 30px;
      margin-left: 10px;
      width: 130px;
      text-align: center;
      margin-top: 120px;
      position: relative;
    }
    #main_menu li a, #footer_menu li a {
      color: #FFFFFF;
      text-shadow: 0px 1px 1px #000;
      display: block;
      font-family: 'PT Sans', sans-serif;
      text-decoration: none;
      font-size: 12pt;
    }
    #main_menu .logo{
      background: none;
      width: 445px;
      margin: 0;
    }
    #main_menu li a:hover, #footer_menu li a:hover{
      text-decoration: underline;
    }
    #main_menu li .submenu{
      display: none;
      margin: 0;
      padding: 0;
      z-index: 10;
      position: absolute;
      left: 0;
      top:100%;
    }
    #main_menu li .submenu:hover{
      display: block;
    }
    #main_menu li a:hover + .submenu{
      display: block;
    }
    #main_menu li .submenu li{
      margin: 0;
      padding: 0;
    }
    #main_menu li .submenu li a{
      font-size: 9pt;
    }
    .red, .red .submenu{ background-color: #ed3327; }
    .blue, .blue .submenu{ background-color: #9dbdd5; }
    .green, .green .submenu{ background-color: #6fb145; }
    .orange, .orange .submenu{ background-color: #f5832e; }
    .yellow, .yellow .submenu{ background-color: #f6ec35; }

    #content{
      overflow: hidden;
      margin-top: 150px;
      font-size: 9pt;
      color: #FFFFFF;
      background-color: #555555;
      width: 965px;
    }
</style>
<body>
  <div class="wrapper">
    <ul id="main_menu">
      <li class="logo">
        <a href="#">
          <img src="ronny_logo.jpg" alt="Logo"/>
        </a>
      </li>
      <li class="red">
        <a href="#">Home</a>
      </li>
      <li class="green">
        <a href="#">Evenementen</a>
        <ul class="submenu">
          <li>
            <a href="#">Item</a>
          </li>
          <li>
            <a href="#">Item</a>
          </li>
          <li>
            <a href="#">Item</a>
          </li>
        </ul>
      </li>
      <li class="blue">
        <a href="#">Bus</a>
      </li>
      <li class="orange">
        <a href="#">Contact</a>
      </li>
    </ul>
    <div id="content">
      <p>fadsfdsfdas</p>
      <p>dfsadfaf</p>
      <p>d</p>
      <p>d</p>
      <p>d</p>
      <p>d</p>
      <p>&nbsp;</p>
      <p>gg</p>
      <p>&nbsp;</p>
      <p>g</p>
    </div>
  </div>
</body>

No additional divs are necessary for this solution.

Cheers!

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

Center the code within the h2 heading

Here in this demonstration (bootply link): <h2>Title <small><code>one line</code></small></h2> I am attempting to vertically center the code element with the title. Despite trying to apply vertical-align: middle to the ...

How come my gifs appear tiny even though I've adjusted their width to 32% each?

I am trying to display three gifs in a row, each taking up one-third of the width of the page. However, when I preview the page, the gifs appear tiny. I have set the divs to 32% each and the gifs should fill 100% of their respective div. Here is the code s ...

Guide on how to show an icon in Meteor when a link is clicked

Is there a way to display a viewed icon upon clicking a link in Meteor? On my list of jobs page, when a user clicks on a job, they are taken to the description page. I would like to add an icon to the post indicating that the user has viewed it. ...

Having trouble getting the header div to span the entire screen

I'm currently working on a project where I have set the header div to 100% width and the main container to also be 100% width. However, I am facing an issue where the right and left sides of the header are not filling the entire space. I managed to fi ...

Revolutionary newspaper design utilizing asp.net's C# web forms

Trying to create a dynamic newspaper layout using ASP.NET C# web form. Struggling to set the page layout size inside a slider and display specific news content on a new page when clicking on an area of the newspaper using Repeater or another suitable contr ...

Tips for integrating semantic HTML with React components

As a newcomer to react, I am eager to establish a strong foundation before delving deep into the language and risking having to backtrack later on. I am curious about how to incorporate semantic HTML in react. Elements such as <header>, <nav>, ...

Display and conceal fields based on radio button selection using JavaScript

Hello, I have a specific scenario that I need assistance with. In my code, I have a div container that contains 3 radio buttons with IDs "rad1", "rad2", and "rad3". Additionally, I have a form with 2 text fields that have IDs "textField1" and "textField2". ...

Steps for choosing an image and embedding it within a div element

Upon loading the site, an image is displayed with the following code: <img id="some_Image" src="some_source"> However, I am looking to avoid requesting this image again from "some_source". This is because calculating the image can be resource-inten ...

Show information from the console logger

I'm currently working on displaying data from a database in an HTML page. While the data is showing up in my console, I'm struggling to figure out how to present it in an HTML table format. I'm unsure about the specific function that needs t ...

What is the reason behind utilities.scss taking precedence over styles.scss and local scss files?

After defining the mt-5 class in both my component's .scss file and the root styles.scss, I noticed that they were both overwritten by _utilities.scss. This left me wondering why this was happening. https://i.sstatic.net/idnze.png https://i.sstatic.n ...

What is the best way to vertically center text within a selection box? (This is not referring to a select box or a div box)

While assigning a line-height to text elements like div, span, or p and dragging them in the browser, an unsightly empty space appears within the selection box: https://i.sstatic.net/Ws08H.png I am seeking a way to elevate the actual text content within ...

What are the steps to retrieve information from a raw HTML document?

Can data be extracted from a poorly written HTML file without IDs or classes? For example, if there is an unstructured saved HTML file of a profile webpage and I want to extract specific information like 'hobbies', can PHP be used for this task? ...

Is there a way to determine if a user has interacted with a scrollbar on a website?

Is there a Jquery function available to determine if a user is currently holding onto a scrollbar on my website? I need to return a Boolean value based on whether the user has control of the scrollbar or not. Additionally, I am encountering a specific iss ...

The Android browser is failing to load a Jquery Mobile page using XHTML

Review the code snippet below for an XHTML page named page1.xhtml. This page includes Jquery Mobile scripting: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Page 1</title> ...

Design a square confined within an adjustable rectangular container

Looking to fill a rectangular area on my page with a square positioned in the center, regardless of whether the rectangle is horizontal or vertical. Many existing solutions focus solely on creating a square from the width of a containing box, which doesn&a ...

The Ray Intersect function in THREE.js encounters issues when a div element is introduced

I have encountered an issue with my Three.js script. It works perfectly fine when there is only one target div on the page holding renderer.domElement. However, when I add another div with fixed height and width above the target div, the ray.intersectObjec ...

What could be causing the malfunction of the dropdown menu attached to my button?

I've been working on setting up a simple button in my Angular application that should display a dropdown menu with various options when clicked. I copied and pasted some Bootstrap template code, made some modifications to match the style of my app, bu ...

Icon overflowing due to Bootstrap 4 card title

I'm currently working on implementing an expand/collapse feature with a red close 'X' button in a Bootstrap 4 card. I've almost got it working, but when I try to place the red close icon outside the element that controls the expand/coll ...

What is the method for achieving a seamless rosace effect in CSS?

While working on my website, I added an interesting effect to a circle. Currently, the circle opens automatically when hovering the mouse over it and closes when the mouse moves away. However, I would like to modify it so that it automatically opens and cl ...

Align a single <td> element in the center of a row while the other row contains multiple <td> elements

I am facing an issue with centering a <td> element in a row, especially when there are multiple <td> elements in the same row. The first row's <td> element remains fixed in the first column position and does not move to the center as ...