Trouble resizing webpage to fit screen dimensions

My latest project involves creating a business webpage with a two-column layout. I want to showcase an "About Us" section on one side, complete with bullet points below it. Everything looks great when viewing the page in full screen, but as soon as I resize the browser window, the text becomes messy and starts overlapping. I've been using divs, containers, and percentages to position elements, but nothing seems to be working. Any suggestions?

Below is the HTML code:

<div class = "aboutuscontainer"> 
    <div class = "abouthead"><h2>About us:</h2></div>
    <div class = "aboutinfo"><p>Codes' Decoding is an independent web design company that prioritizes customer satisfaction and reliability. Established in 2015, we aim to offer top-notch services directly tailored to our clients for a personalized experience.</p></div>
    <div class = "qualityhead"><h4>Quality:</h4></div> 
    <div class = "qualityinfo"><p>At Codes' Decoding, we guarantee high-quality website designs where your satisfaction is our priority. If you're not satisfied, you don't pay - simple as that!</p></div>
    <br> 
    <div class = "valuehead"><h4>Value:</h4></div> 
    <div class = "valueinfo"><p>By choosing Codes' Decoding, you get the best value in the market. Our independence allows us to set competitive rates while maintaining exceptional service for our esteemed clients.</p></div>  
    <br>  
    <div class = "servicehead"><h4>Service:</h4></div> 
    <div class = "serviceinfo"><p>Our dedicated team at Codes' Decoding ensures a flawless experience for every client. We're always available to address any inquiries, making sure you have a seamless journey during our collaboration.</p></div>
</div> 

And here is the CSS code:

.aboutuscontainer {
    position: relative;
    top: 55px;
    left: 0%;
    border-right: dotted yellow 1px;
    max-width: 51.5%;
    height: 100%;
}

.abouthead {
    position: absolute;
    color: yellow;
}

.aboutinfo {
    position: absolute;
    color: white;
    top: 90%;
    left: 0px;
    line-height: 1.5em;
}

.qualityhead {
    position: absolute;
    color: yellow;
    top: 370%;
    left: 2%;
}

.qualityinfo {
    position: absolute;
    color: white;
    top: 370%;
    left: 13%;
    line-height: 1.5em;  
}

.valuehead {
    position: absolute;
    color: yellow;
    top: 570%;
    left: 2%;
}

.valueinfo {
    position: absolute;
    color: white;
    top: 570%;
    left: 13%;
    line-height: 1.5em;  
}

.servicehead {
    position: absolute;
    color: yellow;
    top: 790%;
    left: 2%;
}

.serviceinfo {
    position: absolute;
    color: white;
    top: 790%;
    left: 13%;
    line-height: 1.5em;  
}

Answer №1

After making numerous changes and suggestions, I felt it was necessary to create a fiddle for you: https://jsfiddle.net/aaenyenq/

Key revisions to the code:

  1. Utilize relative positioning instead of absolute.
  2. Avoid using left/top positioning, allow elements to flow naturally, and incorporate widths.
  3. To achieve desired left/right layout, consider using display: inline-block or float: left (preferably display: inline-block).
  4. Simplify the code by removing unnecessary divs (e.g., around h2 and h4 elements) and utilize container classes along with generic markup.
  5. Eliminate <br> tags; opt for margins/padding for spacing needs.

Revised HTML in a simplified form:

<div class = "aboutuscontainer"> 
    <h2>About us:</h2>
    <div class="aboutinfo"><p>Codes' Decoding is an independent web design company committed to customer satisfaction and website reliability since its establishment in 2015. Our direct interaction with clients ensures a delightful experience.</p></div>
    <div class="listitem">
        <h4>Quality:</h4>
        <div><p>We guarantee superior-quality website designs at Codes' Decoding. If you're not satisfied, there's no charge. Money-back assurance if you don't love your new site!</p></div>
    </div>
    <div class="listitem">
        <h4>Value:</h4>
        <div><p>Expect the best value when working with Codes' Decoding. Our independence allows us to maintain low rates without compromising on quality for our cherished clients.</p></div> 
    </div>
    <div class="listitem">
        <h4>Service:</h4>
        <div><p>Our dedicated team at Codes' Decoding ensures a flawless customer experience. We are on hand to address any queries and provide a seamless journey thanks to our experienced team.</p></div>
    </div>
</div> 

Streamlined CSS styles:

.aboutuscontainer {
    position: relative;
    margin-top: 55px;
    left: 0%;
    border-right: dotted yellow 1px;
    max-width: 51.5%;
    height: 100%;
}

.aboutuscontainer h2 {
    color: yellow;
}

.aboutinfo {
    color: white;
    line-height: 1.5em;
}

.listitem h4 {
    display: inline-block;
    vertical-align: top;
    width: 20%;
    color: yellow;
}

.listitem div {
    display: inline-block;
    vertical-align: top;
    width: 78%;
    color: white;
}

If custom spacing is needed for different sections, simply add a class to the listitem div element and adjust spacing accordingly:

(Using hypothetical class "service" -

<div class="listitem service">
):

.listitem.service h4 {
     width: 25%;
}

.listitem.service div {
     width: 73%;
}

Answer №2

Avoid using position absolute if possible. I have made some adjustments to the CSS for you. I utilized float left and percentages for the width.

