Title Bar: Excessive gap; inaccurate navigation to nearby link

I've been trying to align a horizontal navigation bar right below a banner and link directly to specific sections on the same page.

  1. No matter what I do, I can't seem to remove the white space between the banner image and the navigation bar. It showed up after I changed the banner from pure HTML to an image, but fixing it with images hasn't helped.
  2. The links for Bio and Issues position those headings at the top of the view, but Intro does not.

Here's the JSFiddle

Here is the working code:

h1 {
    color: black;
    text-align: center;
}

html, body {
    padding:0;
    margin:0;
    border: 0;
}

#statement {
    position: absolute;
    left: 50%;
    margin-right: -50%;
    transform: translate(-50%, 0%);
    width: 810px;
}

#navbar {
    float: left;
    padding: 0;
}

#navbar ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
    display: table;
}

#navbar li {
    float: left;
    text-align: center;
}

#navbar li a {
    font-size: 30px;
    display: table-cell;
    width: 270px;
    height: 50px;
    text-decoration: none;
    color: black;
    vertical-align: middle;
    background-color: #f0e68c;
}

#navbar li a:hover {
    color: #f0e68c;
    background-color: black;
}

<body>

<div id="statement">

   <img src="http://dreamatico.com/data_images/ocean/ocean-5.jpg" width="810px" height="300px">

   <div id="navbar">
      <ul>
         <li><a href="#intro">Intro</a></li>
         <li><a href="#bio">Bio</a></li>
         <li><a href="#issues">Issues</a></li>
      </ul> 
   </div>

   <h1 id="intro">Intro</h1>
       <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur rid...
   <!-- Truncated for brevity -->
   </div>

</body>

Answer №1

I've been struggling to remove the white space between the banner image and the navigation bar on my website. This issue only started after I switched the banner from pure HTML to an image, and none of my usual tricks with images seem to be working.

To get rid of the white space, try using vertical-align: bottom

#statement > img {
    vertical-align: bottom;
}

When clicking on the Bio and Issues links, the headlines are positioned at the top of the view, but this doesn't happen with the Intro link.

You'll need to clear the floating elements above those h1

h1 {
  clear: both;
  display: block;
}

Check out the Fiddle for more details

Answer №2

Eliminating whitespace:

If you want to get rid of the extra white space, use this CSS code

img {
    display: block;
}

Here is the example

Solving the linking issue:

To fix the problem with linking, try adding more content so that the page can scroll properly.

Answer №3

Concerning the issue with the white space around the image, it seems to be a bit unclear. However, as for the problem with the link not redirecting to the correct location, it appears that there might not be sufficient space on the page. Take a look at this revised fiddle, is this how you envisioned it to function?

<h1 id="intro">Intro</h1>
   <p>
       Lorem ipsum dolor sit amet, consectetuer adipiscing elit... (content truncated)r

Bio

   <p>
       Lorem ipsum dolor sit amet, consectetuer adipiscing e... (content truncated) 

Issues

   <p>
       Lorem ipsum dolor sit amet, consectetuer adipiscing e...(content truncated)

http://jsfiddle.net/gmgdhs75/1/

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

Aligning two identical components within the same container when triggered by a single click

Currently, I am exploring Angular 2 and Typescript and have been developing a pager component for a table. The pager functions correctly, but I have encountered an issue with having two pagers - one above the table and one below it. When the next button on ...

The information is failing to display properly within the mat-menu

Recently, I've been working on creating a navbar that includes a submenu. Even though the navigation bar data is loading properly, I am facing some issues with the submenu functionality. As a beginner in this area, I would appreciate any help or guida ...

Issue with changing the opacity of a Javascript button style is not functioning correctly

The button's opacity used to change gradually in increments of 0.1 every 500 milliseconds, but now it instantly changes to 0.9 without the delay. Issue: Despite being placed within a window load handler and all elements loading properly, the loop is ...

Attempting to achieve the effect where the entire row of a table changes color when the mouse hovers

I'm attempting to create a gradient effect for an entire row in a table when the mouse hovers over any cell within that row. Despite using what I believe is the correct CSS code, nothing changes upon mouseover (even though the original gradient appear ...

Placing a horizontal line or Material UI Divider at the bottom of a webpage

