-1

Initially, I can't change the class name for instance:

<table class="firsttable"> This is the firstable that must be left align
<tbody>
    <tr>
        <td>

<table class="firsttable"> And this is the second table that must be center align
<tbody>
    <tr>
        <td>

How do I code it in css?

NachoB
  • 337
  • 4
  • 15
user1983152
  • 67
  • 1
  • 2
  • 14
  • have you tried the selector + or ~ to update CSS of second table ? such as `.firsttable +.firsttable {text-alig:center}` – G-Cyrillus Nov 23 '16 at 17:36
  • Possible duplicate of [Align two inline-blocks left and right on same line](http://stackoverflow.com/questions/10272605/align-two-inline-blocks-left-and-right-on-same-line) – user1983152 Dec 23 '16 at 15:56

5 Answers5

1

You can use below CSS, It works as intended

<style>
.firsttable:nth-child(1) { text-align:left; }
.firsttable:nth-child(2) { text-align:right; }
</style>

It's CSS3 though.

Nikunj Sardhara
  • 638
  • 1
  • 5
  • 20
0

First table CSS selector:

.firsttable:first-of-type

If second table is last:

.firsttable:last-of-type

Otherwise, second table CSS selector is this:

.firsttable:nth-of-type(2)
hopkins-matt
  • 2,763
  • 2
  • 15
  • 23
0

Use ids:

HTML:

<table class="firsttable" id="table1">
...
</table>
<table class="firsttable" id="table2">
...

CSS:

#table1 {
    text-align:left;
}
#table2 {
    text-align:right;
}

Does this work?

AAM111
  • 1,178
  • 3
  • 19
  • 39
-1

In this case it is better or from my sense I always make it by adding an inline style in the table and I think their no need to create any other style for it in CSS.

<table class="firsttable" style="text-align:left"> This is the firstable that must be left align

And the second table may be another inline style of text-align:center

<table class="firsttable" style="text-align:center"> And this is the second table that must be center align

It is the best approach. But you can also can create some different id here or

 .firsttable:nth-child(1) { text-align:left; }
 .firsttable:nth-child(2) { text-align:center; }

Problem in this is if you use it then if another table appear in this web page area than it will arise a problem. So it is better to use inline style in this case.

Maniruzzaman Akash
  • 4,610
  • 1
  • 37
  • 34
-1

If you want to move the table to the left and one to the right add the following to the appropreate table.

For the align right. Add this at the opening tag <table>.

style="float:right;"

For the algin left add the same code to the exactly same place but change the "left" to "right" depending on where you want it to be.

To aling text do as the other people have seggested.

J. Carter :)

J. Carter
  • 19
  • 1
  • 6