What could be causing the div class to move downward in the CSS code?

I have posted a question, but unfortunately, no one has answered it yet. Here is my code snippet:

* {
    margin: 0;
    padding: 0;
}

body {
    width: 100%;
    font-family: 'Cabin', sans-serif;
    background-color: #333;
}

.firstnav {
    margin:auto;
    height: 1500px;
    display: block;
    width: 70%;
    -webkit-flex: 3 1 60%;
    flex: 3 1 60%;
    -webkit-order: 2;
    order: 2;
}

#third {
    background: #f00;
    position:relative;
    display:inline-block;
    width: 30%;
    margin-left:auto;
    margin-right:auto;
    height: 500px;
    -webkit-flex: 1 6 20%;
    flex: 1 6 20%;
    -webkit-order: 3;
    order: 3;
}

#second {
    background: #fff;
    position:relative;
    display:inline-block;
    margin-left:auto;
    margin-right:auto;
    width: 67%;
    height: 1500px;

    -webkit-flex: 1 6 20%;
    flex: 1 6 20%;
    -webkit-order: 3;
    order: 3;
}

#registration-form {
    font-family:'Open Sans Condensed', sans-serif;
    width: 100%;
    margin: 20px auto;
    position: relative;
    display:block;
    position:absolute;
}

#registration-form .fieldset {
    background-color:#d5d5d5;

    border-radius: 3px;

}

#registration-form legend {
    text-align: center;
    background: #364351;
    width: 100%;
    padding: 30px 0;
    border-radius: 3px 3px 0 0;
    color: white;
    font-size:2em;
}

.fieldset form{
    border:1px solid #2f2f2f;
    margin:0 auto;
    display:block;
    width:100%;
    padding:30px 20px;
    box-sizing:border-box;
    border-radius:0 0 3px 3px;
}
<div class="firstnav">

<div id="second"><p>second<p></div>
<div id="third">

    <div id="registration-form">
        <div class='fieldset'>
            <legend>Todays news
            </legend>
            <form action="#" method="post" data-validate="parsley">

            </form>
        </div>
    </div>

</div>

It seems that the content in the second container is aligning incorrectly. Despite making changes to the "#second" code, the containers are still not side by side as intended. Can someone help me figure out why this is happening?

Answer №1

It appears that a single line is absent. The elements are not floated correctly. Consider including float: left; to #second.

Experiment with it on JSFiddle. I have already implemented the modification for you. Does this achieve what you had in mind? https://jsfiddle.net/jr0gpaqg/

Answer №2

Do you think this solution will be effective for your needs?

Check out this code snippet on JSFiddle

#second {
  background: #fff;
  position:relative;
    display:inline-block;
    float:left;
 margin-left:auto;
  margin-right:auto;
  width: 67%;
  height: 1500px;

   -webkit-flex: 1 6 20%;
           flex: 1 6 20%;
   -webkit-order: 3;
           order: 3;
}

Answer №3

In response to your query...make a modification.

#third {
  background: #f00;
  position:relative;
  display:inline-block;
  width: 30%;
  margin-left:auto;
  margin-right:auto;
  height: 500px;
  -webkit-flex: 1 6 20%;
       flex: 1 6 20%;
  -webkit-order: 3;
       order: 3;
}

Change it to the following...

#third {
    background: #f00;
    position:absolute;
    display:inline-block;
    width: 30%;
    margin-left:auto;
    margin-right:auto;
    height: 500px;
    -webkit-flex: 1 6 20%;
    flex: 1 6 20%;
    -webkit-order: 3;
    order: 3;
}

The issue was with the positioning.

Here is the jsfiddle link for reference.

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

Transform the appearance of a button when focused by utilizing CSS exclusively or altering it dynamically

As a newcomer to coding, I am currently working on a project that involves changing the color of buttons when they are clicked. Specifically, I want it so that when one button is clicked, its color changes, and when another button next to it is clicked, th ...

Shifting the position of an HTML page to one direction

I'm currently working on adding a sidebar to my Twitter Bootstrap 3 project. The goal is to have a fixed positioned nav nav-pills nav-stacked show up on the left side of the page when a button is clicked. I've set its z-index to 1000 so it appear ...

Is it possible to invoke this PHP function within an HTML document?

I'm in the process of developing a social networking platform that allows users to receive notifications when someone follows or unfollows them. The purchased plugin includes a function for notifying users about the number of notifications they have. ...

What steps should I take to eliminate the white gap between the paragraph and the footer on my webpage?

