Having trouble with the Inline-Block display, attempting to design a two-column layout

Despite trying various tips from other Stackoverflow queries, the solutions don't seem to apply in this case. This is the desired outcome.

* {
    box-sizing: border-box;
  }
 
  html {
    height:100%;
    width:100%;
    border: 0px;
    margin:0;
    padding:0;
  }

body {
  height: inherit;
  width: inherit;
  border: 0px;
  margin:0;
  padding:0;
}

header {
    font-size: 30px;
    text-align: center;   
    width: 100%;
    font-family: Lato;
}

... (CSS code continued)
<html> 
  <head>
    <title>Notes:</title>
    ... (HTML code continues)
</html>

Issue: #notesSection is not aligned on the same line as the #brainstormSection when both are set to inline-block.

I have attempted to rectify spacing discrepancies, reset all dimensions, and ensure 100% width and height for HTML, body, and main tags. While the problem can be solved with the float property, is it possible to address it solely with display: inline-block?


UPDATE: After resolving the issue with the inline-block effect by removing unnecessary whitespaces created by CSS, I am now facing challenges with borders. Achieving perfectly straight and even borders, as seen in this example, is proving to be difficult.

Adjusting everything to be flawless in terms of width and height, by meticulously subtracting any added or modified pixels caused by borders, padding, and future changes, is quite cumbersome. Is there a better way to avoid this exhaustive adjustment process? Are there alternative CSS toolkit options for creating two-column webpage projects similar to this example?


UPDATE TWO: Making progress, thanks to the invaluable comments from everyone assisting me! However, there appears to be a noticeable gap in the border between #headerBrainstorm and the content of #sectionBrainstorm. The gap, caused by the padding: 20px; declaration within the #notesSection selector, is perplexing considering all dimensions were reset to box-size: border-box;. I'm curious to understand why this discrepancy persists.

Thank you for your assistance.

Answer №1

To achieve this layout, consider using the display: flex property on the main element instead of inline-blocks for better stability.

header {
    font-size: 30px;
    text-align: center;   
    width: 100%;
    font-family: Lato;
}

main {
    display: flex; /* This line defines the layout */
    width: 100%;
    height: 100%;
    border:0px;
    margin: 0;
    padding: 0;
}


 html, body {
    height:100%;
    width:100%;
    border: 0px;
    margin:0;
    padding:0;
}

.bold {
    font-weight: 900;
}

.figure1 {
    width: 300px;
    height: 300px;
}

.figure1 img {
    width: 400px;
    /* height: auto; */
}

.figCap1 {
    font-size: 17px;
    font-weight: 900;
    font-family: Lato;
}

#offsetTittle {
    font-size: 17px;
    font-weight: 900;
    font-family: Lato;   
}

#notesSection, #brainstormSection {
    flex: 1 0 50%; /* Adjust this according to your needs */
    height: 100%;
    /* border: 1px solid black; */
}
<html> 
  <head>
    <title>Notes:</title>
    <link href="https://fonts.googleapis.com/css2?family=Lato:wght@900&display=swap" rel="stylesheet">  
    <link rel="stylesheet" href="./css/style.css" type="text/css">
    <link rel="stylesheet" href="../globalResources/css/normalize.css">
  </head>

  <body>
    <header>
      <span class="bold">Notes</span>  
    </header>
    <hr>
    <main>
      <section id="notesSection">
        <figure class="figure1">
            <figcaption class="figCap1">Hope to use this if is advatageous:</figcaption>
            <br>
            <a href="https://www.codecademy.com/paths/web-development/tracks/styling-a-website/modules/local-website-development/articles/visual-studio-code" target="_blank">
              <img src="https://ibb.co/TqpPDqD" alt="CodeAcademy Article"></a>
        </figure> 
        <hr>
        <article>
          <span class="bold" id="offsetTittle">Offset:</span>
          <p>Offset is the distance at which the element was moved from its original location; This is seen when you position an element.</p>
          <a href="https://stackoverflow.com/questions/9264767/internet-explorer-box-model-what-is-offset/15974969#15974969" target="_blank"><img src="./images/offset1.png" alt=""></a>
          <img src="https://i.sstatic.net/vvBJo.png" alt=""> 
          <p>In the end this is an issue of mere semantics. Whether we call it "offset" or "position," it's still the same thing; it's the distance from its original location.</p>
        </article>      
      </section>
      <section id="brainstormSection">
        <figure class="figure1">
          <figcaption class="figCap1">Hope to use this if is advatageous:</figcaption>
          <br>
          <a href="https://www.codecademy.com/paths/web-development/tracks/styling-a-website/modules/local-website-development/articles/visual-studio-code" target="_blank">
            <img src="./images/Annotation 2020-07-17 184815.png" alt="CodeAcademy Article"></a>
      </figure> 
      <hr>
      <article>
        <span class="bold" id="offsetTittle">Offset:</span>
        <p>Offset is the distance at which the element was moved from its original location; This is seen when you position an element.</p>
        <a href="https://stackoverflow.com/questions/9264767/internet-explorer-box-model-what-is-offset/15974969#15974969" target="_blank"><img src="./images/offset1.png" alt=""></a>
        <img src="./images/offset2.png" alt=""> 
        <p>In the end this is an issue of mere semantics. Whether we call it "offset" or "position," it's still the same thing; it's the distance from its original location.</p>
      </article> 
      </section>
    </main>  
  </body>
