Impossible to create margins on both the left and right side

Check out this cool pen: http://codepen.io/helloworld/pen/BcjCJ?editors=110

I'm facing an issue where I'm unable to create both left and right margins around my datagrid. Only the left margin seems to be possible.

Any suggestions on how I can fix this?

I want to have a 10px margin on each side, for example.

HTML:

 <div id="gridWrapper" class="test">
<div id="gridHeader">     
      <div class="columnHeader">Monday</div>
      <div class="columnHeader">Tuesday</div>        
  </div>

  <div id="gridContent">

    <!-- Monday Column-->
    <div style="background:lightblue;" class="column">

      <div class="custom-row">3333333 1111111111112222222... (content has been truncated for brevity)

      <div class="custom-row">22222222222... (content has been truncated for brevity)
    </div>

    <!-- Tuesday Column-->
    <div style="background:green;" class="column">

      <div class="custom-row">fsadffsfsfsd fsdsfdfsdfsadffsadffsf... (content has been truncated for brevity)

      <div class="custom-row">fsadffsfsfsd fsdsfdfsdfsadffsadffsf... (content has been truncated for brevity)
    </div>

  </div>

</div>

CSS:

body,html{
   padding:0;
  margin:0;
}
.test {   
    animation: fadein 2s;
    -moz-animation: fadein 2s; 
    -webkit-animation: fadein 2s; 
    -o-animation: fadein 2s; 
}

@keyframes fadein {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}

...

.custom-row{
  height:200px;  

  overflow-y:auto;
  overflow-x:hidden;
  border:1px solid blue;
  background:orange;
}

Answer №1

Avoid using fixed positions to arrange your elements. http://codepen.io/anon/pen/KpNNzK

#gridWrapper {
  position: relative;
  margin-left: 10px;
  margin-right: 10px;
}

body,
html {
  padding: 0;
  margin: 0;
}

