Tips for positioning buttons using HTML and CSS

Looking for some help with my HTML page design. I have a few buttons that I want to style like this:

https://i.stack.imgur.com/3UArn.png I'm struggling with CSS and can't seem to get them positioned correctly. Currently, they are displaying "below the blue line" like this:

https://i.stack.imgur.com/JcDAu.png Below is a snippet of my HTML code:

  <div class="module form-module">
    <div class="flex-container">
      <article class="article">
        <table>
          <tr>
            <td>
              <button>Configurations</button>
            </td>
            <td>
              <button>Create User </button>
            </td>
            <td>
              <button>Update User</button>
            </td>
            <td>
              <button>Create Group</button>
            </td>
            <td>
              <button>Update Group</button>
            </td>
          </tr>
        </table>
      </article>
    </div>
  </div>

You can view my CSS code in this plunker: https://plnkr.co/edit/sCcBBFfWRiCwGz8hs8oR?p=catalogue

If you have any suggestions on how to fix this issue, please let me know!

Answer №1

CSS modifications:

.form-module {
    border-bottom: 5px solid #33b5e5;
    position: relative;
    background: #ffffff;
    width: 100%;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
    margin: 0 auto;
    align: right;
}

.flex-container > * {
    padding: 15px;
    -webkit-flex: 1 100%;
    flex: 1 100%;
}

table {
  border-spacing:0px;
}

td {
  padding:0px;
}

Explanation of Changes:

The blue line serves as a border and was initially set at the top of the button's parent container instead of the bottom, hence the first modification.

Adjusted the padding to eliminate space between buttons and container edges, that's the second change, set it to 0px.

Both the table and button had a 1px border which was separating them from the container edges, hence the third adjustment to set those borders to 0px.

Additional tip:

If you're not already using it, utilizing browser inspector can be beneficial in understanding CSS behavior. Consider Bootstrap for a quicker solution without starting from scratch. It could save you a significant amount of time.

Best wishes.

In case needed, here's the complete updated CSS:

