简体   繁体   中英

Child element styling CSS

I have a div with the id = Body and inside this div i have another div with the id = TableWrapper_Wrapper witch acts as a table for jQuery datatables.

I would like to apply styling to this table.

In my CSS file i have styling added to the body div which works and styling for the TableWrapper_Wrapper which does not work.

body 
{
    font-size: 100%;
    background:#F1F1F1;
}

TableWrapper_wrapper
{
    font-size: 12px;
    white-space: nowrap;   
}

Below is a screen shot of the consloe so you can see the name of the table.

在此输入图像描述

Could someone please tell me how i could add some styling to this table.

在此输入图像描述

TableWrapper_wrapper is the id of a div, so you need to use the id-selector (prefix # to the id` - read about css selectors

#TableWrapper_wrapper
{
    font-size: 12px;
    white-space: nowrap;   
}

It should be

#TableWrapper_wrapper
{
    font-size: 12px;
    white-space: nowrap;   
}

Because TableWrapper_Wrapper is an id not an tag .You can also style them using classname with TableTables_wrapper like

.TableTables_wrapper
{
    font-size: 12px;
    white-space: nowrap;   
}

i recommend you not to use keywords like body as an id of any other tag. and the styling you given

body 
{
    font-size: 100%;
    background:#F1F1F1;
}

in stylesheet if you call body without '#' or '.', it will be considered as body tag

<body></body>

, and the style you write there apply to whole body.. thats why your style is working. and

TableWrapper_wrapper
{
    font-size: 12px;
    white-space: nowrap;   
}

this is not the method to call an id, use hash prefix like this. '#TableWrapper_wrapper'.

#TableWrapper_wrapper
    {
        font-size: 12px;
        white-space: nowrap;   
    }

and for classes use dot prefix, like this '.TableWrapper_wrapper'.

You need to put '#' as for ID selector in CSS. And body tag is already in html structure so no need to use body as a id. you can try below code

body {font-size: 100%; background:#F1F1F1;} 
#TableWrapper_wrapper{font-size: 12px; white-space: nowrap; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM