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 concept of recursion in AngularJS directives

I developed a unique custom directive. angular.module('menu',[]) .directive('MenuDirective',function(){ return{ restrict:'E', replace:'true', scope:{ m ...

Encountering a problem with Selenium when dealing with tabular data displayed in a DIV format on a website, where each row is encapsulated within its own DIV element

While creating Selenium automation tests for a website with multiple rows contained within a main DIV element, each row represented by a separate DIV. For example, if there are 5 dynamically generated rows, the HTML code structure would look like this: < ...

"Preload the search query from the table, link it, and then send it to Ajax for

Currently, I have a dynamically generated table using ajax and a json file. The table consists of three segments: name, ID, and a link for more detailed information on each result. Here is an example of how the table looks: PATO:0001243 light blue ...

Having difficulty locating the login button on the webpage

I am attempting to log into a banking account using selenuim. After opening the webpage and locating the login element, I initially struggled to access it by its "name" or "id." Fortunately, I was able to successfully access it using driver.find_element_by ...

Two rectangular divisions placed next to each other, with one perfectly centered and the height of the second division adjusting to match the height of the

I attempted to implement the Matthew James Taylor method, utilizing three columns. However, my main issue arises when I desire the middle column to dictate the height. In other words, if the center div is 500px in height, I want the right div's height ...

Display animated GIFs in the popular 9Gag format

Is there a way to display a GIF file after clicking on a JPG file, similar to the functionality on 9Gag.com? I am currently using timthumb.php for displaying JPG images. https://code.google.com/p/timthumb/ Below is the code snippet: <div class="imag ...

Eliminate styling from text within an HTML document

I'm currently working on removing text decorations from my text. I managed to remove the underline, but when I hover over the text, the color still appears. How can I get rid of this color as well? Take a look at the code below: messbox { backgr ...

React component is unable to identify prop

I'm attempting to send an array of objects from the main App.js file to a smaller component using props. However, for some reason, the prop is not being recognized within the smaller component file. https://i.stack.imgur.com/WuyFr.png https://i.stac ...

Clicking the popup form causes it to blur out

Having trouble with a blurry pop-up form when clicking the button? Check out the code I've used below: <button class="btn btn-default" data-toggle="modal" data-target="#myModal">ENQUIRE NOW</button> ...

Is there a way to switch an input's appearance to resemble that of a label?

Looking to customize my input fields to resemble labels at first, then apply editable styles with angular.js upon button click. Utilizing bootstrap for my project, wondering if there is a built-in class that can be toggled on and off for these inputs? ...

Sending the value from a for loop through AJAX and populating it into a form field

Currently, I have implemented a piece of JavaScript code that captures user input, sends a request to an endpoint using AJAX, and appends a specific field from the returned results as an option within a datalist. This functionality is working perfectly fin ...

The functionality of jQuery click events seems to be disabled on the webpage, however, it is working perfectly fine on jsFiddle

After thoroughly checking the js tags and ensuring everything is properly closed, it's frustrating when the JavaScript suddenly stops working. The code functions perfectly in JSFiddle, leading me to believe that the issue may lie with something I&apos ...

Creating a PDF from slides using tools like mkd2pdf or wkhtmltopdf has never been easier. This

I am exploring the possibility of creating PDF files using mkd2pdf, a tool based on wkhtmltopdf. Mkd2pdf has the ability to generate PDFs from markdown content and utilizes a CSS file for styling purposes. For example: h1 { page-break-before: always; } ...

What is the best way to address caching fonts and files within CSS?

Utilizing the font icon for displaying icons may result in difficulty when adding new icons to the font due to caching issues. Clearing the cache is often necessary to refresh the display. How can I address this concern? ...

Prevent elements from overlapping within a flexbox container

I've encountered an issue with resizing the window causing the logos to overlap the portrait image. Is there a way to fix the logos relative to the portrait? Below is the code: /* Defaults for Main Part of Pages */ body, div, h1, p { margin: 0; ...

Tips for designing resizable overlay divs

Looking to design an image with an overlay gradient and text, similar to this: <div> <img src="url"/> <div background-image="other url" background-repeat:repeat-x;> <h2>some text</h2> </div> </div> Some impor ...

How can you reposition a component within the dom using Angular?

Just started learning Angular, so I'm hoping this question is simple :) Without getting too specific with code, I could use some guidance to point me in the right direction. I'm currently developing a small shopping list application. The idea i ...

Capture any clicks that fall outside of the specified set

I am facing an issue with my navigation drop down menu. Currently, the pure CSS functionality requires users to click the link again to close the sub-menu. What I want is for the sub-menu to close whenever a click occurs outside of it. I attempted a solu ...

jQuery - patience is required until all elements have completely faded away

I am facing a unique challenge: I need to trigger an action after two specific elements have been faded out simultaneously. The code snippet for this task is as follows: $("#publish-left, #publish-right, #print-run").fadeOut(function(){ //do something ...

Is there a way to sequentially load two iframes, with the second one loading only after the first one is fully loaded

Having two different links that trigger ajax calls can be tricky if only one request is allowed per load. This may result in both iframes displaying the same data. Is there a way to work around this issue? Perhaps loading one iframe first and then triggeri ...