body {
  background: #e9e9e9;
  color: #666666;
  font-family: 'RobotoDraft', 'Roboto', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

table {
  border-spacing:0px;
}

td {
  padding:0px;
}

.pen-title {
  padding: 50px 0;
  text-align: center;
  letter-spacing: 2px;
}

/* Additional styling goes here */


UPDATE: You specified that the buttons should be positioned outside and above the form-module, necessitating a change in the HTML structure rather than just the CSS. We've removed the flex-container div nested inside the form-module div and relocated it after this container is closed. Since the buttons were styled based on .form-module properties, we created a new class "buttons". This ensures form-module and buttons have distinct style properties since they are in separate containers now.

To comprehend how blocks function within containers, reference: http://www.w3schools.com/html/html_blocks.asp

Updated HTML:

<div class="flex-container buttons">
  <article class="article">
    <table>
      <tr>
        <td>
          <button>Configurations</button>
        </td>
        <td>
          <button>Create User </button>
        </td>
        <td>
          <button>Update User</button>
        </td>
        <td>
          <button>Create Group</button>
        </td>
        <td>
          <button>Update Group</button>
        </td>
      </tr>
    </table>
  </article>
</div>
 <div class="module form-module">
 </div>

Revised CSS:

body {
  background: #e9e9e9;
  color: #666666;
  font-family: 'RobotoDraft', 'Roboto', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.buttons table {
  /* Styling details */
}

.buttons td {
  /* Styling details */
}

.buttons input {
  /* Styling details */
}

/* More styles go here */

Complete revised CSS:

body {
  background: #e9e9e9;
  color: #666666;
  font-family: 'RobotoDraft', 'Roboto', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.buttons table {
  /* Updated table styling */
}

.buttons td {
  /* Updated cell styling */
}

.buttons input {
  /* Adjusted input styling */
}

/* Other CSS rules continued... */

Answer №2

Perhaps consider using a 'list' HTML element like ul or li instead of a 'table'.

Check out the plunker here

Updated HTML:

<div class="module form-module">
    <div class="flex-container">
      <article class="article">
        <ul>
            <li>
              <button>Configurations</button>
            </li>
            <li>
              <button>Create User </button>
            </li>
            <li>
              <button>Update User</button>
            </li>
         </ul>
      </article>
    </div>
  </div>

Include the following CSS for styling:

ul{
  list-style-type:none;
  width:500px;
}

li{
  width:33%;
  text-align:center;
  float:left;
  border-bottom:2px solid #33b5e5;
}

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 show an HTML response from an API call on the DOM?

After making an API call, I receive the following HTML response and I am trying to display it on the DOM as actual HTML tags, rather than just showing text with HTML tags. API response: <strong>Hello</strong> Current DOM rendering: <str ...

Using Tailwind CSS to set the margin of an element at certain breakpoints is not functioning as expected

I attempted to customize the margin of a div element at specific screen sizes by using a {screen}: prefix, but it did not have the desired effect. Here is what I tried: <div className={'flex justify-center'}> <div className={'w-fu ...

Create copies of Div elements for them to revert back to their original state following

It seems like a simple task, but I'm struggling to figure out how to do it. On a single page, I have multiple divs: <div id="playerid-1"><a href="javascript:loadplayer(1);">[LOAD PLAYER]</a></div> <div id="playerid-2">& ...

Is it possible to set the input form to be read-only?

I need to create a "read-only" version of all my forms which contain multiple <input type="text"> fields. Instead of recoding each field individually, I'm looking for a more efficient solution. A suggestion was made to use the following: <xs ...

What is preventing the buttons from filling the entire space of the parent element in this case?

https://i.stack.imgur.com/kbiWi.png I'm trying to figure out how to make the Repos and Stars buttons fill the entire height of their parent container, similar to the Github icon. Unfortunately, the code below is not achieving this effect. I attempted ...

Unveiling the Mystery: Why YUI-3 Grids & Google Chrome Cause Overlapping Texts

Although I'm not well-versed in UI design, I find myself having to work on some CSS for a side project. Currently, I am utilizing YUI-3 files such as grids, reset, and fonts, all version 3.9.1. The main issue I am encountering is that the text inside ...

Animation in CSS Appears Jumpy in Chrome

For some reason, the text inside a moving div (which is transitioning using CSS) seems to jitter and shake in Chrome. However, this issue does not occur in Firefox, where the movement is very smooth and achieves the desired effect. #hidexpert { display: b ...

Is there a way to switch between showing and hiding all images rather than just hiding them one by one?

Is there a way I can modify my code to create a button that toggles between hiding and showing all images (under the user_upload class), instead of just hiding them? function hidei(id) { $('.user_upload').toggle(); Any suggestions would be grea ...

Scrolling horizontally with scrollbar functionality

My goal is to create a webpage with a horizontally scrollable DIV element in the center, where the scrollbar appears only at the bottom of the DIV, not at the bottom of the entire page. I am wondering if it is possible to have a scrollbar placed at the ve ...

Modifying website elements with JavaScript

Can someone assist me with getting a script to work on my website that will allow me to switch between four different sets of content using buttons labeled 1, 2, 3, and 4? I have tried using addClass and removeClass but cannot seem to get it right. Here i ...

What can be done to stop Bootstrap columns from shifting positions or stacking on top of each other unexpectedly?

I'm currently working on a testimonial section for my project. The challenge I'm facing is that the content within the 4 divs is not evenly distributed. As a result, when I try to adjust the width of the screen and expect them to align in a 2-2 f ...

The code for the submit button functions properly in Firefox, but encounters issues in Internet Explorer

While this code functions correctly in Firefox, it fails to work in IE8. <a class="sub"> <input type="submit" a="" none;<="" display:=""> </a> Although the button appears on the page, it is not clickable in IE8. Can you help explain ...

When we typically scroll down the page, the next section should automatically bring us back to the top of the page

When we scroll down the page, the next section should automatically bring us back to the top of the page without having to use the mouse wheel. .bg1 { background-color: #C5876F; height: 1000px; } .bg2 { background-color: #7882BB; height: 1000px; } .bg3 ...

Enhance your website design with Bootstrap's unique styling for jumbotron elements

I am currently working on developing a mobile website for calendar events and I need some help. Here is the basic version of the site that I have created so far: The issue I am facing is that the purple backgrounded areas only cover the text, rather than ...

A flex container containing two divs each with a white-space:nowrap element set at 50% width

How can I create a parent div that contains two child divs, each with a width of 50% that adjusts based on content? The issue arises when one of the child divs has an h3 element with white-space:nowrap;, causing it to exceed the 50% width. I attempted to ...

Issues have arisen in IE8 with the background gradient on hover elements in the menu, while it functions properly in all other web browsers

Welcome to the website: I've recently taken on a project involving the gradiated menu on this site. The menu works flawlessly in Firefox, Chrome, and Safari - the hover effect changes the background color to a light gradiated green. However, when it ...

Selenium - Struggling to locate elements that are undeniably present on the website

I started a fun side project to automate tasks on the website using Selenium to automatically complete all achievements. You can check out my code on GitHub: https://github.com/jasperan/pyfastfingers However, I've run into an issue with the login pa ...

What is the method for creating a URL (link) that simulates entering text into a text box and then pressing a button?

There is a button on a 3rd party homepage that goes by the code: <INPUT class="widget-content" TYPE="TEXT" onchange="javascript:document.foo.submit();" NAME="RegExRef"> I am looking to automate the task of populating the text box and clicking the b ...

When attempting to click on my subtopics using jQuery, they do not appear as expected

$(document).ready(function () { $("#subTopics").hide(); $("#mainTopics").click(function () { $("#subTopics").show("slow"); }); }); body { margin: 0; } li, a{ text-decoration: none; list-style-type: none; text-d ...

Using jQuery to target nested HTML elements is a great way to efficiently manipulate

Within the code below, I have a complex HTML structure that is simplified: <div id="firstdiv" class="container"> <ul> <li id="4"> <a title="ID:4">Tree</a> <ul> <li id="005"> ...