arranging and altering the size of elements inside a container div

I recently started working on a new project with CodePen where I am building a website from the ground up. Each section of the site is meant to be a full page, which is why I implemented the section class. Within my first section (about), I have created two divs. My goal is for the layout to remain consistent regardless of browser size. However, I am encountering issues with the positioning of the aboutInfo div when the window is resized, despite setting its position to absolute.

Here is the current snippet of code:

#about {
  background-color: #D1C9BE;
  position: relative;
}

#aboutImage {
  border-style: dashed;
  border-color: red;
  background-color: white;

  position: absolute;
  height: 150px;
  width: 150px;
  top: 50%;
  transform: translateY(-50%);
  left: 300px;
}

#aboutInfo {
  border-style: dotted;
  border-color: black;
  background-color: white;
  font-size: 35px;
  text-align: right;

  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 200px;
}

I have explored various solutions such as Flexbox, jQuery, as well as adjustments to margin and padding. At this point, I am unsure which approach would be most effective and user-friendly.

In summary, my questions are:

  1. How can I resolve the issue of the aboutInfo div moving around?

  2. How can I ensure that the content of the website automatically resizes to fit any browser size?

Answer №1

body {
    margin: 0;
}

html, body {
    height:100%;
    position: relative;
}

/* FULLPAGE */
.section {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;

}

/* ABOUT */
#about {
    background-color: #D1C9BE;
    position: relative;
}

#aboutImage {
    border-style: dashed;
    border-color: red;
    background-color: white;
    height: 150px;
    width: 150px;
}

#aboutInfo {
    border-style: dotted;
    border-color: black;
    background-color: white;
    margin-left: 20px;
    font-size: 35px;
    text-align: right;

}

#aboutInfo p {
    font-size: 15px;
}


/* SKILLS */
#section2 {
    background-color: #D8B17B;
}

/* PROJECTS */
#section3 {
    background-color: #9E9283;
}

/* OTHER */
#section4 {
    background-color: #70614C;
}

Answer №2

Give this styling a try, I've made some updates to your CSS to utilize flex for positioning

   body {
    margin: 0;
}

html, body {
    height:100%;
    position: relative;
}

/* FULLPAGE */
.section {
    height: 100vh;
     display: flex;
    justify-content: space-around;
  align-items: center;

}

/* ABOUT */
#about {
    background-color: #D1C9BE;
    position: relative;
}

#aboutImage {
    border-style: dashed;
    border-color: red;
    background-color: white;
    height: 150px;
    width: 150px;
}

#aboutInfo {
    border-style: dotted;
    border-color: black;
    background-color: white;

    font-size: 35px;
    text-align: right;

}

#aboutInfo p {
    font-size: 15px;
}


/* SKILLS */
#section2 {
    background-color: #D8B17B;
}

/* PROJECTS */
#section3 {
    background-color: #9E9283;
}

/* OTHER */
#section4 {
    background-color: #70614C;
}

Answer №3

Utilize the power of flex to create responsive divs without relying on absolute positioning.

Check out the latest Codepen for reference.

.section {
    display: flex;
    padding: 0 48px; /* provides spacing at edges of the screen */
    align-items: center; /* ensures vertical centering */
}

.section > :first-child {
    margin-right: 48px; /* adjusts distance between boxes */
}

Read this informative article from MDN for more insights on using flex.

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 adjust the brightness of any color when hovered over