.test {
  position: relative;
  animation: fadein 2s;
  -moz-animation: fadein 2s;
  /* Firefox */

  -webkit-animation: fadein 2s;
  /* Safari and Chrome */

  -o-animation: fadein 2s;
  /* Opera */
}

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@-moz-keyframes fadein {
  /* Firefox */

  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@-webkit-keyframes fadein {
  /* Safari and Chrome */

  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@-o-keyframes fadein {
  /* Opera */

  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.columnHeader {
  background: yellow;
}

.columnHeader,
.column {
  -webkit-box-flex: 1;
  /* This ensures all headers have equal width regardless of content */

  width: 100%;
  font-weight: bold;
  font-size: 1.2em;
}

#gridHeader {
  display: flex;
  /* current version */
  /* Ensures all columns have equal width regardless of content */

  width: 100%;
  align-items: center;
  text-align: center;
  position: relative;
  top: 0px;
  left: 0px;
  height: 50px;
  background: gray;
}

#gridContent {
  display: -webkit-box;
  /* Ensures all columns have equal width regardless of content */

  width: 100%;
  background: red;
  position: relative;
  top: 0px;
  bottom: 0px;
  overflow-y: auto;
  overflow-x: hidden;
}

* {
  box-sizing: border-box;
}

.custom-row {
  height: 200px;
  /* Use flex to achieve equal height */

  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid blue;
  background: orange;
}
<div id="gridWrapper" class="test">
  <div id="gridHeader" style="">
    <div class="columnHeader">Monday</div>
    <div class="columnHeader">Tuesday</div>
  </div>

  <div id="gridContent">

    <!-- Monday Column-->
    <div style="background:lightblue;" class="column">
      <!-- ko: foreach-->
      <div class="custom-row">3333333 11111111111... (continues) ...1111</div>

      <div class="custom-row">22222222222... (continues) ...222</div>
    </div>

    <!-- Tuesday Column-->
    <div style="background:green;" class="column">
      <!-- ko: foreach-->
      <div class="custom-row">fsadffsfsfsd fsdsfdfsdf... (continues) ...sad</div>
      <div class="custom-row">fsadffsfsfsd fsdsfd... (continues) ...sad</div>
    </div>

  </div>

</div>

Answer №2

To resolve this issue, apply the following CSS to the #gridContent

width:calc(100% - 60px); // Calculating 2 times 30px ...
margin-left:30px;

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

What is the best way to retrieve the value of a component's HTML id tag in React?

Is there a way for me to retrieve the id of a react component from within the component itself? I need this information to perform some tasks with a third-party library. In Ember, you can access the component's id using elementId, which can be found ...

Implementing the IF statement in jQuery

I've been trying to implement an overflow check when hovering over a div. The issue arises because I'm using jQuery for the hover function and then simple JavaScript for the overflow check in the next step. It seems that directly using an if-then ...

How can images be resized according to screen resolution without relying on javascript?

Looking to use a large banner image on my website with dimensions of 976X450. How can I make sure that the image stretches to fit higher resolution monitors without using multiple images for different resolutions? ...

A guide on detecting overflow in a React functional component

I am in search of a way to determine if a div contains overflowing text and display a "show more" link if it does. While researching, I came across an insightful Stack Overflow answer on checking for overflow in a div. The answer suggests implementing a fu ...

Issues with keyboard accessibility in drop down menus

Looking to improve the keyboard accessibility of my menu bar. Swapped out all instances of :hover with :focus, but unfortunately dropdown menus are still not accessible via keyboard. Does anyone have a solution for this issue? Appreciate any help! ...

Identify when a browser tab is closed and determine which specific tab out of all the open tabs was closed

Is there a way to identify when a browser or tab is closed in Angular/JavaScript? I would like to know if there are specific events that can be used for detecting these actions. Any advice, information, or code examples on this topic would be greatly app ...

Repositioning the final row to the bottom of the container in Bootstrap 4

I am working on a simple footer design that includes contact information in three rows. The first two rows should appear at the top, while the last row needs to be positioned at the very bottom of the container. To achieve this layout, I decided to use abs ...

React conditional statement within a map function embedded in a JSX element

Below is the function I have created to generate tabbed items: function ConstructTabs(props) { const tabs = props.tabs; const makeTabs = tabs.map((tab, index) => { <React.Fragment> <input className="input-tabs" id ...

How can I retrieve the index of an element within a 2D array using JavaScript when the array is displayed on a webpage?

https://i.stack.imgur.com/GHx9p.png I am currently working on developing an Othello game board within an HTML page using Angular. The board itself is constructed from a 2D number array which I then display using the <table> tag on the webpage. Below ...

Utilize Python to extract information from an HTML table

I am looking to extract data from an HTML table using a Python script and save it as variables that can be later utilized in the same script after loading them in if they exist, into a separate file. Additionally, I would like the script to disregard the f ...

Displaying tooltips with ngx-charts in Angular

Currently, I am working on developing a unique legend component that features individual material progress bars for each data entry. My goal is to display the pie chart tooltip when hovering over any of the entries within this custom legend. Below is a sn ...

Guide on creating an accessible table with rows that can be selected

Managing accessibility in a web application can be challenging, especially when dealing with features like selecting multiple rows using checkboxes. In my current project, I have a view that displays a list of items and allows users to select multiple rows ...

I'm looking to showcase the list in a navigation bar by clicking on the hamburger menu. I want to include the 'home' and 'about' text specifically

Having trouble implementing the hamburger menu functionality in my HTML/CSS project. When clicked on a shrunken screen, I want the 'Home' and 'About' text in the nav to appear stacked on top of each other. JS is causing me some difficul ...

Incorporate Vimeo video with full-width display

When embedding a Vimeo video on my website, I use the following code: <div class="fys-fp-content-wrapper"> <div id="fys-fp-video"> </div> </div> #fys-fp-video { position: relative; padding-bottom: 56.25%; padding-top: ...

how to make a "select all" checkbox with Angular 2

`I'm currently working on a feature that allows a checkbox to select all checkboxes within a specific div when checked. The div exclusively contains checkboxes. //TS FILE constructor() { } checkAll: ElementRef | undefined; selectAll(isChecked: ...

Increasing the width of a line to fill the entire space using CSS properties

Seeking alternative ideas to replace my current solution using only CSS for one of the problems. I already have a working JS solution, but I'm interested in exploring a CSS-only approach. https://i.sstatic.net/PQ7er.png A) All elements here have the ...

Is there a way to position my input at the bottom of its parent element?

Is there a way to position this input element at the bottom and center of its parent div? https://i.sstatic.net/gs1yP.jpg ...

Using Conditional Tags for CSS Display

I'm working on implementing Conditional Tags to toggle a CSS class on or off based on the current displayed page. However, I'm running into an issue where the code isn't executing properly. There might be a syntax or logic error causing the ...

Trouble Arising from Regional Settings in my Hybrid App Developed with CapacitorJS and Vue.js

Issue with capacitor app input Correct input in chrome app I'm facing a problem related to regional settings in my mobile application, developed using CapacitorJS and Vue.js 2. The datetime-local control is appearing in a language that isn't the ...

What is the best way to display content at a specific time using Angular?

Whenever a user searches something and no results are found, I display a message. However, when there is content to show, an error message pops up for about 3-4 seconds before disappearing and showing the search results. This is my HTML: <div> &l ...