Ensure that the top border is aligned perfectly with the top of the page while keeping the text in its

I am a beginner student working on my very first project, so I appreciate your patience as I learn.

Currently, I am trying to add a hover effect to the navigation bar links where a blue bar appears at the top of the link and touches the border of the page.

The image above shows how it should look, while the image below displays my attempt at replicating it.

https://i.sstatic.net/27zbR.png

This is the code I have:

header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    height: 79px;
}

header img {
    padding: 30px 50px 30px 50px;
}

nav {
    display: flex;
    padding: 0 25px;
    gap: 68px;
}

nav a {
    display: inline-block;
    color: black;
    text-decoration: none;
    gap: 68px;
    margin-top: 9px;
    border-block-start: 2px solid rgba(0, 0, 0, 0);
}

nav a:hover {
    color: var(--main-color);
    border-block-start: 2px solid var(--main-color);
}
<header>
            <img src="images/logo/logo.png" alt="Logo">
                <nav>
                    <a href="">Accommodations</a>
                    <a href="">Activities</a>
                </nav>
        </header>

Thank you for your assistance.

Answer №1

Consider using padding-top: 9px; for the nav a element.

Ensure to eliminate the default margin set on the body.

body {
  margin-top: 0;
}

 :root {
  --main-color: blue;
}

header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  height: 79px;
}

header img {
  padding: 30px 50px 30px 50px;
}

nav {
  display: flex;
  padding: 0 25px;
  gap: 68px;
}

nav a {
  display: inline-block;
  color: black;
  text-decoration: none;
  gap: 68px;
  padding-top: 9px;
  border-block-start: 2px solid rgba(0, 0, 0, 0);
}

nav a:hover {
  color: var(--main-color);
  border-block-start: 2px solid var(--main-color);
}
<header>
  <img src="images/logo/logo.png" alt="Logo">
  <nav>
    <a href="">Accommodations</a>
    <a href="">Activities</a>
  </nav>
</header>

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

Customized icons for Contact Form 7 on your Wordpress website

Currently, I am in the process of customizing a contact form by incorporating placeholder icons and text using the 'Contact Form 7' plugin within Wordpress. This particular contact form is situated on a website that I am constructing with the &ap ...

Search bar that automatically adjusts based on the size of the containing div

https://i.stack.imgur.com/wtn8K.gif I'm interested in learning how to achieve a layout similar to this. Here's an example of what I've created: <div class="header-con"> <div class="search-bar-con"> <input type ...

I am looking to display the data in a table format within CodeIgniter

Currently, I am working on a project where I have a table with course IDs and under each course ID, student names are listed. You can refer to the image below: https://i.sstatic.net/YNuhh.png I have managed to fetch the data, but I am struggling to displ ...

Upon rerender, React fails to refresh the style changes

I am encountering an issue with my React component where the visibility and position can be changed by the user. Currently, the visibility can be toggled by adding or removing a CSS class, while the position is adjusted through a function that updates the ...

Having a bottom border only on input fields appears strange when viewed on a mobile device

When trying to achieve a bottom border on mobile, I encountered an unexpected issue where a strange line appeared instead in the browser. Here is an image of the problem: https://i.sstatic.net/PqEOF.jpg I expected to see a straight line as intended (it w ...

Discovering the technique to dynamically load various content using jQuery in a div based on its

After discovering this code to extract information from the first div with an id of container (box4) and retrieve any new data from the URL, everything was functioning correctly. However, I encountered an issue when attempting to load box5 and rerun the co ...

Thumbnails gracefully hovering alongside titles

I am puzzled by the fact that some of the thumbnails are displaying differently even though they have the same CSS... h4 { line-height:100%; color: #be2d30; letter-spacing: 1px; text-transform: uppercase; font-family: 'Gnuolane'; font-size:26px ...

An angular component that is functioning properly when connected to a live server, however, it is experiencing issues when trying to run `

I tried integrating versitka into my Angular component by placing the version HTML file and all necessary assets in the appropriate directories. However, when I run ng serve, only the HTML file seems to be working, while the CSS and images fail to load. I ...

Is there a way to ensure that the border of a textarea matches the border of a text input?

My goal is to make the textarea fields in my form have the same appearance as the text input fields, regardless of the browser being used. I am interested in achieving this without imposing a customized style, but instead by leveraging the standard style w ...

Using Angular to include a forward slash "/" in the text input for a date field

Hello everyone, I am a newcomer to AngularJS and I am looking to insert slashes in an input type text element. I prefer not to rely on external packages like angular-ui or input type Date. My goal is to have the format mm/dd/yyyy automatically applied as ...

Enhancing Alerts in Bootstrap 5.1+: Tweaking Text, Background, and Border Colors for Alert-Warning Messages using custom _variables.scss

Incorporating a custom _variables.scss file into my codebase is crucial for my project, and the way I import it is as follows: @import url('https://fonts.googleapis.com/css?family=Nunito'); @import 'variables'; @import 'bootstrap/s ...

Loading input datalist in Firefox postponed

My goal is to implement an input field for a username that allows users to select from a wide range of names/usernames. I want them to be able to enter a partial string from the name or username. Instead of loading the entire list initially, I aim to load ...

When trying to click the button in Navbar.jsx, I encounter an error when attempting to invoke the setShowCart(true) function

I've encountered an issue while trying to call the setShowCart(true) function in Navbar.jsx. I'm unsure of how to fix this. import React from 'react' import Link from 'next/link'; import {AiOutlineShopping} from 'react-ic ...

Adjust the container width to match the width of the visible thumbnails?

Take a look at my website over at: . If you want to see more thumbnails, consider switching to a different album. The album titled Paris contains the most images. If you press the "Show Photo Grid" button located in the bottom-right corner, you'll be ...

custom checkbox is not being marked as checked

I've been attempting to customize my checkboxes, following various tutorials without success. Despite trying multiple methods, I still can't get the checkboxes to check or uncheck. Here is the code I have so far: https://jsfiddle.net/NecroSyri/ ...

HTML form struggles to transfer information to MySQL database

Despite successfully connecting my HTML form to a MySQL database, I encountered an error whenever I attempted to submit data, resulting in no data being passed to the database. Here is a screenshot of the error message: Let's create the necessary da ...

Unveiled absolute positioned element disrupts page layout when revealed

I'm facing an issue where an absolutely positioned element is causing content to move when it's displayed. You can see the problem in action by clicking on Profile in this fiddle. Can anyone help me understand what is causing this behavior and h ...

The Flex 4.6 StyleableTextField fails to recognize and render <br> and <p> tags

I am facing an issue in my mobile project with the StyleableTextField. When I fill it with HTML text using the .htmlText property, the tag works fine but simple line breaks and paragraphs are not being displayed. How can I fix this? Even the simplest H ...

Avoid passing down line-height settings to elements within nested elements

Is there a way to prevent the span styled with font-size: 12px from inheriting the line-height of the span styled with font-size:18px? I need the line-height value to be 1.5 for both 18px and 1.5px font sizes, but I am unable to separate the two spans. ht ...

Using JQuery Slider to call a function without the need for an ID, instead utilizing the object directly

Currently, I am working on implementing a Slider using JQuery, and I have encountered an issue in my code. The function is set to run when the page loads, creating a slider with the Id specified in the div element: $(function() { $( "#slider& ...