When resizing the browser, HTML/CSS elements tend to shift positions :(

I've experimented with different position values like absolute, fixed, and static without success.

Wrapping the element in a div didn't yield the desired result, so I'm seeking assistance to correct this. (If that is the solution)

The issue extends beyond just the .table element, but finding a fix for one will hopefully solve all similar problems.

My goal is to keep the elements where I place them or have them shrink slightly if needed.

This particular object is the focal point of my concern regarding positioning.

This being my first experience with html & css, any guidance would be greatly appreciated.

Thank you for your time :)

.table {
  font-family: "Fira Sans", sans-serif;
  border-collapse: collapse;
  overflow-y: scroll;
  height: 520px;
  width: 425px;
  position: relative;
  display: block;
  z-index: 6;
  left: 120rem;
  bottom: 90rem;
  background-color: white;
  border: 4px solid black;
  z-index: 5;
}
<table class="table">
  <thead>
    <tr>
      <th>
        <input type="text" class="search-input" placeholder="Abbreviation">
      </th>
      <th>
        <input type="text" class="search-input" placeholder="Full Name">
      </th>
      <th>
    </tr>
    <tr>
      <td>XXX</td>
      <td>XXX, XXX, XXX</td>
    </tr>
    <tr>
</table>
</div>

Answer №1

I have taken the liberty of adjusting your HTML code. I included new elements and made changes to your CSS in order to demonstrate how styles can impact each other. The initial .table CSS had too many rules that altered the definition of a table element. Hopefully, my modifications will provide you with some insights.

It would also be beneficial for you to utilize online resources for assistance with HTML and CSS.
MDN is considered THE ultimate source for web development.

ADDENDUM:


The beauty of HTML and CSS lies in their ability to mix and match elements and rules. We have numerous tools at our disposal to customize the appearance of a page. However, this flexibility can also pose challenges.

For what it's worth: Just because we have the capability to embed data collection within a table (in the header or elsewhere) doesn't mean we should.

Yes, it may be permissible. Yes, it may function as intended.

However, it does alter the HTML structure. While this might be technically acceptable and functional, there could be unforeseen issues. For example, using CSS to change display:table to display:block.

Additionally, accessibility concerns must not be overlooked, such as screen readers encountering input fields instead of column headers.

The different parts of an element are meant to work harmoniously together and should only be redefined cautiously. If we find ourselves attempting to make one element behave like another, chances are something was overlooked.

.outer {
  position: relative;
}

.dontmove {
  position: absolute;
  width: 500px;
}

.table {
  font-family: "Fira Sans", sans-serif;
  border-collapse: collapse;
  background-color: white;
  border: 4px solid black;
  width: 100%
}

.table th,
.table td {
  padding: 2px 6px;
}

.table th>input {
  width: 100%;
}
<div class="outer">
  <div class="dontmove">
    <table class="table">
      <thead>
        <tr>
          <th>
            <input type="text" class="search-input" placeholder="Abbreviation">
          </th>
          <th>
            <input type="text" class="search-input" placeholder="Full Name">
          </th>
          <th>
        </tr>
        <tr>
          <td>XXX</td>
          <td>XXX, XXX, XXX</td>
        </tr>
        <tr>
    </table>
  </div>
</div>

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

Is there a way to selectively display a portion of my CSS class based on certain conditions?

Is there a way to conditionally render all of the css inside the following hover psuedoclass based on a variable (data) being not null? Within my React Component that utilizes Material UI makeStyles, I have the following styles: const useStyles = makeStyle ...

Issue with HTML and CSS where the header is displayed behind the rest of the content

I'm having issues with creating a fixed header for my webpage. It seems to be hiding behind the rest of the content on the screen even though I have tried adjusting the z-index without success. Here is a snippet of my HTML code: body { m ...

Disable the ability to scroll the background when the lightbox is opened

Currently incorporating Featherlight for a lightbox feature. Encountering an issue where the background remains scrollable when the lightbox is open. Typically, lightboxes require adding a class to the body with overflow:hidden; to resolve this problem. S ...

Attempting to showcase a pair of unordered lists side by side using the power of flexbox

I am having trouble getting this to display on a single line, no matter what I try. While there may be simpler ways to achieve this without using flexbox, I am eager to learn how to do it using flexbox properties. My desired outcome is to have the first u ...

