Tips on preventing the constant shifting of my webpage div elements when resizing the browser

Whenever I resize my webpage browser, the 3 text input boxes move and overlap, causing the page layout to become messy.

View of The Browser in full screen (normal)

View of The Browser when it's smaller (not normal)

As a beginner programmer, I have attempted solutions from various other sources, but the issue persists.

The h2 element remains unaffected when resizing the browser.

Apologies for the lengthy code snippet included below.

<!DOCTYPE html>

<html>

<style>

#image
{
position: fixed;
left: 50px;
top: 200px;
}

#cSolve
{
position: fixed;
right: 650px;
top: 150px;
}

#bSolve
{
position: fixed;
right: 800px;
top: 350px;
}

#aSolve
{
position: fixed;
right: 500px;
top: 350px;
}

h2
{
text-align: center;
}

</style>

<div id = "image">
    <img src = "i could not put my link here on stackoverflow" width = "350">
</div>
<br> <br>

<div id = "cSolve">
<p> Solve For C: </p>
  A length: <input type="number" name="ac" id="ac"><br> <br>
  B length: <input type="number" name="bc" id="bc"><br> <br>
  Round to 2 decimal places<input type="checkbox" class="checkboxC"/><br> <br>
 <buttononclick="solveForC(document.getElementById('ac').value,document.getElementById('bc').value)"
 >Solve</>
</div>

<br><br>

<div id = "bSolve">
<p> Solve For B: </p>
C length: <input type="number" name="cb" id="cb"><br> <br>
A length: <input type="number" name="ab" id="ab"><br> <br>
Round to 2 decimal places<input type="checkbox" class="checkboxB"/><br> <br>
<button onclick="solveForB(document.getElementById('cb').value,document.getElementById('ab').value)"
>Solve</button>
</div>
<br><br>

<div id = "aSolve">
<p> Solve For A: </p>
C length: <input type="number" name="ca" id="ca"><br> <br>
A length: <input type="number" name="ba" id="ba"><br> <br>
Round to 2 decimal places<input type="checkbox" class="checkboxA"/><br> <br>
<button onclick="solveForA(document.getElementById('ca').value,document.getElementById('ba').value)"
>Solve</button>
</div>
</body>

Answer №1

This code utilizes only bootstrap classes, eliminating the need for any additional CSS. To make it responsive, simply insert your image path in the img tag.

<!DOCTYPE html>

<html>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<br><br>

<center><h1>Pythagoras Theorem Calculator</h1></center>
<br><br>
<br><br>

<div class="col-lg-12 col-md-12 row">
<div class="col-md-3">
   <img src="img.png" class="img-responsive" style="height:200px !important; width:100%;">
</div>
<div class="col-md-6 col-sm-12">
<center>
<p> Solve For C: </p>
  A length: <input type="number" name="ac" id="ac"><br> <br>
  B length: <input type="number" name="bc" id="bc"><br> <br>
  Round to 2 decimal places<input type="checkbox" class="checkboxC"/><br> <br>
 <button onclick="solveForC(document.getElementById('ac').value,document.getElementById('bc').value)">Solve</button>
</center>
</div>
</div>
<div class="col-lg-12 col-md-12">
<div class="col-lg-6 col-md-6 col-sm-12"><center>
<p> Solve For B: </p>
C length: <input type="number" name="cb" id="cb"><br> <br>
A length: <input type="number" name="ab" id="ab"><br> <br>
Round to 2 decimal places<input type="checkbox" class="checkboxB"/><br> <br>
<button onclick="solveForB(document.getElementById('cb').value,document.getElementById('ab').value)"
>Solve</button>

</center></div>
<div class="col-lg-6 col-md-6 col-sm-12"><center>
<p> Solve For A: </p>
C length: <input type="number" name="ca" id="ca"><br> <br>
A length: <input type="number" name="ba" id="ba"><br> <br>
Round to 2 decimal places<input type="checkbox" class="checkboxA"/><br> <br>
<button onclick="solveForA(document.getElementById('ca').value,document.getElementById('ba').value)"
>Solve</button>

