Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply css to first table

Tags:

html

css

See this example: https://jsfiddle.net/kevalbhatt18/w361a9hg/

When you see fiddle first strach result window. otherwise you want see what i want.

My problem is that I crate table and apply css all working fine but now i want to apply border-left: 1px dotted; to only first table.

<div class='openDiv hide'>
    <table id="addPropertyValue1"></table>
    <table id="addPropertyValue2"></table>
    <table id="addPropertyValue3"></table>
    <table id="addPropertyValue4"></table>
    <table id="addPropertyValue5"></table>
</div>

I tried with first-child .but not working

.openDiv :first-child{
        border-left: 1px dotted;
    }

Note : dont apply css on id directly like

.openDiv #addPropertyValue1{
    border-left: 1px dotted;
}

want pure css solution will help me I don't want jquery or javascript to apply dynamic class on table

like image 222
Keval Bhatt Avatar asked Jul 14 '15 08:07

Keval Bhatt


People also ask

How do you select the first table in CSS?

Use first-child for table inside . openDiv . Updated fiddle is here. first-of-type represents the first sibling of its type in the list of children of its parent element, first-child represents any element that is the first child element of its parent.

How do you target first class in CSS?

The :first-of-type selector in CSS allows you to target the first occurence of an element within its container. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.

How do I get CSS only for my first child?

The :first-child selector is used to select the specified selector, only if it is the first child of its parent.

How do I target first TD in CSS?

How to Select the First and Last <td> in a Row with CSS. In this snippet, you can find out how to select and style individual columns of your table, particularly the first and last <td> in the table row. For that, you need to use the child selector pseudo-classes: :first-child and :last-child.


2 Answers

Use first-child for table inside .openDiv.

Like this:

.openDiv table:first-child {
    border-left:1px dotted;
}

Updated fiddle is here.

like image 182
codingrose Avatar answered Oct 11 '22 16:10

codingrose


Apply the css on first child

.openDiv table:first-child{
    border-left: 1px dotted #000;
}
like image 25
Prachi Gharde Avatar answered Oct 11 '22 14:10

Prachi Gharde