Achieving perfect alignment and spacing of columns with HTML/CSS

Just getting started with web development, very new to it. I am in the process of creating a SharePoint site for my workplace using the Modern Script Editor web part. The site will essentially be a resource page with linked buttons on it. I am facing difficulty centering the three columns and ensuring even space between them. Whenever I add more text into the buttons, they overlap each other. Any suggestions or advice would be greatly appreciated. Additionally, I need to include a quick link column on the right side of the page. Is there anything specific I should do differently with it on the HTML side? I understand that the visual appearance will be different for the quick links, so I will focus on the CSS aspect later. Fiddle

CSS

<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    max-height: 100vh;
    background-color: black;
}

header {
    text-align: center;
}

.banner {
    color: #fff; /* Example text color */
}

.banner h1 {
    font-size: 50px;
    margin: 15px;
    padding: 0;
}

.sub-banner{
    display: flex;
    margin-left: 37%;
    margin-right: 33%;
    font-size: 40px;
    flex: nowrap;
    background-color:black;
    color: white;
    border: solid 3px gold;
    border-radius: 5px;
    
}    

.logos {
    display: flex;
    justify-content: space-between;
    text-align: center;
    align-items: center;
    flex-grow: 1;
    
}

.logos a {
    text-decoration: none;
}

.logos a h3 {
    background: black;
    border: solid 3px gold;
    border-radius: 5px;
    padding: 5px;
    color: white;        
        
}

.logos a:nth-child(2) {
 color:black;
}

.logos a img {
    max-width: 300px;
    max-height: 175px;
}

main {
    text-align: center;
    flex-grow: 1;
}

#h3s {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 200px;
        overflow-wrap: break-word;
        justify-content: space-between;
        margin:;
}

#h4s {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 200px;
        overflow-wrap: break-word;
        justify-content: space-between;
        margin:;
}

#h5s {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 200px;
        overflow-wrap: break-word;
        justify-content: space-between;
        margin:;
}

</style>

HTML

<body>
  <header>
    <div>
      <button class="sub-banner">
        Resources
      </button>

    </div>

  </header>

  <main>
    <div class="logos">
      <div id="h3s">
        <a href="">
          <h3>Linked Button sogdfgij fkdjg dfpgj ddfpigj</h3>
        </a>
        <a href="">
          <h3>Linked Buttons idjf sgij sdipgj </h3>
        </a>
        <a href="">
          <h3>Linked Button sogj dfoigj doifgj </h3>
        </a>

      </div>
      <div class="logos">
        <div id="h4s">
          <a href="">
            <h3>Linked Button dofijgodfigj doij </h3>
          </a>
          <a href="">
            <h3>Linked Button pdofg pdofkg pofd kg</h3>
          </a>
          <a href="">
            <h3>Linked Button dpfgj dpiogj dpiogdj p od </h3>
          </a>

        </div>
        <div class="logos">
          <div id="h5s">
            <a href="">
              <h3>Linked Button</h3>
            </a>
            <a href="">
              <h3>Linked Button</h3>
            </a>
            <a href="">
              <h3>Linked Button</h3>
            </a>
           </div>
        </div>
  </main>

Tried setting 33% margins for each column and various adjustments but still facing issues.

Answer №1

I believe you might be complicating things:

  • gap can help define a space between flex items
  • flex-wrap enables items to flow over multiple rows
  • It's important to validate your code, headers should not be nested within anchor tags, and try to minimize the amount of HTML for styling purposes. Use semantic tags whenever possible.

CSS

