[英]CSS Styling, styling children
I am trying to improve my understanding of CSS. 我正在努力提高对CSS的理解。
I have the following HTML table: 我有以下HTML表:
<div class="app-pages validate-email-page" id="containerbg2">
<div>
<form action="<?php echo site_url("/validation-control");?>" method="post" id="dataForm">
<table border='1' class="email-table">
<tr>
<th>First Name</th>
<th>Surname</th>
<th>Email</th>
<th>Sign Up Date</th>
<th>Expiration Date</th>
<th>Roll back user?</th>
<th>Repeat Validation?</th>
</tr>
<?php
$wcl_ci_api->get_page_view_verification_emails();
?>
</table>
<input type="submit" value="Confirm">
</form>
</div>
</div>
</div>
I have the following CSS: 我有以下CSS:
div.validate-email-page table {
text-align: left;
}
From what I understand of the CSS above: 据我对以上CSS的了解:
It is saying that any 'table' within a 'div' with the 'class validate-email-page' 就是说,“ div”中带有“ class validate-email-page”类的任何“表”
Will have the CSS styling applied to it eg all text will be aligned left. 将应用CSS样式,例如,所有文本将向左对齐。
Next, if I want to apply specific styling to parts of the table eg head I can do the following: 接下来,如果要对表的各个部分(例如,head)应用特定的样式,可以执行以下操作:
div.validate-email-page table th{
text-align: left;
}
div.validate-email-page table tr{
text-align: center;
}
And these 2 say: 这两个说:
Center text (Left text) for all rows (headers) in a table within a div with the class 'validate-email-page' div中表中所有类别为“ validate-email-page”的行(标题)的中心文本(左文本)
This all seems to be working fine. 这一切似乎都很好。
My problem is, I want to only centre the checkboxes, which are made by the php and have the class 'checkradio' and type 'checkbox',but so far all my attempts have failed. 我的问题是,我只想将复选框居中,该复选框是由php制作的,具有类“ checkradio”并键入“ checkbox”,但是到目前为止,我的所有尝试均以失败告终。
I have tried lots of different variations, but cannot seem to get it right eg: 我尝试了许多不同的变体,但似乎无法正确完成,例如:
div.validate-email-page table input checkbox{
text-align: Center;
}
I know I am not too far but I cannot work it out and cannot seem to find a clear answer to my problem 我知道我不太远,但我无法解决问题,似乎无法找到解决我问题的明确答案
Preferably I would like to style by column name, so I can change the style of each column based on the column name. 最好是我想按列名设置样式,以便可以根据列名更改每个列的样式。
input checkbox
would match <input> <checkbox> </input>
which isn't something you can have in HTML. input checkbox
将与<input> <checkbox> </input>
匹配,这在HTML中是无法实现的。
If you did select a checkbox, then text-align: center
wouldn't work because there is no text inside a checkbox to centre. 如果您确实选中了一个复选框,则
text-align: center
将不起作用,因为复选框内没有文本可居中。
If you want to centre a checkbox, then you need to select the block element it is inside and then apply text-align
to that. 如果要使复选框居中,则需要选择其内部的块元素,然后对其应用
text-align
。
CSS doesn't have a parent selector , so you can't use the presence of the checkbox to target its parent and select that. CSS没有父选择器 ,因此您不能使用复选框的存在来定位它的父选择器。
You can't align content based on the column either. 您也不能根据该列对齐内容 。
Add the appropriate table cells (the <td>
elements) to a class and use a class selector. 将适当的表单元格(
<td>
元素)添加到类中,然后使用类选择器。
Yes you are close. 是的,你很近。 :)
:)
div.validate-email-page table input.checkradio{
text-align: center;
}
This will applied on the inputs with checkradio class, in the table, within a div with validate-email-page class. 这将应用于表中带有validate-email-page类的div中具有checkradio类的输入。 ;)
;)
Edit: 编辑:
Or you can try the attribute selector: 或者您可以尝试属性选择器:
div.validate-email-page table input[type="checkbox"] {
text-align: center;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.