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

Tips for changing the background color of a Qtextedit?

After experimenting with HTML, I discovered that using type bgcolor="#ffd814" will change the background color in textedit. But how can I achieve the same result using QAction and QColorDialog? This is the method I tried: void MainWindow::on_actionBackgr ...

What steps should I take to make the image appear on the browser?

I am having trouble displaying an image on a webpage in the browser. Despite using the correct path to the image, only the alt tag is being shown along with an ordered list below it. Strangely, Visual Studio Code suggests files while building the path in t ...

What is the proper way to incorporate isset($_POST['id'.$var]) into a loop structure?

I am currently working on a project where I need to create multiple fields for users to comment on. In order to achieve this, I have implemented a while loop that generates the following HTML code for the text inputs: <form name = "replyform" method = ...

Creating a Consistent Look for Italic Font Formatting in Tailwind

In an effort to establish consistent typography on a website being developed by my team, we have devised custom utility classes in Tailwind. One of these classes, small-italicized, also requires the text to be italicized. However, it seems that the fontSiz ...

What are the signs that an element was visible on screen prior to navigation?

Recently, I incorporated SlideUp and SlideDown jquery animations into my website. You can check it out by visiting (click the >>>). However, I noticed a small issue where when users navigate to a new page, they have to re-SlideUp the element that was sl ...

Adjusting height in Google Maps to fill the remaining space

Currently, I am developing a map application where I want the Google Maps DIV to occupy the remaining height under the header. Here is the code snippet: <!DOCTYPE html> <head> <title>Map Application</title> <style type ...

Is there a way to modify the dimensions of this container? (CSS)

After performing a search and clicking on a result, a white bubble pops up on the map. I am looking to use CSS to make this bubble smaller as it is currently too large. Can anyone provide guidance on how to achieve this? ...

What is the best way to combine a top <div> with a bottom <div> in an image without creating unsightly white gaps?

I need help overlapping two divs on top of an image in HTML. The first div should cover part of the top area of the image, while the second div should cover part of the bottom area of the image. These divs should be displayed over the image without leaving ...

Missing inkbar in Material UI tabs when using ReactJS

For some reason, the small inkbar is not appearing under this tab. I suspect it might be a css issue that I can't seem to figure out. It's possible that I'm missing something I don't know about or maybe the height of the tab is too high ...

Choosing specific elements with Selenium using OR/AND operations in Python

I am encountering an issue while working with Selenium using Python. Here is a preliminary example of my code snippet. <body> <button info="content1" aria-label="1">"Click 1"</button> <button info ...

``Is there a way to retrieve the file path from an input field without having to submit the form

Currently, I am looking for a way to allow the user to select a file and then store the path location in a JavaScript string. After validation, I plan to make an AJAX call to the server using PHP to upload the file without submitting the form directly. Thi ...

Nesting a DIV tag within another DIV tag

Being relatively new to web design, my understanding of the DIV tag is that it serves as a logical container for whatever content is inside, and those elements will be formatted according to its rules. I have an outer DIV tag styled as <div style="margi ...

Ways to adjust the ngx-pagination color scheme?

I am looking to customize the background color of ngx-pagination Here is my current code: <pagination-controls class="custom-pagination" id="indicadorPaginationResults" (pageChange)="p=$event" maxSize="9" directionLinks="true" autoHide="true" previ ...

Using Special Fonts in Visual Studio 2013

Encountering a small issue with Visual Studio 2013. My application, developed using html and javascript, utilizes a custom font. When attempting to run the application on a different computer that does not have the font installed, it fails to display corr ...

Refresh the Content of a Page Using AJAX by Forcing a Full Reload

I have a webpage that automatically updates a section using jQuery AJAX every 10 seconds. Whenever I modify the CSS or JavaScript of that page, I would like to include a script in the content fetched via AJAX to trigger a full page reload. The page is ac ...

Tips for decreasing the placeholder font size within a mobile media query

I'm encountering a strange issue. I successfully managed to decrease the font size of the placeholder text for my desktop design, but it's not working for my mobile phone media query. I started with the desktop version and used a max width of 480 ...

"Enhance Your Form with Ajax Submission using NicEdit

Currently, I am utilizing nicEditor for a project and aiming to submit the content using jQuery from the plugin. Below is the code snippet: <script type="text/javascript"> bkLib.onDomLoaded(function() { new nicEditor().panelInstance('txt1' ...

choosing a specific element with jQuery to be used for future purposes

I'm having some trouble with the following code snippet: var star = $("._container > favorite"); var symbol = $(star.parentNode.parentNode).attr("symbol"); var exchange = $(star.parentNode.parentNode).attr("exchange"); After running ...

Select the send all text option when making a request

Using ajax, I can dynamically fill a drop-down select menu. My next step is to include all the text from the selected options in my request. <select name=".." > <option value="0"> ... </option> <option value="1"> xxx </option ...

The JavaScript code appears to be missing or failing to execute on the website

Encountering a console error while trying to integrate jQuery into my website. The JavaScript file is throwing an error in the console that says: Uncaught ReferenceError: $ is not defined catergory.js:1 Even after following the suggested steps in this an ...