Secondary menu

Is there a way to create a sub navigation menu that only changes once I click a link in the main navigation bar, without refreshing the entire page? Any help would be greatly appreciated. http://jsfiddle.net/qrn8Q/ Thank you. HTML Code: <header ...

What is the most effective method for resetting the scroll position of a browser when refreshing a page?

Portfolio Query I am in the process of setting up a basic portfolio website. My navigation bar includes various links, one of which is labeled "About Me". Upon clicking this link, the page immediately jumps to a specific section with an element ID of #abo ...

Twitter Bootstrap 3 Carousel now showcasing a pair of images simultaneously instead of three

Can this carousel be configured to show just 2 pictures at a time instead of 3? Check out the live demo here. I've attempted adjusting the columns to col-md-6 and the CSS to 50%, but haven't had any success... ...

How to align several lines of text in a table cell

I've been trying to center multiple lines of text in a table cell using the table method, but no matter how many online guides and SO posts I follow, I just can't seem to get it right. What I'm aiming for is to have the text perfectly cente ...

JavaScript code that triggers when a checkbox is not selected

I'm attempting to dynamically add an input field when a checkbox is clicked, with the intention of having the checkbox already checked by default. However, I am encountering an issue where the checkbox remains unchecked even after the input field is d ...

Using multiple selectors in JQuery and Javascript

I have a challenge where I need to execute different actions for specific divs. Here is the code snippet I currently have: $("#pending-cancel-1, #pending-cancel-2").click(function(){ Do something special for pending-cancel-1 and pending-cancel-2... }) ...

Creating responsive lines with CSS on top of an image

I would like to add lines on an image using CSS3 and HTML5 Canvas. I came across a tutorial and demo that utilizes an html div: However, when attempting this effect on an image, the line appears outside of the image. How can I ensure that the line is dra ...

The footer has a wandering nature, constantly moving around as the wrapper mysteriously vanishes

I understand that this question has been asked multiple times before, but I am struggling to get it right! My goal is to keep the footer at the bottom of the page, but it seems to be acting strangely. Here is my HTML: <!DOCTYPE HTML> <html& ...

Struggling to line up three images with linked attachments in a single row using Bootstrap 4

Currently tackling my portfolio for a school project, I find myself stuck on organizing my projects in a single line. Here is the code snippet that's giving me trouble... <div class="container"> <div class="row"> <div class= ...

Modify the HTML input type color in React.js only after releasing the mouse button

<input className="color-palatte" type="color" onChange={(e) => onColorChange(e)} /> When interacting with the color palette, I have set up an API call to trigger only when I release the slider instead of continuous calls while sliding over the co ...

Retrieve the AngularJS scope object by using an alternate scope object as the identifier

As I loop through an array of person objects using ng-repeat, imagine the array looks something like this: [{ "display_name": "John Smith", "status": "part-time", "bio": "I am a person. I do people stuff.", }, { "display_name": "Jane Doe", "stat ...

The downside Div is being displaced by a Paragraph with an overflow-y:scroll property

In my Div, I have set the width and height of a paragraph along with the property overflow-y:scroll. It's working fine as the paragraph is displaying with a vertical scroll. However, it is causing displacement in the div below. Below is the HTML code ...

Styling the CSS to give each grid element a unique height

I am working on a grid layout with three columns where the height adjusts to accommodate all text content. .main .contentWrapper { height:60%; margin-top:5%; display:grid; grid-template-columns:1fr 1fr 1fr; grid-gap:10px; /*grid-te ...

Why might a responsive website automatically switch to mobile view?

My website has a responsive grid system that utilizes media queries with breakpoints. However, I am encountering an issue on IE8 where the "mobile version" of the site is being displayed as the default view even when the screen size is set to what should b ...

Achieving a Side-Along Sidebar with CSS, Fully Embracing

I'm encountering an issue with achieving 100% height using CSS. Despite my extensive search for tutorials and solutions, I haven't been able to achieve the desired results. My layout consists of a sidebar and a main column where the content will ...

The contents table remains fixed in the top right corner as you scroll

I have developed an Angular app with a table-of-contents component that only displays two items. The code for the script is as follows: ts import { Component, OnInit } from '@angular/core'; import { pdfDefaultOptions } from 'ngx-extended-p ...