Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I centre this checkbox?

Tags:

css

I have a table, one column of which contains only a checkbox and I am currently centering these with

<td style="text-align:center; vertical-align:middle;">
  <input type="checkbox" name="xyz">
</td>

Now I want to add some JS to (de)select all/none, so I want to add a checkbox in my table header row, along with some text

TH is, by default, bold and I am happy leave it so for actual Column header text, bu I was normal text for the "all/none" and then I want a centered checkbox below that.

----------------  
| Search ?   | Next column  
| (all/none) |  
|   [x]      |  

here's my code - how do I get that checkbox to center?

<th>Search?<br>    
    <span class="th_not_bold">(all/none)</span><br>    
    <input style="text-align:center; vertical-align:middle" type="checkbox" name="search_all" id="search_all" onClick="ReportAllNoneClicked()">  
</th>
like image 753
Mawg says reinstate Monica Avatar asked Nov 18 '11 03:11

Mawg says reinstate Monica


People also ask

How do you align a check box?

Put each checkbox and label within an <li> element. Add overflow:hidden to the <li> and float the label and checkbox left. Then they all align perfectly fine.

How do I move a checkbox to the center in CSS?

In this method, we are using the display FlexBox property to center the checkbox in the cell of the table. Output: Method 2: In this method, we will be using Text align center property of the CSS to center the checkbox in the cell.

How do I change the position of a checkbox in HTML?

Use the :checked pseudo-class, which helps to see when the checkbox is checked. Style the label with the width, height, background, margin, and border-radius properties. Set the position to "relative". Style the "checkbox-example" class by setting the display to "block" and specifying the width and height properties.

How do I align a checkbox horizontally?

Set the checkbox horizontally by including the data-type = "horizontal" to the fieldset. You can select the checkbox button more than one at a time.


1 Answers

try using

<th> 
<td style="text-align:center; vertical-align:middle;">
<div>Search</div>
    <div class="th_not_bold">(all/none)</div>
    <div><input style="text-align:center; vertical-align:middle" type="checkbox" name="search_all" id="search_all" onClick="ReportAllNoneClicked()"> </div>
</td>
</th>
like image 118
Varun Avatar answered Oct 07 '22 15:10

Varun