Is it possible to create a universal effect where an element becomes darker or lighter when hovered over, regardless of the initial color? Here is an example: .change-color{ Background:green; width:100px; height:100px } .change-color:hover{ Background ...

Add a border to the navigation bar item to indicate the current page being displayed

This section shows the current navigation bar item https://i.sstatic.net/6RAGJ.png This is the desired outcome when clicking on the tab https://i.sstatic.net/8nFeB.png Uncertain about the best approach for achieving this. I have attempted to submit a val ...

Step-by-step guide to creating a border around text with a number included in between the lines

Is there a way to replicate the appearance of the image shown below using CSS, Bootstrap, or other client-side methods? ...

What is the best way to switch out the characters 'a' and 'b' in a given string?

Let's say we have the following text. Lorem ipsum dolor sit amet The revised text should look like this: merol merol merol merol Is there a predefined function in JavaScript that can help us replace characters like this within a string? ...

The map is not displayed on the leaflet

I am having trouble getting the map to display properly. I have added the cdn link in my head. <link rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="18747d797e747d6c5829 ...

What could be causing this code to malfunction in Internet Explorer 7?

Code: Demo: In the majority of modern browsers such as Safari, Chrome, Firefox, and IE8/9, the code works perfectly fine. However, there seems to be an issue with IE7, causing it not to work. Any idea why this might be happening? My goal is for the conte ...

Positioning a flex item to the right by using float

I am in need of assistance with my HTML layout. <div class="container"> <div class="sidebar" style="float:right"> Ignore sidebar? </div> <div> main content </div> </div> The container is set to have a flex disp ...

Can you always rely on promises being fulfilled?

Consider a scenario where we have a function named logData to handle HTTP requests and another function called logIntoDatabase. async logIntoDatabase(message) { ... } async logData(request, response) { await logIntoDatabase("something happened"); ...

Warning: The Unhandled Promise Rejection arises when an error is thrown within an asynchronous function without a try-catch block

Encountering the following issue in my Node-Express App UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error came about either by throwing inside an async function without a catch block, or rejecting a promise that was not hand ...

What could be the reason for my AJAX function transmitting form data to the designated URL?

After a user submits their form, my goal is to utilize JQuery/AJAX in order to prevent the page from redirecting or reloading. The issue I am facing is that despite using the POST method, the user data is being refreshed and displayed in the URL! On my l ...

How do I switch between liking and unliking a post using Ajax's success response?

I have successfully implemented code to insert or delete likes from the database, and it functions correctly upon page refresh. However, I am struggling to figure out how to make it toggle upon clicking. I have attempted various online solutions without su ...

Creating a scrolling list group in a single column that moves in sync with another longer column

When working with two columns in Bootstrap, such as col-4 and col-8, how can you ensure that a list-group stays fixed within its column and vertically aligned even when the content in the other column is scrolled down? Dealing with this responsively can b ...

Send HTML table information from view to Controller action in ASP.NET Core by converting it to a list

Encountering issues with null values in the controller action method, preventing table data rows from being looped through. Model: class: public class Generation { public int Generation1Count { get; set; } public int Generation1TotalS ...

Show whether the day is even or odd with the JavaScript getDay object

I'm currently working on a task where I need to show the text "Even Day" if the day of the month is 2, 4, 6..., and "Odd Day" for days such as 1, 3, 5, and so on. I attempted to achieve this by setting up an array linked to the getDay object, but unfo ...

Modifying the data of a particular object in my rtk asynchronous thunk

I recently started using rtk and immer. I encountered an issue when trying to update my state with redux. For example, when a user logs in, I store their data in redux with the following structure: data = { "user_profile" : { "name&q ...

Tips on showing binary information as images using extjs 4

As the proud owner of a valid .JPEG image's binary data, I am on a quest to convert this information into an actual viewable image using Python. Seeking advice on how to successfully transform this binary code into a visually appealing .JPEG format w ...

I need to search through a tree structure in typescript based on a specific value without encountering a maximum stack call exceeded error

How can I perform a value-based search on a complex tree structure in TypeScript without encountering the maximum stack call exceeded error? I am attempting to navigate through an expandable tree using TypeScript, and I will provide the code snippet below ...

Simple methods for ensuring a minimum time interval between observable emittance

My RxJS observable is set to emit values at random intervals ranging from 0 to 1000ms. Is there a way to confirm that there is always a minimum gap of 200ms between each emission without skipping or dropping any values, while ensuring they are emitted in ...

Utilize Mouseover and Mouseout events to activate and deactivate the timer

How do I implement a mouseenter event to turn off a timer and a mouseleave event to turn on the timer? If the timer interval is reached, the webpage will automatically refresh. I attempted to do it myself, but couldn't get it to work: <script> ...

Is it necessary to use the prefix meteor when incorporating npm with Meteor?

When I am working on Meteor 1.3 projects, is it necessary to always prepend meteor before npm? The Meteor documentation and code examples seem to offer different approaches. I believe that the recommended practice is: $ meteor npm install --save some-pac ...