If you're new to html and css, feel free to check out the url [file:///Users/CatherineDu/百度云同步盘/practice/about.html]. I'm currently working on building a simple website and facing an issue - there are unwanted white spaces between the ...

Unable to load circles on page refresh with amCharts Maps

I am experiencing an issue with the functionality of my amCharts maps. Whenever I refresh the page, the circles that are supposed to be displayed disappear. However, when I zoom in, the circles reappear. This problem has me puzzled, and I'm not sure ...

Choosing several buttons in typescript is a skill that every programmer must possess

I need help with selecting multiple buttons in TypeScript. The code I tried doesn't seem to be working, so how can I achieve this? var input = document.getElementById('input'); var result = document.getElementById('result'); v ...

Attaching a CSS file to a personalized WordPress widget

After much searching and struggling due to language barriers or lack of PHP knowledge, I couldn't figure out how to achieve this: public function widget( $args, $instance ) { ?> <div style="padding: 0 0 14% 0"> <div class="m ...

The art of CSS Absolute Positioning and the Science of Body Sc

I'm trying to position an absolute div in the bottom right corner of a page. .absolute{ position: absolute; right:0; bottom: 0; } While this code works, I've noticed that when scrolling the page, the right/bottom position is relative t ...

Switching between dark and light mode in Ant Design

I have successfully implemented dark mode toggling in my application. However, when I try to switch back to light mode, the CSS does not seem to be reloading properly. Below is the code snippet: //ThemeContext.jsx const DarkTheme = lazy(() => import(". ...

What is the best way to eliminate the alert message "autoprefixer: Greetings, time traveler. We are now in the era of CSS without prefixes" in Angular 11?

I am currently working with Angular version 11 and I have encountered a warning message that states: Module Warning (from ./node_modules/postcss-loader/dist/cjs.js): Warning "autoprefixer: Greetings, time traveler. We are now in the era of prefix-le ...

Change the appearance of a div based on the presence of a certain class within a child div using jQuery styling techniques

I'm trying to set a default padding of 15px for div.content, but if it contains a child div.products-list, I want the padding to be removed. I've looked into solutions using jquery, but nothing seems to work. Here's how my layout is structur ...

Ensure that the Popover vanishes upon scrolling the page - Material UI (MUI) v5 compatibility with React

When implementing the MUI v5 standard pattern for displaying a popover upon hovering over another element, everything works smoothly except for one scenario: If you hover over the element And without moving the mouse, use the scroll wheel to scroll throug ...

Incorporating a YouTube video

Having trouble integrating a YouTube video that won't play automatically on your website? The video is visible, but just doesn't start playing on its own. What could be causing this issue? Appreciate any help you can provide! ...

Enhance the spacing between the UL-LI navigation menu and the currently selected item

I'm struggling with adjusting the spacing between items in my navigation menu, specifically the li elements that are currently too close together. I've attempted to increase the margin-left within the .main_menu li CSS rule, but it doesn't s ...

What is the best way to ensure that my drop-down menu items match the size of the parent nav bar?

I'm having trouble creating a dropdown menu using only CSS. Specifically, I am struggling to ensure that the dropdown menu is the same size (width and height) as its parent element. Here is a link to a working example: HERE This is the snippet of HT ...

What is the correct way to implement checkbox validations using jQuery?

I have a total of 3 checkboxes that I would like to arrange in a particular order based on their checks. Currently, when one checkbox is selected for download, the logic I have implemented only considers the first checkbox and ignores the rest. I am look ...

CSS - Ensuring the second line of text in ul/ol li does not extend further left than the first line

My website features several lists that have this format: > lorem ipsum I am trying to style them like this: > lorem ipsum If anyone can provide guidance on how to rephrase the question I am asking, I would greatly ap ...

Using only python, launch a local html file on localhost

Currently, I am executing a code on a remote server that periodically creates an "status" HTML file (similar to TensorBoard) and saves it in a directory on the server. To check the status, I download this HTML file whenever needed. However, if I could use ...

Leveraging Spotify's webAPI to listen to a randomly selected album by a specific artist (ID

Welcome to my little project! As I am not a developer myself, please bear with me for any silly questions that may arise. My idea is to create an "audio book machine." The concept involves using a website that showcases various artists of audiobooks. Upo ...

Steps for retrieving the attribute values of <i> tags enclosed within a designated <div> element

Currently, I am extracting data from a website where I encounter a recurring pattern with a varying number of values. For example, an instance of this pattern is shown below: <div class="lang"> <i class="flag fr" qtip-tooltip= ...