Challenges with resizing floating divs

As a beginner in Web Development, I am tasked with creating a web portfolio for an assignment.

In my design layout, I have a navigation bar in a div floated left, and a content div floated right serving as an about me section containing paragraphs and lists.

However, when resizing the browser, the right-hand content div drops below at a certain size. I would like the text within the content div to compress into the div instead of dropping down?

Note that I need to achieve this using HTML/CSS only, as JavaScript solutions will be introduced later in the assignment.

I have replaced all personal info in the paragraphs with similar placeholder text.

If this sounds like a trivial question, please bear with me as my code may seem amateurish since I'm still learning.

Any assistance or guidance on how to keep the text compressed within the content div upon resizing would be greatly appreciated.

Answer №1

Instead of delving into the specifics of your example, the issue arises from mixing percentage widths with pixel padding. To ensure responsiveness when resizing the browser, stick to using percentages exclusively. This same principle applies to border widths; if the element's width is set in percentages, then its borders should be as well - unless specific styles are triggered by CSS media queries at a certain width. The rule also extends to margins: if an element's width is defined in percentages, so too should its margin.

Answer №2

To position the "text text text" div on the right side, add the following CSS to your styles:

#content-container {  display: inline-block; }

If you want to adjust the CSS based on screen size, you can utilize @media queries to set min/max-width and define a variable for display:

@media screen and (max-width: 800px) {
    div { background-color: red;}
}

@media screen and (min-width: 801px) {
    div { background-color: lime;}
}

In the examples above, when the screen width is 800px, the div elements will have a red background color, and if it's higher than that, they will be lime.

Essentially, you can use this technique to stack divs on top of each other or arrange them in any desired order. I believe this approach could be beneficial for your layout.

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

Having several contact forms embedded within a single webpage

I am currently in the process of developing a prototype website and my objective is to have multiple forms on a single page. My goal is to have a form for each service, where users can click on the service and fill out a form to request a quote. The first ...

Automatically activate the next tab in Bootstrap

I have a modal that performs a count. Once the count is completed, the modal closes. My goal is to automatically switch to the next tab in Bootstrap when the modal closes. Here is the HTML: <ul class="nav nav-tabs namelocationtable"> <div clas ...

Issue with table cell resizing improperly with scrollable pre content

I'm facing a challenge with resizing my table cell correctly within a variation of the "holy grail" layout. The behavior differs when displaying my main content as a block versus a table-cell. The issue seems to stem from having a scrollable pre bloc ...

Unable to retrieve data from Flask for AJAX request

When making an AJAX call to a Flask function to retrieve data using a token, the code looks like this: @app.route("/questgen/results", methods = ['POST', 'GET']) def fetch_results(): token = request.form.get('token&a ...

Utilizing the powerful combination of TailwindCSS and Next.js Image to achieve a full height display with

Trying to utilize the Next.js' <Image> component with the layout=fill setting, I created a relative div housing the Image tag. However, I am looking for a way to set the height based on the Image's height. Came across this example, but the ...

Javascript menu toggle malfunctioning with sub-menus

I am in the process of creating a responsive menu for a complex website. The horizontal menu transitions into a vertical layout on smaller screens, with javascript used to toggle the sub-menu items open and closed when clicked. One issue I am facing is wit ...

Issue with exchanging columns in Bootstrap version 5.0

Seeking assistance! I am a beginner with bootstrap and struggling to figure out an issue I'm experiencing. In the attached image(s), my goal is to have the coin image positioned above its corresponding text on the left side when the screen size is red ...

Tips for showing a value in a disabled text input box

When users access the page, the table should appear as follows: Marks Per Answer Total Marks Marks Remaining (blank text input) 4 4 (blank text inp ...

Guide to attaching a mouse click event listener to a child element within a Polymer custom component

I'm currently facing an issue where I am attempting to attach a click listener to one of the buttons within a custom element during the "created" life cycle callback (even attempted using the "ready" callback with the same outcome). Unfortunately, I ...

The Php Include function is known to create unnecessary whitespace and disregard any specified styles

On one of my web pages, I am using the include() function to bring in content from another page. This external page contains both HTML and PHP code, with echoes for output. Here's an example: The page Apple.php looks like this: <html> <head ...

Stop using Flexbox in Material UI on small screens

How can I prevent Flexbox from functioning on small screens using Material UI? I am looking for something similar to the d-md-flex class in Bootstrap but for Material UI. In Bootstrap (works as expected) <div class="d-md-flex align-items-md-center ...

Hover your mouse over the menu to activate a timeout feature

Having an issue with my multi-level menu - when I hover over a main menu item, the sub-menu items are supposed to display. However, if I move the mouse too quickly from the main item to the sub-item and it goes off the path, the sub-menu disappears and I h ...

I am attempting to get a jquery plugin to function properly on my Windows 7 Internet Explorer IE7 browser. The plugin in question can be found at http://jvectormap.owl-hollow

I'm encountering some strange issues with my Internet Explorer IE7 browser on Windows 7. The jquery plugin I am attempting to use can be found at . Unfortunately, this plugin is not functioning properly on Internet Explorer IE7 on Windows 7, but it ru ...

Unused sizing attributes in IMG tags

I can't seem to figure out what's going wrong here... I want the image tag to initially display the 250px wide "small" image, and then allow the browser to select the most suitable image using the srcset and sizes attributes - essentially, the " ...

When the window is scrolled to 50%, I would like to load some additional data

Looking to load data when the browser scrollbar reaches 50%... In jQuery, I created the following function: $(window).on('scroll', function () { alert("scrolling"); if ($(window).scrollTop() + $(window).innerHeight() > ...

The background image stubbornly refuses to stretch to the full width of the section container

Looking at my code example and the screenshot provided, it's clear that the image is not fitting into the container even when set to 100% width or utilizing other properties. Below you will see the code snippet: .about-us{ background-image: url(i ...

Images for the background of the table header and sorting icons

Currently, I am utilizing jquery.tablesorter for table sorting functionality. However, I have a desire to apply a pattern to my table headers using a background-image. Unfortunately, when I do so, the .headerSortUp and .headerSortDown classes on the sorted ...

Styling Your PHP Output with Echo

Is there a way to create a compact text box with a scroll bar that can display recurring data generated by PHP activities on the server side? How can I format it in this way? ...

The HTML element failed to be inserted

Currently, I am involved in a project based on .NET Core for my organization. This project entails loading work orders from our SQL database using Entity Framework and then filtering them to display as markers on a map via the Google Maps API for our insta ...

The navigation bar on the website highlights vibrant green arrows next to the

I'm having trouble implementing a bootstrap menu on my website using the code provided by Bootstrap. The menu is not displaying correctly and instead showing small green UL arrows. I have JavaScript and Bootstrap scripts in my project. Is there a way ...