Working with react and material ui, I am facing an issue in positioning a divider close to the bottom of the webpage along with a logo. In my jsx file, I have a functional component utilizing material UI drawer on the left side of the browser, where I have ...

Learn how to display months on a countdown timer and then customize the format with basic JavaScript for a website

Looking to create a countdown page for the upcoming ICC cricket world cup event that displays the remaining days in two different formats: Format #1: 01 months 10 days 10 hours Format 2: 01 hours 20 minutes 10 seconds (If less than 2 days remain) I curr ...

Issue with horizontal scrolling functionality in DataTables

I have a table with over 10 columns, and I am using datatables to display the data. I have enabled horizontal scrolling due to the large number of columns, but the scroll is not appearing. Can someone please assist me with this issue? Here is a screenshot ...

Tips for preventing H1 from taking up the entire div

I'm currently working on developing a new theme for my WordPress website. One issue I've encountered is that the h1 element is causing the top menu to appear below it instead of on the same line. Can anyone help me overcome this challenge? Here& ...

Troubleshooting issues with custom global components failing to apply styling in NuxtJs

I have designed various components such as buttons that I want to be able to use and reuse across my entire website. I have already developed plugins Object.entries(components).forEach((([name, component]) => { Vue.component(name, component) })) and ...

Change `console.log` to output to a specified `div` container

I found a great example of using a simple rss feed parser on Stack Overflow. $.get('https://stackoverflow.com/feeds/question/10943544', function (data) { $(data).find("entry").each(function () { // or "item" or whatever suits your feed ...

How to make text dynamically shrink with TailwindCSS class 'flex-shrink-0'

I've designed an 'Album' (React) component to showcase album artwork, name, and release date in a card-like format. This component consists of two divs - one for the photo and the other for text. Each artist's discography displays multi ...

Issues with mobile stylesheet loading properly

After migrating my website to a new server, I encountered an issue where the text displayed incorrectly on mobile devices but appeared fine on laptops. Surprisingly, when using Chrome's mobile viewer for inspection, everything looked as it should with ...

Make the div disappear upon clicking the back button in the browser

When a user selects a thumbnail, it triggers the opening of a div that expands to cover the entire screen. Simultaneously, both the title and URL of the document are modified. $('.view-overlay').show(); $('html,body').css("overflow","h ...

Div with hidden scrollbars for smooth scrolling experience

Is there a way to create scrollable DIV's without visible scrollbars? While Mac OS 10.7-8 display no visible scrolls, other operating systems like Windows, Mac OS, and Linux show the scrollbars. How can I achieve scrollable divs without the scrollbars ...

Is there a way to arrange an HTML list in this specific manner using CSS or JavaScript?

I need to arrange a list of items in columns with 5 rows each, as shown in the attached image. This list is generated dynamically using an SQL query with a loop on the li tag. I am looking for a solution to order the list in this way using javascript or ...

Adjustment of Image Placement

I'm describing my desired outcome briefly - I want the inputs in the code to appear in the top left corner of a large image. Despite trying multiple approaches, I have been unable to achieve this layout. When considering 2 columns, the inputs should b ...

Customizing the appearance of the 'Submit' button compared to the <a href=""></a> button using CSS

I am experiencing some issues. Even though the CSS code for these two buttons is exactly the same, their appearance is different. I am unable to make the :hover or :active effects work either. My goal is to have the left 'input type="submit' but ...

What is the best way to incorporate a PHP file into an HTML file?

Below is the code snippet from my index.php: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Voting Page</title> <script type="text/javascript" src="js/jquer ...

What is the best strategy for positioning an anchor element within a list item using JSX or Bootstrap in a way that maximizes efficiency?

I have the following code snippet <li className = "list-group-item list-group-item-success" key ={todo.id}>{todo.text}<a style="float:right;" onClick={() => props.onEdit(todo)} className="edit-todo glyphicon glyphicon-edit" href="#"& ...

Using Javascript to convert numerical input in a text box into its corresponding letter grade

I have been working on this code, but I am facing some issues with displaying the result. My goal is to input a number, such as "75", click a button, and have the bottom textbox show the corresponding letter grade, starting with "C" for 70-80 range. Here i ...