</center></div>
</div>

</body>

Answer №2

To create a more responsive design, consider utilizing Bootstrap for your project. Alternatively, if you prefer working with pure CSS, Flexbox is a great option that allows you to achieve a similar layout as Bootstrap.

Based on the code provided, some adjustments may be needed to ensure responsiveness, especially when resizing the screen to extremes. Explore CSS properties such as vh (viewport height), vw (viewport width), and percentages. These properties can help you achieve a responsive design by adapting to various screen sizes effectively.

The code snippet below is tailored to your existing code. Feel free to experiment with different values and additional properties to fine-tune the design according to your requirements:

* {
    margin: 0;
    padding: 0;
}
#container {
    position: relative;
    height: 100vh;
    width: 100vw;
}
#img {
    float: left;
    margin: 10vh 10vw;
    padding: 5px;
    height: 20vh;
    width: auto;
}
#cSolve {
    position: absolute;
    right: 33%;
    top: 66%;
    height: 33vh;
    width: 25vw;
}
#bSolve {
    position: absolute;
    right: 66%;
    top: 66%;
    height: 33vh;
    width: 25vw;
}
#aSolve {
    position: absolute;
    right: 50%;
    top: 25%;
    height: 33vh;
    width: 25vw;
}
h2 {
    text-align: center;
}
<!DOCTYPE html>
<html>
   <head>
       <title>Some Title</title>
   </head>
   <body>
       <div id="container">
           <div id ="image">
               <img id="img" src="path/to/image.png" alt="theorem" width = "350">
           </div>
           <div id="cSolve">
               <p> Solve For C:</p>
               A legnth: <input type="number" name="ac" id="ac"><br><br>
               B legnth: <input type="number" name="bc" id="bc"><br><br>
               Round to 2 decimal places<input type="checkbox" class="checkboxC"/><br><br>
               <button onclick="solveForC(document.getElementById('ac').value,document.getElementById('bc').value)">Solve</button>
            </div>
            <div id="bSolve">
                <p> Solve For B: </p>
                C legnth: <input type="number" name="cb" id="cb"><br><br>
                A legnth: <input type="number" name="ab" id="ab"><br><br>
                Round to 2 decimal places<input type="checkbox" class="checkboxB"/><br><br>
                <button onclick="solveForB(document.getElementById('cb').value,document.getElementById('ab').value)">Solve</button>
            </div>
            <div id="aSolve">
                <p> Solve For A:</p>
                C legnth: <input type="number" name="ca" id="ca"><br><br>                     A legnth: <input type="number" name="ba" id="ba"><br><br>
                Round to 2 decimal places<input type="checkbox" class="checkboxA"/><br><br>
                <button onclick="solveForA(document.getElementById('ca').value,document.getElementById('ba').value)">Solve</button>
            </div>
        </div>
    </body>
</html>

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

Load the data from amp-list after triggering an event

I am currently exploring ways to load data on my second amp-list only after the first one has a selected value. Additionally, I am struggling to display a placeholder for the second amp-list. <div class="row"> <div class="col-sm-4 position-in ...

How can I adjust the height of the carousel slider to fit the course section perfectly?

I am currently working on a new website that includes a carousel slider in one of its sections. I am trying to figure out how to make the slider fit within that section while still maintaining responsiveness. Any suggestions on how to achieve this? I am u ...

Avoiding HTML code within XML

I'm currently experiencing an issue with an invalid XML character appearing during interaction with a SOAP web service. When sending a formatted HTML message to a specific web service, I encountered a failed message that read as follows: Fault messa ...

Alter the class following modifications to the list

https://i.stack.imgur.com/QZob0.pngIn my dual list, the data is displayed in a ul li format fetched from a JSON file. Users can move items between the two lists. However, I am facing an issue where I want to apply a property that only displays content with ...

What is the best way to add an active class to a clicked menu item that already has a class

