What is the best way to align a table (datatable) to the left?

How can I align the table to the left without using float:left in the following code? Applying text-align: left to the parent element of the table doesn't seem to work as expected.

http://jsfiddle.net/william/B4qJG/1

HTML:

<div class="valueList">
 <div class="valuePair">
   <label>Assets</label>

  <div>
    <div>
      <div class="dataTables_wrapper">
        <table cellspacing="0" style="border-collapse:collapse;" class="display">
          <thead>
            <tr>
              <th scope="col" class="sorting_asc" style="width: 406px;">Name</th>

              <th scope="col" class="sorting" style="width: 440px;">AssetNumber</th>

              <th scope="col" class="sorting" style="width: 305px;">Action</th>
            </tr>
          </thead>

          <tbody>
            <tr class="odd">
              <td class=" sorting_1">Chair</td>
              <td>2323424</td>
              <td><a href="#">Remove</a></td>
            </tr>

            <tr class="even">
              <td class=" sorting_1">Table</td>
              <td>34345345</td>
              <td><a href="#">Remove</a></td>
            </tr>
          </tbody>
        </table>
      </div>
    </div><input type="button" value="Add Asset" />
  </div>

  <div class="clear"></div>
</div>
</div>

CSS:

.valueList
{
    width: 100%;
    text-align: left;
}

    .valueList .valuePair
    {
        width: 100%;
        padding: 0.3em 0;
        border-top: 1px #eee solid;
    }

    .valueList .valuePair *
    {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
        -webkit-box-sizing:border-box;
    }

    .valueList .valuePair:first-child
    {
        border-top: 0;
    }

        .valueList .valuePair > div, .valueList .valuePair > label
        {
            float: left;
            padding: 0.3em 0;
            line-height: 2em;
            border: 1px solid transparent;
        }

        .valueList .valuePair > *:first-child
        {
            width: 20%;
            /*margin-right: 1%;*/
            padding-right: 1%;
            font-weight: bold;
        }

        .valueList .valuePair > * + div
        {
            width: 75%;
            border-color: white;
            padding-left: 1%;
        }

        .valueList .valuePair > div.clear
        {
            padding: 0;
            border: 0;
            height:0;
        }

            .valueList .valuePair > * + div > input[type=text],
            .valueList .valuePair > * + div > textarea
            ,.valueList .valuePair > * + div > select
            {
                width: 100%;
                max-width: 350px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -webkit-box-sizing:border-box;
            }
            .valueList .valuePair > * + div > input[type=radio],.valueList .valuePair > * + div > input[type=checkbox]
            {
                width: auto;
            }


table.display {
    width: 60%;
}

.dataTables_wrapper {
    text-align: left;
}

Answer №1

table.display {
    width: 60%;
    margin: 0;  /* <- this setting suits my needs ****/
}

Answer №2

Perhaps this could be a solution.

position:relative;
z-index:3;
left:50%;
top:50%;

Adjust the left and top % values according to the desired position of your table.

Answer №3

To make adjustments in the HTML code, modify these lines to ensure Margin-Left is set to 0.

.main-container {
  max-width: 940px;
  margin-left: 0;
  margin-right: auto;
}

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

The Angular Ivy strictTemplates error message states that the type 'Event' cannot be assigned to the type 'InputEvent' parameter

I'm feeling lost trying to figure out what's wrong with this code snippet: <input #quantity type="number" matInput formControlName="quantity" (input)="onQuantity($event, i)" placeholder="Quantity"/> onQuantity(event: InputEvent, i: number ...

What is causing the slider image to be the only element that is not adapting to different screen sizes?

I am currently using the flexslider from woothemes and I am unable to understand why the image is consistently wider than the content when the browser window is resized or when viewed on an iPad/iPhone. Upon inspection, I couldn't find any styles on ...

What is the best way to transform Adobe XD designs into HTML and CSS with Vue.js?

I am looking to create a single page application with vue.js and came across this helpful reference at . A colleague has created a prototype using Adobe XD, and now my task is to transform it into HTML/CSS while making it functional and connecting it to an ...

Floating footers with centered content - they remain aligned in the center even when zoomed out

