Elements not following percentage in top positioning

I am facing an issue with resizing containers on my webpage. Despite using position: relative for everything, I am unable to properly adjust the size of the top containers using percentages. Any assistance would be greatly appreciated!

                 position:relative;
                 height:100%;
                 width:100%
               }
               .picturebox {
                 position: relative;
                 border: solid white 1px;
                 min-width: 25%;
                 max-width: 25%;
                 height: 100%;
                 top: -350px;
               }
               .servicepic {
                 position: relative;
                 width: 100%;
                 top: 30%;
                 padding: 2%;
                 -webkit-box-sizing: border-box;
                 -moz-box-sizing: border-box;
                 box-sizing: border-box;
               }
               .middlecontainer {
                 position: relative;
                 border: solid white 1px;
                 min-width: 60%;
                 max-width: 60%;
                 top: 500%;
                 left: 25.1%;
               }
               .rightcontainer {
                 position: relative;
                 border: solid white 1px;
                 min-width: 14.75%;
                 max-width: 14.75%;
                 height: 100%;
                 top: -629px;
                 left: 85.2%;
<html>

<body>
  <div class="bigbox">
    <div class="container">
      <div class="title">
        <h1>Codes' Decoding</h1>
        <br>
        <h2 id="slogan">"Providing all of your web design needs"</h2> 
      </div>
    </div>
    <div id="buttoncontainer">
      <a href="file:///C:/Users/Cody/Desktop/Websites/Practice.html">
        <div class="breadcrumb1">
          <p>Home</p>
        </div>
      </a>
      <a href="breadcrumb2">
        <div class="breadcrumb2">
          <p>Stuff</p>
        </div>
      </a>
      <a href="breadcrumb3">
        <div class="breadcrumb3">
          <p>Stuff</p>
        </div>
      </a>
      <a href="breadcrumb4">
        <div class="breadcrumb4">
          <p>Stuff</p>
        </div>
      </a>
    </div>
    <div class="lightestl">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="nextlightestl">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="nextdarkestl">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="darkestl">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="lightestr">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="nextlightestr">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="nextdarkestr">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="darkestr">
      <p>
        <br>
        <br>
      </p>
    </div>
    <div class="giantbox">
      <div class="picturebox">
        <img class="servicepic" src="http://exportbaltic.com/sites/default/files/styles/gallery_large_640/public/product-images/Export-Baltic.jpeg?itok=Cs0mNaSk">
      </div>
      <div class="middlecontainer">
        <p>hello</p>
      </div>
      <div class="rightcontainer">
        <p>hello</p>
      </div>
    </div>
  </div>
</body>

</html>

Answer №1

To achieve the desired output shown in this Fiddle demonstration, I made adjustments by switching the CSS property from position: relative; to position: absolute; on the specific divs. I then set individual positions for each div using top: 0;, adjusting the width: %; according to the required widths of the divs so that they collectively add up to 100%. I also eliminated margins to ensure a seamless fit and utilized left: %; where % represents the percentage of page occupied by divs to the left.

However, it's important to note that this method lacks flexibility. For more dynamic results, utilizing a framework like Bootstrap would be highly recommended.

Answer №2

It is important to note that the current approach being taken by my friend is not considered best practice.

Consider using image or gradient CSS instead of:

<div class="lightestl"><p><br><br></p></div>
<div class="nextlightestl"><p><br><br></p></div>
<div class="nextdarkestl"><p><br><br></p></div>
<div class="darkestl"><p><br><br></p></div>
<div class="lightestr"><p><br><br></p></div>
<div class="nextlightestr"><p><br><br></p></div>
<div class="nextdarkestr"><p><br><br></p></div>
<div class="darkestr"><p><br><br></p></div>

Avoid using position relative for everything as it is not an optimal solution.

To ensure three containers align with the same size, consider utilizing flexbox. Learn more about flexbox here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

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

Ways to eliminate the leading bullet point from an unordered list

I am currently working on creating a gallery of images using php and css. The images are placed in an unordered list as shown below: <ul style="list-style-type:none;"> <? while($data=mysql_fetch_row($result)) { $pic=$data[2]; if ($pic) { $ ...

Python Selenium error: NoSuchElementException - Unable to find the specified element

Coding Journey: With limited coding knowledge, I've attempted to learn through various resources without much success. Now, I'm taking a different approach by working on a project idea directly. The goal is to create a program that interacts wi ...

What is the best way to fill in predetermined HTML with information using jQuery?

Currently, I am working with several ajax forms that allow me to add rows of data dynamically using ajax. While the form submission is functioning correctly, I am having trouble figuring out the best way to append the newly inserted data into the database. ...

Issue with JavaScript not executing upon clicking the submit button on a form within the Wordpress admin page

In the admin pages of my Wordpress installation, I have created an HTML form. My goal is to validate the data inputted when the submit button is pressed using a Javascript function. If the data is not correctly inserted, I want alerts to be displayed. Desp ...

Guide to creating HTML file with SSI tags

Currently, my website uses Nginx SSI tags to dynamically include template files such as the header, footer, and sidebar. However, I need to provide the final HTML output to clients instead of running it on their browsers. The issue I'm facing is that ...

Tips for postponing the execution of inline javascript

Main page <script> $.ajax({ type: 'GET', url: 'ajax.php', context: document.body, success: function(data) { $("#content").html(data); } }); </script> <div id="content"></div> Ajax ...

What steps can be taken to stop 'type-hacking'?

Imagine owning a popular social media platform and wanting to integrate an iframe for user signups through third-party sites, similar to Facebook's 'like this' iframes. However, you are concerned about the security risks associated with ifra ...

Troubleshooting CSS Code Issues on Myspace

Greetings! I am currently working on enhancing a friend's profile on myspace.com. I have two divs on each side of the screen that I want to align next to each other. I have tried using float: left; and float: right;, as well as experimenting with marg ...

Is it possible to reset a form without using JavaScript? (The input type=reset function is not functioning correctly

So, basically I need a quick way to clear all the fields in my form. I've experimented with a couple of options: <input type="reset" value="Clear all fields"> And <button type="reset">Clear all fields</button> Unfortunately, none ...

What is the best way to position a div at the bottom of the main div?

How can I position a div with the class "boxLinks" at the bottom of the main box with the class "main-box"? Here's my idea: The main class has a width of 1200px; within this main class, there are 5 divs with each div having a width of 25%. .main- ...

Incorporating a technique for aligning text towards the right as the number of characters or digits expands

I'm designing a game user interface with a money indicator. Let's imagine the player has 0 dollars in their wallet, it should appear like this: https://i.stack.imgur.com/35eoh.png Please note that it is located in the upper right corner. The p ...

Make the minimum height of one div equal to the height of another div

My query is somewhat similar to this discussion: Implementing a dynamic min-height on a div using JavaScript but with a slight twist. I am working on a dropdown menu within a WordPress site, integrated with RoyalSlider. The height of the slider div adjust ...

The align-content property in CSS Flex does not function properly when used alongside an inline height declaration

I encountered an issue with the CSS Flex property align-content. It seems to not work properly in a container where the height is declared inline. However, once I move the inline height declaration to a separate CSS class, everything works fine. Both Chrom ...

Ways to adjust image placement and size post-rotation with CSS/JS to ensure it stays within the containing div and avoids being cut off

Check out this jsfiddle I've been experimenting with. The jsfiddle is designed to rotate an image by 90 degrees in either clockwise or anti-clockwise direction upon button click. However, the rotated image currently appears outside of its parent div. ...

Create a dynamic feature on a JSP page that allows users to click a button and instantly see changes

How can I create a button on an HTML or JSP page that, when clicked, will dynamically add content to the same page? For example, imagine I have a JSP page called Prescription.jsp with input forms like: ID name select commodity weight tolerance ...

Floating action button within a collapsible panel

I am having trouble placing a fixed-action-btn inside a collapsible body. It keeps appearing in the bottom right corner of the page instead of within the collapsible itself. How can I ensure that the button stays inside the body? Check out this link for r ...

The reload button retains functionality while being present within an Angular2 form, allowing for a seamless user experience. The

After some observation, I have realized that when a button is placed inside a form but has no connection or function related to the form, such as a back or cancel button, it unexpectedly reloads the entire page. For instance, let's consider having ...

Different ways to swap table cells using only CSS

Does anyone know how to switch the positions of table cells using only CSS? I have three divs set up like this: #content { width: 1000px; display: table; float: none; vertical-align: top; border: 1px solid red; } #left { float: left; } #ri ...

The W3C Validator has found a discrepancy in the index.html file, specifically at the app-root location

While attempting to validate my HTML page, I encountered the following error: Error: Element app-root not allowed as child of element body in this context. (Suppressing further errors from this subtree.) From line 4347, column 7; to line 4347, column 16 ...

Extracting precise information from HTML documents

Looking to extract specific data from an HTML file using C# and HtmlAgilityPack. Here is a snippet of the HTML: <p class="heading"><span>Greeting!</span> <p class='verse'>Hi!<br> // Hello!</p>& ...