I have menu items on the master page, and if users click on that menu item, I want to show it as active. My goal is to append "Active" to the existing class to indicate that it is active. _Layout.cshtml: <div class="menu-items-navigation"> <di ...

Tips for adjusting the border-bottom line in real-time as text is selected from a dropdown menu

$('#select').on('change', function() { name = $('#select :selected').val(); //some code here }); . bdr-txtline { border-bottom: 1px solid black; } <div class="container"> <div class="row"> <div ...

Tips for creating an element that maintains its dimensions when a border is added during a hover effect

One issue I often face is the desire to add a border to an element on hover, only to find that as the border appears, the element's height and width change, causing it to visually jump and potentially push other elements. Is there a solution for this ...

Create a scrollable horizontal list of items

I am encountering an issue with my mat chip list in Angular Material. I have a mat chip list filled with mat-chips that I want to display in a single row. If there are more items than can fit on the screen, I would like the area to be scrollable horizonta ...

Tips for displaying a div near the cursor's location when hovering in React JS

Looking for a way to show a hidden div at cursor position when hovering on Text item1 or item2. Check out the sample GIF animation in this Link My attempt using Jquery code inside React resulted in an error: $(".text-item").mouseenter(function ( ...

Switch the navbar background color from see-through to black

On my website, I have set up a navbar navigation that transitions between a transparent background and a black background as the user scrolls down. However, I would like the black background to be present at all times for the navbar. I built the website us ...

What is the best way to eliminate unexplained spacing at the bottom of a webpage using CSS?

I am struggling to create a basic webpage using Bootstrap and D3, and I can't seem to figure out how to remove the excess whitespace at the bottom. Any tips on how to resolve this issue would be greatly appreciated. I attempted to set the min-height ...

What is the best way to align a container in the middle of the page without positioning the text in the center

Query 1: What is the best way to horizontally center the container div while keeping Typography aligned to the left? Expected outcome: https://i.stack.imgur.com/yKCZF.jpg Query 2: How can a component be positioned below the AppBar without relying on mar ...

Erase jQuery from the text

I am struggling with splitting or removing text from a filename. For example, if I have filenames like: 200726100_50-0002.JPG 230514008_60-0001.JPG The desired result should be: 230514008_60.JPG 200726100_50.JPG Am I not using the split function cor ...

What steps should be taken to switch a class from one li element to another and remove it in the process?

As I develop the navigation bar for my website, I am faced with a challenge. I want to create a button-like behavior where clicking on an li element triggers a drop-down section underneath it without using the # attribute to prevent jumping to the top of t ...

Ways to conceal or deactivate button controls on videojs?

I am building an application using video.js and Vue. I am looking for a way to hide or disable certain controls like the play button, playback rate, and make the progress bar read-only. In the video.js documentation, I found that using controls: false hi ...

An alternative to Firebug for Internet Explorer

Can anyone suggest a suitable replacement for Firebug that is compatible with IE 7 and 8? I need a tool that allows me to edit CSS/HTML in real-time, debug JavaScript code, and visualize the positions of elements on web pages. Appreciate any recommendati ...

Ways to verify the content within two separate p elements

<p> expanded state:</p> <P> true </p> Merging the text from both tags into a single output. Final Output: expanded state: true ...

The process of setting up a carousel for tables using jQuery

I can successfully implement jquery for an image carousel, but now I need to find a way to create a sliding table format. Any assistance on this matter would be greatly appreciated. Here is the code I currently have: <ul> <li><a style= ...

What could be causing my video not to display a thumbnail on mobile devices until it is played?

When I view my website on mobile devices, there is no background image displayed before playing a video. Below is the HTML code I am using: <div class="row " > <div class="col-12 text-center"> <video control ...

Eliminate the Material Stepper heading

Is there a way to remove the header navigation from the material stepper? I've tried using the following CSS code without success: .mat-horizontal-stepper-header-container{display: none} You can view the stepper on Stackblitz by clicking this link: ...