</html>

Answer №2

Indeed, achieving this is possible by utilizing display:inline-block. A simple adjustment needs to be made to the CSS property width in #notesSection from 50% to 49%.

header {
    font-size: 30px;
    text-align: center;   
    width: 100%;
    font-family: Lato;
}

main {
    width: 100%;
    height: 100%;
    border:0px;
    margin: 0;
    padding: 0;
}


 html, body {
    height:100%;
    width:100%;
    border: 0px;
    margin:0;
    padding:0;
}

.bold {
    font-weight: 900;
}

.figure1 {
    width: 300px;
    height: 300px;
}

.figure1 img {
    width: 400px;
    /* height: auto; */
}

.figCap1 {
    font-size: 17px;
    font-weight: 900;
    font-family: Lato;
}

#offsetTittle {
    font-size: 17px;
    font-weight: 900;
    font-family: Lato;   
}

#notesSection, #brainstormSection {
    display: inline-block;
    width: 49%; /* Modification needed here */
    height: 100%;
    /* border: 1px solid black; */
}
<html> 
  <head>
    <title>Notes:</title>
    <link href="https://fonts.googleapis.com/css2?family=Lato:wght@900&display=swap" rel="stylesheet">  
    <link rel="stylesheet" href="./css/style.css" type="text/css">
    <link rel="stylesheet" href="../globalResources/css/normalize.css">
  </head>
  <body>
    <header>
      <span class="bold">Notes</span>  
    </header>
    <hr>
    <main>
      <section id="notesSection">
        <figure class="figure1">
          <figcaption class="figCap1">Hope to use this if is advatageous:</figcaption>
          <br>
          <a href="https://www.codecademy.com/paths/web-development/tracks/styling-a-website/modules/local-website-development/articles/visual-studio-code" target="_blank">
            <img src="https://i.imgur.com/Bs9e3k2.png" alt="CodeAcademy Article"></a>
      </figure> 
      <hr>
      <article>
        <span class="bold" id="offsetTittle">Offset:</span>
        <p>Offset is the distance at which the element was moved from its original location; This is seen when you position an element.</p>
        <a href="https://stackoverflow.com/questions/9264767/internet-explorer-box-model-what-is-offset/15974969#15974969" target="_blank"><img src="https://i.sstatic.net/vvBJo.png" alt=""></a>
        <img src="https://i.sstatic.net/BPFut.png" alt=""> 
        <p>In the end this is an issue of mere semantics. Whether we call it "offset" or "position," it's still the same thing; it's the distance from its original location.</p>
      </article> 
      </section>
      <section id="notesSection">
        <figure class="figure1">
          <figcaption class="figCap1">Hope to use this if is advatageous:</figcaption>
          <br>
          <a href="https://www.codecademy.com/paths/web-development/tracks/styling-a-website/modules/local-website-development/articles/visual-studio-code" target="_blank">
            <img src="https://i.imgur.com/Bs9e3k2.png" alt="CodeAcademy Article"></a>
      </figure> 
      <hr>
      <article>
        <span class="bold" id="offsetTittle">Offset:</span>
        <p>Offset is the distance at which the element was moved from its original location; This is seen when you position an element.</p>
        <a href="https://stackoverflow.com/questions/9264767/internet-explorer-box-model-what-is-offset/15974969#15974969" target="_blank"><img src="https://i.sstatic.net/vvBJo.png" alt=""></a>
        <img src="https://i.sstatic.net/BPFut.png" alt=""> 
        <p>In the end this is an issue of mere semantics. Whether we call it "offset" or "position," it's still the same thing; it's the distance from its original location.</p>
      </article> 
      </section>
    </main>  
  </body>
</html>

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

Using React and TypeScript to enable file uploads

Seeking assistance in creating a basic single select upload component. When I click a button that contains a hidden input field, the file dialog opens and allows me to choose a file. The placeholder then changes to display the selected file name along with ...

Navigational dropdown menu item vanishing upon hover

Utilizing bootstrap for my website, the main navigation employs dropdowns for secondary choices. I am encountering an issue in IE10 only (works fine everywhere else) where the dropdown menu is inconsistently accessible. Additionally, if you manage to acce ...

