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

Is there a way to use Jquery to determine if a parent div contains a scroll

I'm trying to find a jQuery example that checks if any parent div has a scroll bar, but I can't seem to locate a helpful one. Here is the code snippet I am working with: <div> <div class="heading"> <div class="visit ...

Feature exclusively displays malfunctioning image URLs for the web browser

Hello everyone! I've been diving into learning JavaScript and recently attempted to create a function that randomly selects an image from an array and displays it on the browser. Unfortunately, despite my efforts, all I see are broken link images. Her ...

IE9 crashes when displaying elements with float:left style

After clicking the "off" and then "on" hyperlink in the provided HTML snippet, IE9 crashes. Here is the simplified version of the code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD& ...

Modifying the Color of Individual Items within the Pagination Component in MUI

I am attempting to modify the background color of every item in my Pagination component by utilizing makeStyles. import { Pagination } from "@material-ui/lab"; import { makeStyles } from "@material-ui/core"; const pagination = makeStyl ...

Having trouble with CSS messing up your gridview button display?

Oddly enough, whenever I place buttons inside a gridview, they end up looking very small (as shown in the image below), even though the gridview itself has no CSS applied to it. Is it possible that some other CSS is affecting the buttons? I have too much ...

Tips for inserting an element in the middle of two elements using HTML

Here is the current structure of my DOM: <body> <h1> </h1> <button> </button> <p> </p> I am trying to dynamically add another p element in between the button and the existing paragraph when the button is cl ...

JavaScript Error: Unable to determine the value of a null property

Is there a way to validate the user's input in real-time on an HTML form? Take a look at the following HTML code: <div class="col-md-2"> <input class="form-control" name="nbequipement" id="nbequipement" placeholder="" type="text"> ...

Creating a personalized, perfectly centered container with a specific width in Twitter Bootstrap

I've been struggling with a unique challenge for the past day without success. I can't seem to figure out where I am making a mistake. My goal is to design a fixed container layout using Bootstrap, which is precisely 33em wide and horizontally c ...

What is the method to create a link that doesn't take up the entire page?

As a beginner in HTML, I have been working on a website for fun and facing an issue with buttons. When I add a button, the entire area becomes clickable, even if there is empty space around it. This means that you can click on the left or right side of the ...

Organizing content into individual Div containers with the help of AngularJS

As someone who is new to the world of AngularJS, I am currently in the process of learning the basics. My goal is to organize a JSON file into 4 or 5 separate parent divs based on a value within the JSON data, and then populate these divs with the correspo ...

Create dynamic and interactive content by embedding text within SVG shapes using the powerful D

How can I write text into an SVG shape created with d3.js and limit it to stay inside the shape similar to this example http://bl.ocks.org/mbostock/4063582? I attempted to use a clipPath following the example provided. However, when inspecting with firebu ...

Problem with the overflow setting of a specific div

My website is currently hosted on a test server at medexcel.comeze.com. However, I am encountering an issue where the overflow of the top div is no longer hidden when I hover over a menu button in the top bar. This results in the bottom right corner of th ...

Centering multiple floated divs using bootstrap

Looking for some help with a bootstrap panel design. I am trying to align a heading title to the left and a select element along with a date range input to the right of the panel heading, vertically aligned in the middle. While I have made progress on this ...

Having trouble accessing DOM elements in Durandal

Running on Durandal, this mobile app features names and images on an HTML page. The function below helps format the page: define(function (){ function getAutors(myUrl) { $.ajax({ type: "GET", url: myUrl, data: { num ...

Aligning SVG shapes within each other

I recently encountered a scenario where I needed to position SVG shapes in the center of each other with varying scales. For instance, placing a rectangle or triangle within the center of a circle. While I found some solutions that worked for shapes like ...

Numerous HTML documents being uploaded to the server for a multitude of individuals

Currently, I am developing a game on a website where players create new rooms and are assigned specific roles with individual powers. Some players need to wait for input from others, creating a dynamic gameplay experience. Additionally, there are certain ...

Can one customize the background color of a segment in a radar chart using Chart.js?

Could I customize the color of the sectors in my radar chart to resemble this specific image? https://i.stack.imgur.com/U8RAb.png Is it feasible to achieve this using Chart.js? Alternatively, are there other chart libraries that have this capability? It ...

What is the best way to save variables in PHP for later use in various scripts?

As a newcomer to PHP programming, I am facing a rather simple issue that I haven't been able to solve despite trying various methods and searching online for a solution. Any assistance you can provide would be greatly appreciated. The problem at hand ...

Obtaining the source id using HTML5 Drag & Drop functionality

Is there a way to retrieve the id of the div I am dragging from, similar to how it is demonstrated here? Your insights are greatly appreciated. Thank you. ...

Ways to position a DIV on the right side of the screen using percentage margin to adjust its distance from the edge as the browser is resized

Allow me to provide a clearer explanation here: Imagine an element placed on a webpage with a margin of 10% from the left side. When the size of the page is adjusted, the margin on the left decreases accordingly - for example, 10% from 1400px - 140px, and ...