Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Reusing my DIV

Gussy81

Coder
Hi,

I have a div that has some styles - the most important is the background image. Its working as i would like to to on my homepage. I want to re-use the div on my about us page with out copying the div attributes but giving it a different name. Can i re-use the below div with a different background image?

CSS:
#header { /*Placement of image for header background */
    position: relative;
    background-image: url("../../images/header.jpg");
    background-size: cover;
    background-position: center center;
    background-attachment: fixed;
    text-align: center;
    padding: 7.5em 0 2em 0;
    cursor: default;
    color: #F4EDEA;
    font-family: Helvetica, Sans-Serif;
    font-style: normal;
    line-height: 12px;
    font-weight:400;
    font-size: 12px;  
}

HTML:
<!-- Header -->
<div id="header">

    <!-- Inner -->
    <div class="inner">
        <header>
            <p>THE OFFICE OF</p><BR>
            <h1><a href="index.html" id="logo">LICITORS</a></h1>
            <BR><!-- <hr /> -->
            <p>THE EXPERTS</p>
        </header>
        <footer>
            footer here
        </footer>
    </div>
 
Last edited by a moderator:
Solution
By reuse, you mean use the same styles on 2 different pages? Then you can import the same stylesheet into the about us page, give the div in the about us page a different class/id and give that class/id a different background image.

Here's an example (assuming you give the div about as it's id):
CSS:
/* Import this stylesheet in both the homepage and about us page */

#header,
#about {
    position: relative;
    background-size: cover;
    background-position: center center;
    background-attachment: fixed;
    text-align: center;
    padding: 7.5em 0 2em 0;
    cursor: default;
    color: #F4EDEA;
    font-family: Helvetica, Sans-Serif;
    font-style: normal;
    line-height: 12px;
    font-weight:400;
    font-size: 12px;  
}...
By reuse, you mean use the same styles on 2 different pages? Then you can import the same stylesheet into the about us page, give the div in the about us page a different class/id and give that class/id a different background image.

Here's an example (assuming you give the div about as it's id):
CSS:
/* Import this stylesheet in both the homepage and about us page */

#header,
#about {
    position: relative;
    background-size: cover;
    background-position: center center;
    background-attachment: fixed;
    text-align: center;
    padding: 7.5em 0 2em 0;
    cursor: default;
    color: #F4EDEA;
    font-family: Helvetica, Sans-Serif;
    font-style: normal;
    line-height: 12px;
    font-weight:400;
    font-size: 12px;  
}

#header {
    background-image: url("../../images/header.jpg");
}

#about {
    background-image: url("../../images/about.jpg");
}

If you mean reuse, as in reuse that same element/component so you dont have to type it in on each page you want to use it, then React might be what you're looking for.
 
Solution
By reuse, you mean use the same styles on 2 different pages? Then you can import the same stylesheet into the about us page, give the div in the about us page a different class/id and give that class/id a different background image.

Here's an example (assuming you give the div about as it's id):
CSS:
/* Import this stylesheet in both the homepage and about us page */

#header,
#about {
    position: relative;
    background-size: cover;
    background-position: center center;
    background-attachment: fixed;
    text-align: center;
    padding: 7.5em 0 2em 0;
    cursor: default;
    color: #F4EDEA;
    font-family: Helvetica, Sans-Serif;
    font-style: normal;
    line-height: 12px;
    font-weight:400;
    font-size: 12px; 
}

#header {
    background-image: url("../../images/header.jpg");
}

#about {
    background-image: url("../../images/about.jpg");
}

If you mean reuse, as in reuse that same element/component so you dont have to type it in on each page you want to use it, then React might be what you're looking for.
Spot on. Nice and simple. Thank you
 
Back
Top Bottom