Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I'm developing a web, then I get stuck when I changed to the different desktop or device the position will changed too.The problem the link of HOME and PRODUCT will change if I changed the monitor, I want the HOME and PRODUCT in the top and right. And the position will never change if I move on different screen. This my code :

CSS
#header {
    background: #186467;
    height: 700px;
    width: 1500px;
    line-height: 1300px;
    position: fixed;
    top: 0;
    left: 0;
}

.logo {
    float: left;
}

.product {
    position: relative;
    bottom: 615px;
    left: 905px;
}

.home {
    position: relative;
    margin: 615px 100px 200px 300px;
}

    bottom: 615px;
    left: 850px;
}

HTML
<!DOCTYPE HTML>
<html>
   <header>
       <link rel="stylesheet" href="main.css"/> <!-- call the CSS file in the root folder (main.css) -->
       <title>rafidkarim | Developing The World</title>
    </header>
   <body>
    <section id="header">  <!-- HEADER -->
       <img class="logo" src="images/logo.png"/> <!-- The Logo -->
       <a class="home" href="#">HOME</a>
       <a class="product" href="#">PRODUCT</a>
       </section>
    </body>  
</html>


So, I want if changed the monitor, desktop, or device all position of the HTML content would not changed too.
Posted
Updated 21-Oct-15 4:52am
v2
Comments
Richard Deeming 21-Oct-15 10:38am    
You haven't shown your HTML markup, most of your CSS is missing, and you haven't described the problem clearly.

Remember, we can't see your screen, access your computer, or read your mind. You need to explain the problem as if you're talking to people who aren't familiar with your project.

Use the "Improve question" button to update your question with the missing information.
rafidkarim 21-Oct-15 10:52am    
I'm sorry, I just improved the question
Krunal Rohit 21-Oct-15 13:15pm    
Why you're not using bootstrap ?

-KR

1 solution

Based on the description of what you're trying to do, your CSS is overly complicated. Something like this should work:
HTML
<header id="header" class="clearfix">
    <img class="logo" src="images/logo.png">
    <div class="links">
        <a class="home" href="#">HOME</a>
        <a class="product" href="#">PRODUCT</a>
    </div>
</header>

CSS
.clearfix:before,
.clearfix:after
{
    content: " ";
    display: table;
}
.clearfix:after
{
    clear: both;
}
.clearfix
{
    *zoom: 1;
}

#header
{
    background: #186467;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
}

.logo
{
    float: left;
}
.links
{
    float: right;
}

The .clearfix CSS class is the micro-clearfix[^] to make sure that the floated content inside the header doesn't intrude onto the following elements.

Because you're using position:fixed for the header, it isn't part of the document flow. You'll need to make sure the rest of the content leaves enough room for the header using margin-top.

Demo: https://jsfiddle.net/95vdjgc4/[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900