Positioning a div element directly beneath another div and aligning it to the left

Currently, I am working on a project using ASP.NET MVC 4. In terms of the user interface, particularly in relation to the _Layout, it is a very basic setup that will be consistent across all pages. While utilizing bootstrap 3, the website is primarily designed for large display devices and may involve other tools as needed.

Although I am incorporating styled elements from bootstrap 3 for the foundational layout, these elements have already been customized. Therefore, my inquiry leans more towards general CSS/JS principles rather than focusing on specific frameworks or libraries. By seeking assistance here, I hope to find the optimal solution for the following issue:

To aid in clarity due to my limited experience, I have utilized distinct colors to explain what I aim to achieve. Within the

<div id="top-nav-wrapper">
, which solely serves as a container for three other divs and provides the background image, there is a slight challenge with larger resolutions causing unwanted stripes at each end of the centered, fixed 970px layout. The styling for this wrapper div is relatively straightforward:

#top-nav-wrapper {
    background-image:url('/Content/images/navbar-stripe.png');
    background-repeat:repeat-x;
}

Contained within the #top-nav-wrapper are three additional div tags. The first one features a dark blue background -

<div class="container">
. While utilizing the bootstrap 3 class .container, its style has been customized to include:

.container {
  max-width: none !important;
  width: 970px;
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

Following this div is another one housing navigation buttons against a dark yellow background -

<div class="container" style="height: 80px; padding-right: 0px
!important; padding-left: 0px !important;">

This div also utilizes the .container class but incorporates additional styling elements as shown.

The final div represents a grey line -

<div class="container" style="background-color: grey; height: 50px;">
, applying the predefined .container class with some modifications.

The highlighted red box in the diagram indicates what needs to be introduced next. Looking to insert a vertical menu under the dark yellow div, maintaining alignment with its bottom-left corner. The "Home" link within the menu should be displayed in blue to demonstrate this positioning. Additionally, the menu should overlay the grey div similar to the illustration provided above. Essentially, the goal is to ensure the vertical menu always matches the width of the "Home" menu link, a task I feel can be achieved with minor adjustments using jQuery. As such, my main question revolves around the proper method of positioning the div in the desired manner?

Answer №1

If my understanding is correct, the 970px containers begin at the left edge of the light blue Home link and extend "off screen" towards the right. Feel free to correct me if I am mistaken.

In this scenario, I would recommend setting up a single container that is 970px wide with auto margins for centering it, and then placing the other containers inside. If the red box is nested within the 970px-wide container, knowing the height of the gray box allows you to simply style the red box with margin-top: -50px

Below is some code for reference, which you can view in this JSFiddle.

HTML:

<div id="top-nav-wrapper">
    <div class="container">
        <div style="height: 50px; background: #006"></div>
        <div style="height: 80px; padding-right: 0px
!important; padding-left: 0px !important; background: #eb0;"></div>
        <div style="background-color: grey; height: 50px;"></div>
    </div>
</div>
<div id="main-wrapper">
    <div class="container">
        <div style="background: red; width: 200px; height: 400px; margin-top: -50px"></div>
    </div>
</div>

CSS:

#top-nav-wrapper {
    background-image:url('/Content/images/navbar-stripe.png');
    background-repeat:repeat-x;
    width: 100%;
}