Storing HTML in a Database

I've encountered an issue while attempting to parse through an HTML file that consists solely of tags. I wrote a function to extract the content between these tags, and while I'm able to display it on the page without any problems, inserting th ...

Adjust image width in column

After searching through various tutorials and Stack Overflow posts, I am still unable to properly resize my image in the right column. I have a layout with a left and right column - the left contains a menu and the right holds some content along with a ba ...

How to implement a pop-up dialog box with multiple input boxes using AngularJS?

If you click on the link below: https://material.angularjs.org/latest/demo/dialog You'll notice that the prompt dialog box features only one input field. I'm curious to know if it's possible to customize this using mdDialog to include mult ...

The setInterval function does not function properly in IE8 when set to 0

I have a function called changeColor that updates the styling of certain elements in my HTML. In order to apply this function, I am using a timer like so: var timer = setInterval(changeColor,0); The issue I am encountering is that setting the time interv ...

How can we combine Angular Gradients and CSS Webkit Gradients for a modern design

Can a gradient be created that resembles the color picker style shown here? The outer part showing full saturated, 50% brightness values and transitioning towards the inside to 100% brightness. https://i.sstatic.net/ohuF4.jpg ...

Resize the images and align them side by side

I have a container with a maximum width of 1400px. Inside this container, there are two images of different sizes. I want to align them in a row using flexbox so that they fit within the 1400px width and still maintain a visually appealing appearance as sh ...

Automatically adjust image size to match viewport dimensions without cutting off edges

I am facing a CSS challenge. The issue is with an image that has dimensions of 1024x500 pixels. When the browser window size decreases below the width of the image (1024px), the image starts to get cropped on the sides. I have set the container width to 10 ...

Unique ways to serialize an HTML element efficiently: JavaScript tricks

Is there a way to store a reference of an HTML tag for future use? For instance, if I click on a div and save a pointer to that div in JavaScript, is it possible to serialize this pointer and then de-serialize it to use in another part of the web applicat ...

Concealing items in a loop using Javascript

I need assistance with this issue. I am trying to hide text by clicking on a link, but it doesn't seem to be working correctly. Even though I tried the following code, I can't figure out why it's not functioning as expected. Is there a diff ...

Is it possible to access a file on the client's PC without transferring the file to the server?

Is there a way to read an excel file directly from a user's PC in a web app and insert the cell values into a MySQL database cell by cell? Or should the file be uploaded to the server first before being read? (The web app is built using JSP) ...

The dropdown login form is malfunctioning on my Wordpress website

After reading various tutorials and guides online, I managed to set up a login screen. You can view the code in my jsfiddle: Jsfiddle. Unfortunately, I am facing issues with making the code function correctly. Being new to Jquery, I might have made a begin ...

Dealing with 'this' while using an addEventListener

I need to trigger the function handleRangeUpdate in a way that it responds to the event calling it and decides whether to run console.log(this.value). The problem arises when I pass e into handleRangeUpdate using addEventListener, causing the value of thi ...

Whenever I click on <a href="whatever.aspx"></a>, I would like the page to be displayed within the current page

This is the code I am working with: <asp:DataList ID="dlGallery" runat="server" RepeatLayout="Flow" Width="100%" CellPadding="4" ForeColor="#333333"> <AlternatingItemStyle BackColor="White" ForeColor="#284775" /> <FooterStyle BackColor ...

Learn how to utilize the getElementByClassName method in JavaScript to insert checkboxes into two lists that share the same class name

I have a situation where I have two lists sharing the same class name. I need to dynamically create checkboxes in both of these lists based on XML data. My current dilemma lies in how to properly utilize getElementByClassName in JavaScript to add checkbox ...

Applying position: absolute in HTML/CSS to lock parent and child elements in

Transform the boxes into concentric circles (circles within each other that share the same center). The outer circle should be black with a size of 300px and the inner circle should be white with a size of 200px. html: <div id="p10"> <div id ...

Dynamic WordPress Website Designs

Seeking recommendations for responsive WordPress themes that offer extensive CSS and structural customization options. The goal is to retain all of WordPress's built-in features, such as blogging capabilities, while having the freedom to completely co ...

Tips on including variables within quotation marks in JavaScript

I'm currently working on a JavaScript project using Pug. My goal is to use Express and MongoDB to develop a CRUD application that generates an edit button for each post, triggering a specific event when clicked. However, instead of the desired resul ...

jQuery allows you to dynamically add a link that can remove a control in a unique

I am facing an issue with generating controls and removing them dynamically. I am trying to include a 'Link' that will trigger a function to remove the dynamically created control. The control and link are placed next to each other. Below is the ...