Improving website header design with CSS styling

I'm having trouble fixing the header at the top of my website. When I use position:fixed;, the header shifts to the left and the rest of the content moves up. I've tried adjusting the z-index and padding, but the header still remains off to the left. Can anyone provide a solution for this issue?

Thank you.

<body>
<div class="header_area ">
<div class=" header ">
<div class="logo  floatleft">
<img src="images/2016.png" alt="logo" width='100%' align="middle" style="border:5px solid white"/>
</div>
<div class="mainmenu floatright ">
<nav class="main-navigation pull-right hidden-xs hidden-sm">
(now some list there)

.header_area{}
.header
{
    position: fixed;
    z-index:1000;
    padding: 10px 0;
    margin: 0 auto;
    transition: all 1.3s ease 0s;
    -moz-transition: all 1.3s ease 0s;
    -webkit-transition: all 1.3s ease 0s;
    -o-transition: all 1.3s ease 0s;
    -ms-transition: all 1.3s ease 0s;

}
body{
    padding: 20px 10px;
    font-family: sans-serif, open-sans;
    font-size:14px;line-height:20px;color:#414141;
}
nav.main-navigation {
    position: relative;
    z-index: 9999;
    font-family: bebasregular;
}

Answer №1

Consider including the following:

position: fixed;
top:0; left:0; right:0;

Answer №2

Give this a go

    <div class="header_area ">
<div class=" header ">
<div class="logo  floatleft">
<img src="images/2016.png" alt="logo" width='100%' align="middle" style="border:5px solid white"/>
</div>
<div class="mainmenu floatright ">
<nav class="main-navigation pull-right hidden-xs hidden-sm">
</nav>
  </div>
  </div>

&

    .header_area{
height:400px;
}
.header
{
    position: fixed;
    z-index:1000;
    padding: 10px 0;
  background-color:red;
  top:0px;
  left:0px;
  width:100%;
    margin: 0 auto;
    transition: all 1.3s ease 0s;
    -moz-transition: all 1.3s ease 0s;
    -webkit-transition: all 1.3s ease 0s;
    -o-transition: all 1.3s ease 0s;
    -ms-transition: all 1.3s ease 0s;

}
body{
    padding: 20px 10px;
    font-family: sans-serif, open-sans;
    font-size:14px;line-height:20px;color:#414141;
}
nav.main-navigation {
    position: relative;
    z-index: 9999;
    font-family: bebasregular;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to call upon JavaScript code from an external file

Just starting out with Spring and JavaScript! I've put together a JSP file https://i.sstatic.net/XemJ5.png In my first.js, you'll find the following method: function firstmethod() { window.alert("Enter a New Number"); return true; } H ...

Merge different $_GET parameters together before submitting

Not too certain if it's achievable, but here's the issue I'm struggling with. I need a form that generates this specific link. The desired end link is: I am unable to utilize a form for this task, but I can work with input fields. Any sug ...

When jQuery adds new elements, their CSS may not be applied accurately

One issue I encountered is using jQuery to dynamically add new elements, only to find that the CSS isn't being applied correctly to the newly added element. To illustrate this problem, I created a jsFiddle. In the example, there are differences in sp ...

Newcomers: Introduction to PHP password security

As someone who is new to PHP password hashing and coding, I recently created a simple login form that requires a username and password. After successfully submitting the form, the password is stored in a database by using $_POST['password']. Howe ...

What is the method for evaluating two variables in Javascript?

In attempting to compare two distinct variables, userInput and commandOne, I aim to trigger specific code upon a match between them. The initial step involves pressing a button to activate myTest(). function myTest() { userInput = document.getElementB ...

Fullpage.js problem with locating navigation button

Currently, I am utilizing the fullpage.js plugin on my website to create a slide-in navigation bar. I have added a pancake element to open it on the first section of fullpage. However, I am struggling to position it in the top left corner of the page. Belo ...

Setting the CSS background-position to be fixed relative to its parent element

I have a question that may be a bit challenging. I'm not entirely sure if it's possible, but I feel like I remember seeing or doing something similar in the past. I am currently working on creating a horizontal menu using a div block sized 980x36 ...

Change the position of a div by clicking on different content menu buttons to make it go up

I have implemented move up and move down buttons in my context menu for multiple div drops. However, I am facing an issue with moving the div down after clicking the move down button. Here is the code snippet that I am currently using: $(".propertyClass" ...

Encountering difficulty retrieving data upon initial click within an Android webview during server communication

I have encountered an issue when calling this method from JavaScript. The data is returning as null for the first time, but starting from the second time it works fine. Seeking assistance on this matter. @SuppressLint("JavascriptInterface") public Str ...

"Creating a duplicate of an element by utilizing the `next`

I have a dilemma involving two divs within a section of my project - one div is dynamically created while the other exists statically. My goal is to transfer the non-dynamically created div into the one that is generated dynamically. let adContainer = $ ...

Press the button to update several span elements

Imagine I have multiple span elements like this: <span>A</span> <span>B</span> <span>C</span> <span>D</span> and a div element (which will be converted to a button later) named "change". <div id="chan ...

Strive to discover the ideal solution for capturing a screenshot of an OpenLayers map using html2canvas. Currently, the map elements are losing their CSS classes and images are not

Seeking advice on the best solution for working with html2canvas and css. I'm trying to take a screenshot of a map that includes various elements, but after capturing the image, all the css classes are lost and the images are not rendered properly. S ...

Is there a way to execute a JavaScript function by clicking on an anchor tag?

Many websites, such as StackOverflow, have attempted to address this particular issue. However, the explanations provided are complex and difficult for me to grasp. I am looking for someone who can help identify my mistakes and explain the solution in simp ...

Material UI causing animation to fail to trigger

After integrating material UI into my existing application, I encountered a peculiar issue. When adding material UI components to modals, the entering animation fails to trigger. Interestingly, downgrading material UI or removing all MUI components resolve ...

Removing a specific MySQL row using HTML in collaboration with Node.js

I've been working on a feature to allow users to delete specific rows from a table. Each row has a "Delete" link at the end, but when I click it, nothing happens. There are no errors displayed, and the console shows that 0 row(s) have been updated, ye ...

Attempting to incorporate a vibrant hover effect into a sleek carousel design

I am struggling to implement a hover effect with color on an image within a slick carousel on my Wordpress website. I have been exploring various options but haven't found a solution yet. ...

Chrome successfully processes Ajax GET request, however Firefox and Safari encounter issues

Successfully tested in Chrome, the following code executes a GET request that prints out the reportOrder to the terminal. However, when the request is made in Safari or Firefox, it returns a 404 error instead of receiving the stringified JSON. if(formread ...

What techniques can I use to adjust the size of an image through zooming in and out?

In my custom gallery component, the crucial code section looks like this: <Gallery> <Header> <img src={galleryIcon} alt='Galley icon' /> <h1>My Gallery</h1> </Header> ...

When using JSON.parse, it may sometimes return [Object Object] instead of the expected

The JSON output of my API looks like this: [{"UserName":"xxx","Rolename":"yyy"}] I am trying to extract the values for Username and RoleName separately using JSON.parse, but it is giving me [Object Object]. Can someone please assist? Your help is much ap ...

Creating a sleek and dynamic grid system using Sass for columns ranging from small to large sizes

I'm having trouble locating the information I need on Google. I'm attempting to establish a flexible grid system that employs columns similar to foundation or bootstrap. Specifically, I am aiming to implement column column-med column-lg, but I&ap ...