Surya Kasturi
Surya Kasturi

Reputation: 4753

How to add background image or color on padding

<body>
<div class="container">
    <div class="navbar1 navbar navbar-inverse">
        <div class="navbar-inner">
            <ul class="nav pull-right">
                <li><a href="#">sign in</a></li>
            </ul>
        </div>
    </div>
</div><!--/container NAVBAR-->

<div class="container">
    <div class="row-fluid">
        <div class="header">
            <div class="span12">
                <h1> Hello World</h1>
            </div>
        </div><!--/inner-wrapper-->
    </div><!--/row-fluid-->
</div><!--/container-->
</body>

EDIT

In this classes like span**, navbar, row-fluid, container create default padding.

Take a look into this page: http://jsfiddle.net/SjYyj/1/

There is a gap between "header" class and "navbar"! How to remove that without adjusting padding!

Upvotes: 0

Views: 1327

Answers (1)

funerr
funerr

Reputation: 8166

Edit - Update:
Well, you basically want the padded area to have a background color, without changing the padding.
The simplest solution I could think of is:
Wrap the whole 'back end' with a fixer class, and give it a background color.
html:

<!DOCTYPE html>
<hhttp://jsfiddle.net/SjYyj/#forktml lang="en">

    <head>
        <title>Home</title>
        <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css"
        rel="stylesheet">
    </head>

    <body>
        <div class="fixpadding"><!--Fixer-->
            <div class="container">
                <div class="navbar1 navbar navbar-inverse">
                    <div class="navbar-inner">
                        <ul class="nav pull-right">
                            <li><a href="#">sign in</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <!--/container-->
            <div class="container">
                <div class="row-fluid">
                    <div class="header">
                        <div class="span12">
                                <h1> Hello World</h1>

                        </div>
                    </div>
                    <!--/inner-wrapper-->
                </div>
                <!--/row-fluid-->
            </div>
            <!--/container-->
        </div>
        <!--End Fixer-->
        <script src="./js/jquery.min.js"></script>
        <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
    </body>

    </html>

css:

.header {
    background-color: grey;
}
.fixpadding {
    background-color: grey;
    border-radius:4px 4px 0 0; /* Fine-tuning with nav bar */
}

Try it out.

Edit 2:

You may see that if you resize the window, the background color will "spread-out" . To fix this, I've warped all of the body with a container, and set some more css:
html:

<div class="container">
        <div class="fixpadding">
        ...
        </div>
<!--End Fixer-->
</div>

css:

.header {
    background-color: grey;
}
.fixpadding {
    background-color: grey;
    background-size: contain;
    border-radius:4px 4px 0 0;/* Fine-tuning with nav bar*/
}

Check it out.

Edit 3:

You can't color a padded area specifically.
I made some changes to show you what you could do:
Try it here.
The red and green colors are there so you could see the impact.
I've hard-coded the css into the html so you won't need to hassle with the selectors.
HTML:

<!DOCTYPE html>
<hhttp://jsfiddle.net/SjYyj/#forktml lang="en">
<head>
    <title>Home</title>
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
</head>

<body>
  <div class="container" style="background-color:red;border-radius:4px 4px 0 0;">
    <div class="navbar1 navbar navbar-inverse">
        <div class="navbar-inner">
            <ul class="nav pull-right">
                <li><a href="#">sign in</a></li>
            </ul>
        </div>
    </div>
</div><!--/container-->

<div class="container" style="background-color:green;">
    <div class="row-fluid">
        <div class="header">
            <div class="span12">
                <h1> Hello World</h1>
            </div>
        </div><!--/inner-wrapper-->
    </div><!--/row-fluid-->
</div><!--/container-->
<script src="./js/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>

</body>

</html>

Upvotes: 1

Related Questions