Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background color inside my <div> element using CSS

Tags:

html

css

I have created a <div> tag css table as required. But I am stuck up at one particular place. I need to fill a background color inside my <div> element. Which attribute is to be used to do so?

My code is as follows:

<htmL>

<head>
    <style>

        div.table{
            display: table;
        }
        div.row{
             display: table-row;
            border-style:solid;
            border-color: black;
            border-width:15px;
            padding-top:35px;
            padding-bottom:35px;
            padding-right:50px;
            padding-left:50px;
            margin-top:25px;
            margin-bottom:25px;
            margin-right:50px;
            margin-left:50px;
        }

        
        div.cell{
            display: table-cell;
            border-style: solid;
            border-width:15px;
            padding-left: 30px;
            padding-right: 30px;
            padding-top: 30px;
            padding-bottom: 30px;
            font-weight:5000;
            font-size:200%;
            
            
        }

    </style>
</head>
<body>
    <div id="table" class="table">
        
        <div id="r1" class="row">
            <div id="sys55" class="cell">55
            </div>
            <div id="sys56" class="cell">56
            </div>
            <div id="sys57" class="cell">57
            </div>
            <div id="sys58" class="cell">58
            </div>
            <div id="sys59" class="cell">59
            </div>
            <div id="sys60" class="cell">60
            </div>
            <div id="sys61" class="cell">61
            </div>
            <div id="sys62" class="cell">62
            </div>
            <div id="sys63" class="cell">63
            </div>
            <div id="sys64" class="cell">64
            </div>
            <div id="sys65" class="cell">65
            </div>
        </div>

        <div id="r2" class="row">
            <div id="sys54" class="cell">54
            </div>
            <div id="sys53" class="cell">53
            </div>
            <div id="sys52" class="cell">52
            </div>
            <div id="sys51" class="cell">51
            </div>
            <div id="sys50" class="cell">50
            </div>
            <div id="sys49" class="cell">49
            </div>
            <div id="sys48" class="cell">48
            </div>
            <div id="sys47" class="cell">47
            </div>
            <div id="sys46" class="cell">46
            </div>
            <div id="sys45" class="cell">45
            </div>
            <div id="sys44" class="cell">44
            </div>
        </div>

        <div id="r3" class="row">
            <div id="sys43" class="cell">43
            </div>
            <div id="sys42" class="cell">42
            </div>
            <div id="sys41" class="cell">41
            </div>
            <div id="sys40" class="cell">40
            </div>
            <div id="sys39" class="cell">39
            </div>
            <div id="sys38" class="cell">38
            </div>
            <div id="sys37" class="cell">37
            </div>
            <div id="sys36" class="cell">36
            </div>
            <div id="sys35" class="cell">35
            </div>
            <div id="sys34" class="cell">34
            </div>
            <div id="sys33" class="cell">33
            </div>
        </div>

        <div id="r4" class="row">
            <div id="sys32" class="cell">32
            </div>
            <div id="sys31" class="cell">31
            </div>
            <div id="sys30" class="cell">30
            </div>
            <div id="sys29" class="cell">29
            </div>
            <div id="sys28" class="cell">28
            </div>
            <div id="sys27" class="cell">27
            </div>
            <div id="sys26" class="cell">26
            </div>
            <div id="sys25" class="cell">25
            </div>
            <div id="sys24" class="cell">24
            </div>
            <div id="sys23" class="cell">23
            </div>
            <div id="sys22" class="cell">22
            </div>
        </div>

        <div id="r5" class="row">
            <div id="sys11" class="cell">11
            </div>
            <div id="sys12" class="cell">12
            </div>
            <div id="sys13" class="cell">13
            </div>
            <div id="sys14" class="cell">14
            </div>
            <div id="sys15" class="cell">15
            </div>
            <div id="sys16" class="cell">16
            </div>
            <div id="sys17" class="cell">17
            </div>
            <div id="sys18" class="cell">18
            </div>
            <div id="sys19" class="cell">19
            </div>
            <div id="sys20" class="cell">20
            </div>
            <div id="sys21" class="cell">21
            </div>
        </div>

        <div id="r6" class="row">
            <div id="sys10" class="cell">10
            </div>
            <div id="sys09" class="cell">09
            </div>
            <div id="sys08" class="cell">08
            </div>
            <div id="sys07" class="cell">07
            </div>
            <div id="sys06" class="cell">06
            </div>
            <div id="sys05" class="cell">05
            </div>
            <div id="sys04" class="cell">04
            </div>
            <div id="sys03" class="cell">03
            </div>
            <div id="sys02" class="cell">02
            </div>
            <div id="sys01" class="cell">01
            </div>
        </div>
    </div>
</body>
</html> 

My Current output is as follows:

Table

I need to fill a 'red' color or a 'green' color inside the white space you can see. Suggest me the best possible options using CSS to do so.

like image 912
bali208 Avatar asked Jan 24 '14 11:01

bali208


People also ask

Can div have a background color?

With Hexadecimal values, you can set a background color for a div or any other element with a total of 6 characters.

What is the correct HTML for adding a background color of a div element?

1 Answer. The correct answer to this question “What is the correct HTML for adding a background color” is option (b). <body bgcolor = “green”>. This is the correct HTML command that is used for adding a background color of choice.

How do I change the color of an element in CSS?

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.

How do you put a background color on the background in CSS?

By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally. Tip: The background of an element is the total size of the element, including padding and border (but not the margin). Tip: Always set a background-color to be used if the image is unavailable.


2 Answers

add background: green; in your div.cell{}

FIDDLE

like image 102
Karuppiah RK Avatar answered Sep 22 '22 14:09

Karuppiah RK


Use background-color: <color>. (https://developer.mozilla.org/en-US/docs/Web/CSS/background-color)

like image 24
darthmaim Avatar answered Sep 22 '22 14:09

darthmaim