Responsive design does not work with a relative position

Being a fan of using position:relative along with top, left, bottom, and right for positioning elements, I find myself frequently adjusting the values manually in the console before updating the CSS file. While I enjoy this process, there is a major drawback - it lacks responsiveness to changes in size. Allow me to demonstrate with a quick example.

In the initial image, the topic icons such as delete topic and edit appear well-aligned. However, upon zooming in, as seen in the second image, the alignment is completely off. Here is the code for the page in its entirety. I am desperately seeking a solution that would allow for easier responsiveness. Position:relative may be convenient, but sadly it doesn't offer responsiveness :(

Minimal CSS:

span.icon_share_topic {
    position: relative;
    /* left: 1422px; */
    /* top: 1048px; */
    margin-left: 60%;
}
<span.icon_flag_topic {
    position: relative;
    left: 990px;
}
...

Minimal HTML :

  <div class="topic-buttons">
        ...
</code></pre>

<p>If you are interested in more than just the above code, please let me know. Any help would be highly appreciated! By the way, I'm working on this project <a href="https://ide.c9.io/amanuel2/ng-fourm" rel="nofollow noreferrer">here</a>. It would be fantastic if we could collaborate on resolving this issue here!</p>

<p>Based on James Howell's suggestions, I made adjustments to the HTML:</p>

<pre><code> <span ng-if="flagSee();" class="container_flag_icon">
           ...
</span>

And updated the CSS accordingly:

span.container_flag_icon.ng-scope {
    position: relative;
}
span.icon_flag_topic {
    position: absolute;
    left: 976px;
}    

Unfortunately, even after making these modifications, the issues persist when zooming. -_-

Answer №1

To start, eliminate any statements that are not absolute. Then implement some more advanced flexbox styling techniques. By utilizing flex-wrap: wrap, you can prevent content from overflowing the screen on the left side by allowing it to span multiple lines. Employing justify-content: flex-end will help neatly align everything to the right, similar to what you attempted with relative positioning for larger screens.

Best of luck with your exciting project!

Answer №2

When you utilize the following CSS code:

position: relative

You are placing an element relative to its parent. As a result, if the position of the parent element changes (such as during a browser resize), then the elements positioned in this manner will also be affected.

To address this issue, it is advisable to enclose the items you wish to position within a container element, like a div, and apply relative positioning to that container element while giving the child elements absolute positioning. Here's an example:

<div class="parent">
    <div class="child"></div>
</div>

.parent{
    position: relative;
}

.child{
    position: absolute;
    right: 0px;
}

Answer №3

Your layout strategy needs a complete overhaul. If you want to make a quick adjustment to a website that is structured as you have indicated, you can add a fixed-width viewport to eliminate responsiveness:

<meta name="viewport" content="width=1200"> 

By the way, feel free to change the width value to any number that maintains satisfactory appearance.

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

Utilize the :not() selector in combination with the :first-child() selector

Currently, I am seeking a method to merge two css selectors together in order to target specific elements. The selectors I am attempting to combine are ':not' and ':first-of-type'. Here is the code snippet that represents my current sit ...

Is it possible to validate without having to refresh the page?

I am brand new to coding and I have a login form on my index.php page. <form action="login.php" method="post" name="form1"> <div class="form-group"> <div class="form-label-group"> <input type="text" id="inputEm ...

show the content depending on the result given by a connected class to a function

Currently, I am executing a loop where each item contains a button with a specific class that is linked to a method. The text displayed on these buttons depends on the value returned by the mentioned method. HTML Template <button v-for="(item, ind ...

What is the best way to transform SASS into CSS?

