What is causing these divs to shift apart instead of staying next to each other when the browser window is resized?

I am facing an issue with two of my divs not staying next to each other when resizing the browser window. They align perfectly when the window is wide, but as soon as I resize it to a narrower resolution, the right div moves below the left one: http://jsfiddle.net/za5X7/

My goal is to have #sitelatestposts occupy 55% of the width space and let #siteinfos take up the remaining percentage.

<div class="homepagediv">
    <div class="panel-grid-cell" id="sitelatestposts">
            <h1 class="blogtitle">Recent posts</h1>
            <ul>
                <li><a href=#><h5>Title 1</h5><p>Lorem ipsum</p></a></li>
                <li><a href=#><h5>Title 2</h5><p>Lorem ipsum</p></a></li>
                <li><a href=#><h5>Title 3</h5><p>Lorem ipsum</p></a></li>
            </ul>
    </div>
    <div class="panel-grid-cell" id="siteinfos">
            <h1>About the author</h1>

        <p>Contact 555-215-5548</p>
        <p>Lorem ipsum</p>

    </div>
</div>

CSS:

.homepagediv {
    zoom: 1;
   width: 100%;
}
.homepagediv h1, .homepagediv h2, .homepagediv h3, .homepagediv h4, .homepagediv h5, .homepagediv h6 {
    clear: none;
}
.panel-grid-cell {
    margin: 0 auto;
    padding: 0;
    float: left;
}
.blogtitle {
    padding: 0 0 0 10px;
    margin:0.5em 0 22px 0;
}
#sitelatestposts {
    width: 55%;
}
#sitelatestposts ul {
    padding: 0;
    list-style-type: none;
}
#sitelatestposts h5 {
    font-size: 14px;
}
#siteinfos {
    margin-right:10px;
}

If you have any suggestions on how to resolve this issue, please share! Thank you!

Answer №1

To make it work, just set the width of #siteinfos.

For example, if you set #sitelatestposts to 55%, then set #siteinfos to 35% (adding up to 90% together).

By doing this, you can maintain your margin-right.

However, setting #siteinfos to 45% AND keeping the margin-right will exceed 100% (100% + 10px), causing them not to be displayed side by side.

Answer №2

Include

width:35%;

in the styling for #siteinfos{}

This should make the total width equal to 100% (with 55% allocated to #sitelatestposts)

http://example.com

Answer №3

After eliminating the margin-right of #siteinfos, I adjusted the width to 45%.

#siteinfos {
width:45%;
margin-right:0; }

The margin-right could potentially create a line break, and since it is a float:left; element, there is no need for a margin-right. If necessary, consider applying padding-right to the elements inside that div to maintain the correct size and alignment.

EDIT: VIEW FIDDLE HERE

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 reason for the lack of auto complete functionality in this specific Bootstrap example remains unclear

I've been attempting to implement an auto-complete dropdown feature with dynamic data, but I'm facing an issue where no suggestions are displayed in the dropdown. I found this example on Datalists: https://getbootstrap.com/docs/5.1/forms/form-con ...

The strategy of magnifying and shrinking graphs on Google Finance for better analysis and

I am seeking to understand the logic behind a zoom-able graph similar to the one on Google Finance. I am aware that there are pre-made components available, but I am interested in a simple example that breaks down the underlying logic. ...

JavaScript isn't functioning properly after UserControl is loaded via Ajax

Thank you, Stilgar for helping me solve my issue. I created a javascript file and placed all my code in it. After adding this file to the UserControl and retrieving the UserControl's html, I used $("#DivID").html(UserControlHTML). Now everything is wo ...

Tips for storing the output of a script URL in a JavaScript variable

I am currently facing an issue with running a script in the 'head' element of a webpage. The script makes an API call to a specific URL and retrieves results in the form of a JavaScript array. However, I am encountering difficulty because the API ...

The width of the Div element is not following the specified dimensions, and it also has an unspecified margin

Check out my code snippet at: http://jsfiddle.net/8z4aw/ I'm trying to create a table-like layout using div elements, but for some reason the browser is not respecting the specified widths and seems to be adding an unwanted right margin. Where is thi ...