Behold my unique and straightforward footer design (100% zoom above, 70% zoom below) : To keep things simple, I aimed to center content with a single div having a fixed width and margin: 0 auto, all while maintaining the same color for the outer footer la ...

New to the world of web design and seeking answers as to why my style is not being applied

After diligently following the courses on CodeAcademy (I know, kind of lame but it's a start), I finally feel confident in my ability to write my own HTML and CSS code. However, when I tried to do so using Sublime Text 3 and opened my HTML file, I not ...

What could be causing the extra space at the top of my div element?

My goal is to accomplish the following: However, there appears to be an unnecessary gap above the Social icons div. You can view the live page at This is my current markup:- <header> <img src="images/home-layout_02.jpg" alt="Salem Al Hajri Logo ...

In order to verify the dynamic components within the table

I need assistance with validating dynamically created textareas. In the code below, I am able to validate only the first row but struggling to do so for the second row. How can I get all the row values validated? Thank you in advance. To generate dynamic ...

Steps to vertically shift an image downwards within a navigation bar using HTML and CSS

Currently, there is a fully functional navigation menu that can be toggled within a webpage. An image is also included in the navigation menu and positioned below the text. I would like to move the image to the very bottom of the navigation menu to remove ...

Arranging two classes in close proximity

I need help aligning two classes that are stacked on top of each other to be displayed side by side. Below is a screenshot of the two classes: https://i.sstatic.net/V0tLL.png The right class is .testm_boxes1, and the left class is .testm_boxes2. Here is ...

What is the best way to end a table row after every group of four items?

I am working with a Handlebars template to display an array of movies in a table with four columns. Currently, I have set up a HBS helper in my code: app.engine('handlebars',exphbs({ defaultLayout: 'main', helpers: { n ...

Smart method for repositioning multiple elements on the display

Imagine we have multiple divs displayed on a screen: https://i.stack.imgur.com/jCtOj.png ...and our goal is to move them collectively, either to the left: https://i.stack.imgur.com/KBfXC.png ...or to the right: https://i.stack.imgur.com/c1cUw.png An ...

Trouble with Updating Div Content?

Within my HTML code, I have included this JavaScript snippet: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <script> var auto_refresh = setInterval( function() { $('#loaddiv').fadeOut ...

What is the best way to horizontally align my div content while ensuring it is responsive, alongside a sidebar and top menu on the same

I am facing an issue trying to center my div content responsively with a sidebar menu and a top menu using Bootstrap. However, when I require the side-menu file, my div content gets placed at the bottom of the page unexpectedly. I am only using Bootstrap 5 ...

The transparency of the text in my navbar is glitching when I scroll down

I'm experiencing an issue with my navbar text becoming translucent when scrolling. How can I fix this problem? Check out the picture below for more details. ...

Incorporating an image as a clickable element instead of a traditional button using HTML and

Here's the issue at hand: I currently have "+" and "-" icons at the end of each row to add and delete rows as needed. However, I would like to replace the "-" icon with a trashcan symbol instead. I attempted to do this by replacing it with an image s ...

Guide to aligning a URL in an HTML file

Greetings all, I'm new to HTML and struggling with how to center a URL on my webpage. For example: <a href="http://www.google.com"> Click Here to Open Google </a> I attempted using the tag and the STYLE attribute but without success. ...

Exploring the World of 2D Array Animation

I'm in the process of creating a Pacman ghost using visual 2D arrays. I would like the ghost to move similar to this: https://i.sstatic.net/KPmUt.gif I am considering implementing CSS transitions for the movement, but I'm unsure about how to do ...

Issue with setting HTML content using jQuery's .html() method

I have a simple functionality. When a user clicks on the edit link, it transforms the previous element into an input element for editing, and changes the edit link into a cancel link. If the user decides not to edit, they can click on cancel and everything ...

Is there a way to display a loader when an item is selected from a dropdown menu? For example, while data is being fetched from the backend, can we

This is the HTML form division I have created: <div class="col-lg-2 "> <select name="limitCount" id="limitCount" ng-model="limitCount" class="form-control col-md-2 panel-refresh" ...

Borders are absent on several div elements

There is a strange issue I'm facing where some borders on identical divs are not showing up. I have spent hours trying to troubleshoot this problem, and it seems like zooming in or out sometimes makes the border appear or disappear. My hunch is that i ...