Looking for an online tool to easily convert a few lines of SASS into pure CSS. Despite searching on Google, all the links I found talk about converting CSS to SASS. Below are the specific lines I need assistance in converting to CSS: =text-shadow($color ...

Delete property from object in JavaScript

Looking for a solution to replace the content of an object with another in an array of objects without passing the reference directly. The challenge is not knowing what values my function will pass, so I can't use them as keys to avoid copying the re ...

Adjust the backdrop for the currently chosen tab

For some reason, my code isn't working even though I thought I did everything correctly. My goal is to change the background color for the selected tab. This is what I have tried so far: <script> $('#navigation li').click(function() { ...

Activate a module within a Vuex action only upon dispatching

Is there a way to import a package for use in a Vuex Action only when the Action is dispatched, in order to reduce the size of my entry bundle? Here's what I've tried: export const actions = { async createNewBin(store, bin) { const fireba ...

Ways to boost memory capacity in nodejs

I've been attempting to increase the memory limit in node.js, and to do so I added an environment variable. You can see how I did it here Unfortunately, it doesn't seem to be working as expected. I even tried using capital letters with no succe ...

Retrieve the information transmitted to an EJS file within a separately included JavaScript file

I'm currently utilizing express js to render a file by using: res.render('plain',{state:'admin'}) The file plain.ejs includes main.js: <script src ="/main.js"></script> I need assistance on how to access the state v ...

Elastic_Frame | "Error: Unable to process action as property 'toLowerCase' is not defined"

Attempting to create a personal and project portfolio using Vu Khanh Truong's "elastic_grid" jQuery plugin for the actual portfolio. You can access it here. However, encountering some issues on my page: 1) The header for the portfolio section disappe ...

The element type provided is not valid: it should be a string (for built-in components) or a class/function. Utilizing SSR with Node.js, React, and React-

Playground: https://codesandbox.io/s/focused-dream-ko68k?file=/server/server.js Issue Error: Encountered an error stating that the element type is invalid. It was expecting a string or a class/function, but received undefined instead. This could be due ...

Tips on adjusting the placement of a div element with JavaScript

Initially, I am unsure if the title accurately reflects what I am seeking. Within my HTML form, I have numerous elements such as div, p, or js. Here is an example: <div id="main"> <div id="abc1"></div> <div id="abc2"></div&g ...

The offlinefirst.sock encountered an EPERM error

Encountering an error when attempting to run https://github.com/jakearchibald/wittr on Windows bash. Assistance in either resolving or troubleshooting this issue would be greatly appreciated: Development server listening. (PID:469) Config server liste ...

What is causing the border-bottom in these inline divs to not display when using a fractional height? (Specifically in Chrome)

Here is a jsfiddle I'd like to share with you: https://jsfiddle.net/ionescho/4d07k799/4/ The HTML code: <div class='container'> <div class="row"></div><div class="row"></div><div class="row"></div> ...

Ways to position an image in the middle of a Div

I am currently working with PHP and Smarty, attempting to display a slideshow's images in the center of a specific div, but I am encountering difficulties achieving this. Below you will find the code snippet. Can anyone help me figure out what I migh ...

The information displayed in the second drop-down menu will change based on the selection made

My goal is to create a dynamic web page with two drop-down menus. The options displayed in the second drop-down menu will change based on the selection made in the first drop-down menu. For instance, if Category A is selected in the first drop-down menu, ...

Struggling with creating an html file that is responsive on mobile devices

I am currently utilizing bootstrap 4 for the construction of a website. I have encountered an issue where my homepage does not display properly on handheld devices when using Google Chrome's device toggle toolbar. The homepage requires scrolling to vi ...

What is the correct method for exporting an ES6 module function as a library to be utilized in a Node.js application?

Imagine having a node.js application that does not pass through webpack bundling: Node App const Html = require('./build/ssr-bundle.js'); let result = Html.ssrbundle.render(); console.log(result); Here is my ES6/JSX file, which undergoes web ...

NodeJs: express wreaks havoc on the generated HTML markup

Similar Question: ExpressJS: how to output pretty html While using Express as my framework for node.js, everything is running smoothly except for one minor issue. When I view the page source by right-clicking on the browser, all my HTML code appears u ...

What could be causing the absence of req.body data in a specific route in my Node JS application?

Hello, I am encountering an issue with my Node JS application: When attempting to authenticate, I am receiving an "undefined" value for "req.body.username" upon sending a POST request to that specific route. This problem seems to only occur on this parti ...