Check out the updated CSS here

.qualityhead {
   color: yellow;
   width: 30%;
   float:left;
}

I hope this solution proves helpful for you.

https://i.sstatic.net/J9f5G.png

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

Why are my buttons displaying uneven spacing?

I'm stumped trying to figure out what's causing the strange spacing issue you can see in this image https://i.sstatic.net/11Fj5.png (unfortunately, I can't embed images yet...sorry) https://i.sstatic.net/z0P5Q.png taken from . Here is the ...

Approach the data from various angles, customize the rendering of container components using parameters

Is it considered an antipattern to have a container component return different representation elements based on a condition variable passed to it? For example, I have routes for both the SummaryPageComponent and CustomersPageComponent. The Summary page ha ...

Press the html button and activate the button using Visual Basic

Being new to Visual Basic, I have created a simple app using the WebBrowser component. The web page that loads contains an HTML button. I want this HTML button press to enable a button in Visual Basic, but I don't know how to do it. I have researched ...

displaying data with the use of Ajax in laravel

Querying data from the 'Company' table in the database and receiving it in JSON format, I am now looking to present it in a Data Table. Controller public function fetch(Request $request){ $table = \DB::table('company')-&g ...

If the text is a single line, center it. However, do not center the text if it

Can we center align text horizontally if it occupies a single line, but refrain from center aligning and use white-space: normal when the text spans multiple lines (ideally without the need for JavaScript)? ...

Is it possible to access the HTML <section> tag in the code behind?

I have a website with different sections. The homepage is the main section, and when I click on any link, it takes me to a special section. <section id="homepage" class="page-homepage current-page page"> <a class="nav-link" data-opening-page- ...

What is the best way to add a title at the end of a navigation bar using React?

Recently, I came across a navigation bar code in ReactJS online and decided to style it according to my preferences. Currently, it appears like this: https://i.sstatic.net/BR8QS.png However, I am aiming for it to resemble the following design: https://i ...

issues with the styling and scripts within the jsp document

During my project work, I encountered an issue with the front end as shown in the image below. https://i.sstatic.net/gLIUr.png Upon loading the project, all styles and scripts disappear completely. How can I resolve this issue promptly? I attempted to up ...

Guide to creating a fully clickable Card component with Material UI and React JS

Currently in my React project, I am utilizing Material UI Next. Within this framework, I have implemented the Card component that contains both an image (Card Media) and text (Card Text), with a button located below the text. My inquiry pertains to makin ...

Is it possible to create a webpage that is invisible to users accessing it from a desktop device

Is it possible to create a webpage that is only visible on tablet and mobile devices, while redirecting desktop users somewhere else? I want this page to be hidden from desktop users entirely. ...

Adjusting the position of a stationary element when the page is unresponsive and scrolling

Managing a large web page with extensive JavaScript functionality can be challenging, especially when dealing with fixed position elements that update based on user scroll behavior. A common issue that arises is the noticeable jumping of these elements whe ...

Recommendation for a reliable and user-friendly chat platform without the need for third-party involvement

I am in need of a chat room for a specific group of users on my social network. Ideally, I want a chat feature that is simple and does not require a third party. The chat should automatically use the user's name based on their authorized id when they ...

Is there a way to make those three elements line up in a row side by side?

I'm working on a layout using HTML and CSS that will display two images on the left and right sides of the browser window, with text in between them. I want them all to be horizontally aligned within a container. Here is the code snippet: <div cla ...

Repair the masthead background during overscroll

The Dilemma At the top of my webpage, I have a sleek masthead with a captivating background image that scrolls along with the page. However, there is an issue when users overscroll upwards, causing an undesirable white overflow to appear. To rectify this ...

"Enhance your webpage with a captivating opaque background image using Bootstrap

I'm new to exploring Bootstrap and I am currently experimenting with options for displaying content with a semi-transparent background image. Currently, I am using a "well" but I am open to other suggestions. I have managed to place the image inside t ...

Secure your DOM's href attribute from prying eyes

I have a display page that shows all of our reports in the following format: https://i.sstatic.net/lNzH8.png When hovering over a report, it displays the file's URL (where it is located on our server). I want to prevent users from accessing this inf ...

Using setAttribute will convert the attribute name to lowercase

When creating elements, I use the following code: var l = document.createElement("label");. I then assign attributes with l.setAttribute("formControlName","e");. However, a problem arises where the setAttribute method converts formControlName to lowercase ...

The CSS overflow property does not seem to be functioning properly when applied to a span element that

Here is my current setup: http://jsfiddle.net/YKXUb/1/ My CSS looks like this: .two { height: 100%; width: 100%; border:1px solid green; } .hold { float: left; height: 100%; width: 35%; border:1px solid green; } .right { hei ...

The transition of the element transform between the states of 'relative' and 'fixed' lacks smoothness

On my webpage, I have a banner element with the class .banner and a floating element with the class .float. As the user scrolls, I want the floating element to appear centered vertically relative to the banner when it is in view. However, once the user sc ...

Adjusting offcanvas height in Bootstrap based on content

.cursor-pointer { cursor: pointer; } <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="690b06061d1a1d1d09c13c809e9afbcfc1792efeff8">[email protected]</a>/dist/js/bootstr ...