.logos {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.logos a {
  flex: 1;
  text-decoration: none;
  min-width: 25%;
  background: #000;
  font-size: 1.3em;
  padding: 20px;
  box-sizing: border-box;
}

HTML

<div class="logos">

        <a href="">
          Linked Button description
        </a>
        <a href="">
          Linked Buttons description
       
        <a href="">
          Linked Button description
        </a>


          <a href="">
            Linked Button description
          </a>
          <a href="">
            Linked Button description
          </a>
          <a href="">
            Linked Button description
          </a>

  
            <a href="">
              Linked Button
            </a>
            <a href="">
              Linked Button
            </a>
            <a href="">
             Linked Button
            </a>
           </div>
        </div>

Explore Here

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

Modify the image inside a div when hovering

How can I create a product card that displays thumbnails of images when hovered over, and changes the main image to the thumbnail image? My current challenge is getting this functionality to work individually for each card on an e-commerce site. Currently, ...

Adjust the height of the container div for the carousel according to the length of the text displayed

My image carousel features description content positioned on the right for wide-screen windows. However, I want the description to shift below the images when the browser window reaches a certain breakpoint. The challenge I am facing is that the height of ...

Two elements occupy the rest of the vertical space

In the center, there is a div with content inside. I want the top and bottom divs to occupy the remaining space. Similar to this example <div class="container"> <div class="top"> </div> <div class="middle"> C ...

Using Python to interact with website dropdown menus without relying on Selenium

Is there a Python library available that can assist me in opening a web page, selecting options from drop-down lists, and performing clicks without relying on Selenium? ...

Upon executing `$('div')`, an empty array is returned

My goal is to retrieve all the div classes on a page using jQuery $('div');. However, the page does not natively support jQuery, so I am loading it through external links until $ === jQuery evaluates to true. Even on Stack Overflow where jQuery ...

How can CSS be used to make an element completely move off the visible screen?

Imagine if I had a div that was positioned outside of the visible area of the computer monitor screen. When using CSS transitions to move it to a specific position, it would create an effect of the element slowly moving in from outside of the screen. Add ...

Adjust the dimensions of the thead, tbody, and td elements on the fly

I've implemented this property in a .css file on the table shown below and there are 9 records. .fixed tbody td, thead th { width: 5.2%; float: left; } In my scenario, when there are 4 columns, the width should be 23.2%; for 5 columns ...

Using HTML to execute a JavaScript function that transforms images

The script cutImageUp has been previously discussed on SE in a thread about Shattering image using canvas. However, I have encountered a different issue while attempting to use it. The HTML code I implemented seems to be ineffective, and despite my efforts ...

Highlight text when the user is scrolling the page - using JQUERY

Can anyone suggest a way to dynamically underline text as the user scrolls down a webpage? The underline should only be visible while the user is scrolling. I've experimented with animate.css and other plugins, but haven't been able to achieve th ...

Customizing the appearance of checkboxes in React Material-Table filtering feature

Is there a way to modify the style of checkboxes in filtering? For instance, if I wish to adjust the dimensions of the checkbox that appears for the Birth Place field, what steps should I take? https://i.stack.imgur.com/pZLqQ.png ...

What could be causing the DIV elements to not align side by side?

<div id="dvFirst" class="mainSecond" style="background: #6FA5FD;"> <div id="leftdiv3" class="leftdiv">Client: </div> <div id="rightdiv3" class="rightdiv"><asp:DropDownList ID="ddlCliNewMsg" AutoPostBack="t ...

Tips on displaying dynamic content on a single page with AngularJS 1.6

Just getting started with Angular and looking for a way to display dynamic content from a JSON file using AngularJS 1.6? Here's an example to help you out. News.json { "Articles": [ { "Title": "News 1", ...

choose a distinct value for every record in the table

My goal is to only change the admin status for the selected row, as shown in the images and code snippets below. When selecting 'in-progress' for the first row, I want it to update only that row's status without affecting the others. <td ...

Ensuring that the text input is perfectly lined up with the submit button

Is there a way to solve this discrepancy? Solution: https://jsfiddle.net/6q352ysx/59/ The elements are currently the same height, but not aligned properly. https://i.stack.imgur.com/ajVyJ.png Which alignment option should I use? Option 1: vertical-ali ...

What is the proper way to safely escape a JSON string for an object that contains user-generated content?

How can I correctly use the variable s for the value-field of an option-element while escaping user input used for key and value? var key='highway'; var value='track'; var s = JSON.stringfy({ [key]:value }, undefined,''); s ...

Prevent the cursor from exiting the div element when the tab key is pressed

Currently, I have implemented a search input box allowing users to either enter a value or select from a list of suggestions. The issue arises when the user selects an option using the tab key, as it causes the cursor to move outside the input box despite ...

When text is inserted into an inline-block div, it causes the div to shift downwards in

Consider the following HTML code snippet: <div class="one"> Test </div> <div class="two"> </div> <div class="three"> </div> If we apply the following CSS styles: div { display:inline-block; height:30px; ...

Unable to hear sound - JavaScript glitch

Spent countless hours trying to figure this out - Can't get the audio file to play when clicking an HTML element. var sound = document.querySelector(".soundfile"); function playAudio() { sound.play(); } document.querySelector(".btn-hold").addE ...

I need to position the CSS vertical scrollbar on the right side of the page

I can't figure out how to move the vertical scrollbar to sit on the right side of my site's work page. Any help would be greatly appreciated. Below is the provided HTML code: <div class="heading"> <h1>PRINT</h1> &l ...

CSS declarations that have not been acknowledged or acknowledged

While working on a client's stylesheet today, I came across the following code: p { -webkit-hyphens: auto; -webkit-hyphenate-character: "\2010"; -webkit-hyphenate-limit-after: 1; -webkit-hyphenate-limit-before: 3; -moz-hyphens: manual; orphans: ...