Another option for "top-margin" in CSS?

I'm having some trouble fitting navigation tabs onto an <article> element, especially in Firefox and on different screen sizes. Does anyone have a solution that works across all browsers and maintains consistency when the screen is resized?

The desired outcome is as follows:

I want it to look exactly like that, but without using a fixed margin-top.

EDIT:

Code:

Navigation:

nav {
    width: 100%;
    height: 4%;
}

nav ul {
    list-style-type: none;
}

nav li {
    width: 100%;
    background-color: #9A9489;
    display: inline-block;
    text-align: center;
    width: 11%;
    font: 1.4em/1.3em Bonveno, Open Sans, Sans-Serif;
    float: right;
    cursor: pointer;
    margin-right: 0.5%;
    border-top-left-radius: 0.3125em;
    border-top-right-radius: 0.3125em;
    transition: background-color 0.2s ease-in-out;
}

Article (without margin-top):

article {
    width: 99.5%;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 0.3125em 0 #9A9489;
    padding: 0 0 0.5% 1.5%;
}

HTML:

<nav>
    <ul>
        <a href="contact.php">
            <li>Contact</li>
        </a>

        <a href="pictures.php">
            <li>Pictures</li>
        </a>

        <a href="about.php">
            <li class="selected">About</li>
        </a>

        <a link="black" href="index.php">
            <li>Home</li>
        </a>
    </ul>
</nav>

<article>
<h1>Hello World</h1>

<p>Hello world</p>
</article>

Answer №1

Have you considered using positioning instead of margins? You may want to try using a relative position for this situation. Here's how:

.YOUR_TABS_SELECTOR{
  position: relative;
  top: 10px;
}

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

Receiving an absence of string or a null value from a text box

My goal is to test the functionality of an <input> element by entering text into a textbox and then displaying that data in the console. However, I am encountering issues with retrieving and printing the content. Additionally, I am interested in test ...

Looking to establish a minimum height for a webpage

I am working on creating a webpage with three distinct sections: A fixed height header A fluid main section A fixed height footer My goal is to ensure that the page has a minimum height so that the bottom of the footer aligns with the bottom of the wind ...

I am attempting to display the Δ symbol on my website, however, it is not appearing on the webpage

In my attempt to display my company logo on the website, I encountered an issue where the Δ symbol is not appearing correctly in the browser. strong class="footer-logo">KyΔnsys</strong To address this problem, I have implemented unicode charset=" ...

Is there a way to eliminate the .html extension from the end of URLs for web pages?

Can someone provide guidance on how to eliminate the .html extensions from file names? Specifically, I noticed this feature on the site tekmillion.com. Your assistance is greatly appreciated. Thank you! ...

Looking for assistance with automated web testing using selenium

I am currently using Selenium to carry out testing on a web application, but I have encountered an issue. One of the nodes that needs to be clicked has a value that constantly changes upon startup. For example: click css=#f0012 > ins.jstree-icon At s ...

Is there a way to connect CSS files from a different directory?

I'm currently in the process of developing a website and I encountered an issue with linking my CSS file, which is stored in a different folder. I originally had it in the same directory as my HTML code, but now I need to figure out how to link it pro ...

Troubleshooting the issue with the collapse feature of the Angular UI

I am struggling to ensure my navbar starts collapsed using the code provided below. I am utilizing Angular-ui-bootstrap: navbar.directive.html: <button type="button" ng-click="isCollapsed = !isCollapsed"> <span class="sr-only">Toggle naviga ...

Displaying the products has an issue with the alignment of heights

I have a project in eCommerce that I'm working on. Currently, I am facing an issue where the height of the product list varies and disrupts the overall alignment when I insert additional content. Below is the code snippet I am using with Bootstrap 4: ...

Combine all the HTML, JavaScript, and CSS files into a single index.html file

So here's the situation - I am utilizing a C# console application to convert four XML files into an HTML document. This particular document will be circulated among a specific group of individuals and is not intended to be hosted or used as a web app; ...

Display button in Django template based on user's group level

In my application, there are 3 groups with different permissions: viewer, editor, and creator. I need to display the appropriate buttons based on these permissions. For viewers, they can only see lists and details. Editors have viewer permissions plus th ...

Looking for assistance with resizing SVG images

I am facing some challenges with the HTML/CSS code to make all SVG's scale uniformly in terms of height/width. I have set up a simple structure but I'm unsure of what steps to take next. When I view the images in the browser, they are all scaled ...

Issue with linking CSS file to EJS file in Express.js

After carefully reviewing the setup of my folders and code structure, I am confident that I have correctly linked the CSS to the EJS file. Despite this, I am still facing issues as it is not working properly. To provide a visual reference, I have include ...

JQuery method for altering currentTime's format

I am attempting to showcase the current time and duration of my videos on my website using the format 00:00, but I am having some difficulty... myVideo.on('timeupdate', function() { $('.current').text(myVideo[0].currentTime); $ ...

Using media queries, one can adjust the positioning of elements in CSS

Can someone please help me? I'm struggling to change the position of a div from absolute to static when the page width reduces to 800px. The challenge is that I can't modify certain code because I am displaying a slideshow that maintains an aspec ...

perform an action in PHP when a button is clicked

I'm currently developing a PHP admin panel that displays a list of users in an HTML table format. Each row in the table includes a button that allows the admin to send a notification to the selected user. Below is the code I used to create and displa ...

The Bootstrap 4 navigation bar is failing to extend fully across the width when a dropdown menu

Here is the code I am using for the navigation bar. When I click on the dropdown button, this is how it appears on my webpage: Click here <nav class="navbar navbar-expand-lg navbar-dark bg-color mb-3"> <a class="navbar-brand" ...

Struggling to design a form to incorporate changing weekly elements into a homepage

Hey, I'm looking to simplify my life by creating a form that allows me, as the administrator/creator, to easily update a group of weekly variables from datalists without needing to manually change the code every time. <form method="post" action= ...

The alert box is not displaying, only the text within the tags is visible

Trying to implement an alert message for logged-in users. A successful login will trigger a success message, while incorrect username or password will display an error. function showMessage(response) { if (response.statusLogged == "Success login") { ...

Chrome may clip the gradient radius when setting the focal point outside of the SVG gradient

I just joined this community and I might have some questions that could be considered too basic. Recently, I've been trying to understand SVG and came across something that left me puzzled. Take a look at this: <svg xmlns="http://www.w3.org/20 ...

How can a borderless text field be created using Material UI?

Today, I delved into using Material UI for my React project. My goal is to create a registration form similar to this one. Essentially, I want 5 input text fields without any borders and with a simple background color effect when active. However, I'm ...