.container {
  max-width: none !important;
  width: 970px;
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

.container div {
    width: 100%;
}

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

Added the .active state to the menu navigation successfully, however the active color was not implemented

My primary navigation menu is managed by WordPress and can be seen below. I aimed to modify the active state when a user clicks on a link in the menu by adding background-color and color for styling purposes. Although changing the background-color upon cl ...

Having trouble aligning page in the center with flexbox and styled components

Hey there, I'm having some trouble figuring out how to center my page using flexbox within styled components in a Next.js app. Any suggestions or tips? Let me share with you my Blog Component import ReactMarkdown from 'react-markdown' impor ...

What is the best way to send multiple values from the view to a method without using two-way binding?

https://i.sstatic.net/X4ivP.png When I change the dropdown value for the route type in my code, I need to pass both the gender value and the route type ID to my data retrieval method. Currently in my HTML file, I have only written a change event. I attem ...

Utilizing Laravel 5.2 to showcase a video

I am currently developing in Laravel 5.2 and facing an issue with displaying a video on my view page. While I can successfully store the video in my database table, I am encountering difficulties when trying to fetch and display it. In my database table, I ...

When using the jQuery datepicker with the minDate set to 0, any past dates entered in the text box will be automatically reset to the current date

How can I prevent users from selecting past dates in a jQuery datepicker, while keeping any existing past dates displayed as is? My current code looks like this: $("#t1").datepicker({ minDate:0 }); And the text box code is, <input type="t1" va ...

"Implement a jQuery fade-in effect following a collective toggle action

After looping through the hidden elements, the $("span#slogan").fadeIn("slow"); does not execute. How can I ensure that the fadeIn is the last action to be performed? <style type="text/css> #hidden span{ display:none; float:left; font-siz ...

What is the best way to set the tab as "active" in the first iteration of a PHP while loop?

When using a while loop to populate tabs with PHP, maintaining only one active tab at a time can be tricky. I have grasped that assigning the 'active' class within the loop causes all tabs to become active. So, how should I modify the script if I ...

The picture tag in HTML5 is failing to be responsive when used with Bootstrap

I'm experimenting with the html5 <picture> tag to set different images. I placed the 2 pictures within a bootstrap grid, allowing them to be responsive until the breakpoint 768px, where the image changes. However, when I decrease the browser si ...

Could you share the most effective method for implementing a live search feature using javascript or jquery?

While attempting to create a live search for a dataset containing over 10,000 rows, I specified the DOM structure that is available. Despite my efforts to check each result after a single input during the live search process, my browser keeps hanging. Is t ...

What is the best way to save the result of a post ajax request in a variable?

I am attempting to make an AJAX call to one API, store the response in a variable, and then display that output to the user. So far, I have experimented with two different methods: var Fake = $.ajax({async:false, url:'http://9dbad321.ngrok.io/output ...

The chosen value in Select2 does not display in the order it was selected, but rather

I recently encountered an issue with a third-party plugin created by Ivan Vaynberg. When using the multiselect feature in select2, I noticed that the select2("val") method returns selected values in sorted order, rather than reflecting the order in which t ...

Tips for maintaining high performance while continuously animating SVG paths

I'm currently working on developing a mobile game that involves drawing 6 SVG paths and continuously moving them from top to bottom on the screen. I have implemented a simple JavaScript function that updates certain variables and uses them to set the ...

Animating colors with jQuery and shifting SVG shapes to create dynamic and

I am currently working on an svg animation that involves changing the color of the svg to a different color, creating a running light effect. Rather than fading the fill color of the entire svg as commonly seen in examples, I aim to achieve a dynamic trans ...

Tips for extracting an SVG path from HTML structure

This example I'm referencing is by Chris Coyer <svg version="1.1" xmlns="http://www.w3.org/2000/svg" mlns:xlink="http://www.w3.org/1999/xlink" style="display: none;"> <defs> <g id="icon-image"> <path class="path1" d="M0 4v26h32v ...

relocate information to another div when the page is resized

I am working on a design where all the text is inside one div on mobile and tablets, but on desktop, the p tags move to the div below it. Each div has its own unique background image. Here's how the markup looks like: <main> <div class= ...

Separate the data into categories and create pie charts to represent each one

I am currently retrieving data from a backend database server, and the information being returned is as follows: [{ "Year": 2014, "Name": "A", "Values": 18 },{ "Year": 2014, "Name": "B", "Values": 16 },{ "Year": 2015, "Name": "D", "Values": 20},{ "Year": ...

Utilize the assigned value of a variable from a separate file

Is it possible to set a variable in an external file called "Variable.js", assign it a value in a file named "Page1.html", and then use that variable with its assigned value in another file named "Page2.html"? For example, let's consider the contents ...

What is the best way to incorporate hyperlinks or text color modifications to a variable string in JavaScript?

I have a website that features a random on-load slideshow with text displayed in div containers for each slide. I am looking to enhance the functionality by adding links or changing the color of specific words within the text. You can view my current progr ...

The jQuery Datetime Picker

I am currently attempting to utilize a date and time picker found at the following link: However, I am facing an issue where this picker only functions properly when the jquery-ui.js file is excluded. It seems that there may be a conflict with the base jq ...

Are HTML files and PHP generated files cached differently by web browsers?

My current setup involves Nginx as a web server and Firefox to check response headers. I added two files on the server - test.html and test.php, both containing the same content. In the Nginx config file, I have set the expires directive to 30d in the serv ...