Completing two tasks with a single form submission and a single button press

I'm currently working on a script that inserts data into a database using a form. I'm trying to figure out how to trigger another action in a different section after the insertion. Any insights or tips would be greatly appreciated! ...

What steps do I need to take in order to integrate an mpg video onto my

I am in need of embedding mpg (dvd compliant mpeg2) movie files onto my webpage. Unfortunately, I do not have the ability to convert these videos into any other format. This webpage is solely for personal use, so any solution would be greatly appreciated. ...

Tips for synchronizing JavaScript rendering time with Python requests?

My goal is to retrieve the HTML content of a JavaScript-generated website so that I can extract information using BeautifulSoup. However, when I attempt to request the HTML, the data I receive is from before the page fully loads. Below is the code snippet ...

HTML code for an admin login form

Looking for a way to create a login form without PHP in HTML for an administrator account, so the admin information remains secure and cannot be easily accessed from a database. Any suggestions or tips on how to achieve this? ...

What is the most effective method to extract an ID from a URL that is written in various formats?

Does anyone know of a reliable method to extract an ID from various URL formats using javascript or jquery? https://plus.google.com/115025207826515678661/posts https://plus.google.com/115025207826515678661/ https://plus.google.com/115025207826515678661 ht ...

CSS: Creating a block that stretches the entire width of its parent block

I've been facing the same issue multiple times. Whenever I use the float property to display one block, the next block ends up overlapping with the first one. For example: Consider the following block of code: .row_item{ width: 30%; display: block; ...

Upon selecting multiple checkboxes, corresponding form fields will be displayed based on shared attributes

When multiple checkboxes are selected by the user, corresponding form fields should appear based on the checkboxes. For example, if both flight and hotel checkboxes are checked, then the full name and last name fields should be displayed while other fields ...

After refreshing, a blank page appears when using the HTML POST method

After conducting a test using an HTML form with the POST method, I encountered an unexpected outcome. The setup involved two HTML pages hosted on an Apache server (with PHP already installed): post.html and target.html. Below are the code snippets for thes ...

iOS does not support Css3 Transition

My Transition Code works on PC and android devices, but it does not work on iOS devices. I am only using HTML and CSS. /***** BOX 3 *****/ #box3 { height:240px; width:198px; border:1px solid #dedede; background-color:#fcfcfc; position:relative; overflow:h ...

Expanding the padding within a box results in an increase in the overall height of the table row that encapsulates it

My goal is to create a table displaying marks with a box around each mark that expands slightly when hovered over to indicate activity. Below is the code I am using: .container { position: absolute; width: 80%; left: 50%; transform: translateX(-5 ...

Issue arises when applying both overflow-x:scroll and justify-content:center

Encountering a problem with using overflow-x: scroll and justify-content: center on a flex parent container. Here is my code snippet: The issue: the first flex child item is not visible as it is cropped on the left side. Please refer to the screenshot and ...

Craft a unique parallax effect using Framer Motion's clipping feature

To help visualize my concept, I have sketched it out using Figma. This idea involves a slide transitioning between pages. The goal is to cover the entire page with a sliding effect, and then place a sticker (dubbed the Parallax Box) on top of it. However ...

Bottom div refuses to adhere to the bottom of the page

I need help with creating a footer div that sticks to the bottom, left, and right of the page. The current footer doesn't extend all the way down and left. How can I resolve this without using "position: fixed;"? Below is the code snippet (I have rep ...

Learn how to extract JSON information from a URL and integrate it into either a table or dropdown in Vue.js

Looking to retrieve a JSON data array from a URL and utilize it to populate either a table or dropdown with Vue.js and Axios. Here is the link where I intend to fetch the data. Any advice on how to accomplish this? https://jsonplaceholder.typicode.com/us ...

Background with funky Font Awesome colors

Font Awesome is working perfectly for me, but I'm experiencing an issue with strange borders appearing around the icons in Chrome. Interestingly, this problem doesn't occur in IE and Firefox browsers. What's even more peculiar is that the bo ...