HTML and CSS - Aligning text and managing scrollbar visibility

I am currently diving into the world of coding and embarking on the journey of crafting a website for my father. This project not only helps me gain valuable experience but also builds up my portfolio.

Utilizing unsemantic and normalize frameworks, I encountered some challenges along the way:

1) The alignment between the text "Michael Gilsenan" and the navigation bar is proving to be quite tricky. Despite experimenting with line-height adjustments, the text seems to move sporadically in unexpected directions.

2) Implementing a horizontal line under the header using either the <hr> tag or the border-bottom property triggers a scroll bar inside the containing <div> where the <nav> element resides.

After tirelessly searching for solutions over the past 4 hours and delving into numerous resources, exhaustion has started to set in. Apologies if I might be overlooking something glaringly obvious at this point!

Your assistance is greatly appreciated.

<!DOCTYPE html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"/>      
    <link rel="stylesheet" type="text/css" href="../external/css/normalize.css">
    <link rel="stylesheet" type="text/css" href="../external/css/unsemantic-grid-responsive-tablet.css">
    <link href="https://fonts.googleapis.com/css?family=Montserrat:700|Open+Sans:400,600" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body class="grid-container">

        <header class="grid-parent">

            <div class="grid-50">
                <a href="" class="headertext">Michael Gilsenan</a>
            </div>

            <div class="grid-50">
                <ul>
                    <li><a href="">About</a></li>
                    <li><a href="">Bio</a></li>
                    <li><a href="">Portfolio</a></li>
                    <li><a href="">Blog</a></li>
                    <li><a href="">Contact</a></li>
                </ul>
            </div>

        </header> <!-- end of header-->

</body>

* {
        margin: 0;
        text-decoration: none;
    }

    hr {
        border-style: solid;
        border-color: #cacaca;
        position: relative;
        top: -40px;
    }

    /* header styles */

    header {
        font-family: 'Open Sans', sans-serif;
        margin-top: 80px;
        overflow: auto;
        border-bottom: solid #cacaca 1px;
    }


    header a {
        color: #332e2d;
    }


    .headertext {
        font-family: 'Montserrat', sans-serif;
        font-size: 300%;
        letter-spacing: -0.01em;
        line-height:
    }

    ul li {
        display: inline; 
    }

    ul {
        word-spacing: 0.5em;
        text-align: right;
    }

Answer №1

When working with the ul

line-height: 55px; /* to match the height of the headertext. */

Dealing with the header

overflow-y: hidden;

Visit this link for more information.

The key was identifying the source of the scrollbar issue. I initially focused on the ul, but upon closer inspection, I discovered that it was actually being added to the header section.

Note: It is recommended to use a proper header tag like <h1> for the headertext instead of simply increasing the text size. Search engines rely on header tags for SEO purposes. You can still modify the size of header tags using CSS while maintaining the semantic structure.

Answer №2

A scroll bar is being displayed because the overflow property in the style declaration for the header element is set to auto:

header {
  font-family: 'Open Sans', sans-serif;
  margin-top: 80px;
  overflow: auto;                        <-- change or remove this
  border-bottom: solid #cacaca 1px;
}

The auto value allows the browser to decide whether to add scrollbars when content exceeds container dimensions, often resulting in unintended scrollbars. Removing the overflow property or setting it to none will get rid of the scrollbar.

If you are struggling with alignment due to the float-based layout of the unsemantic stylesheet you are using, consider learning and implementing flexbox instead. Here are some recommended tutorials:

To achieve your desired layout with flexbox, follow these steps:

Remove unsemantic grid classes from your HTML Replace your CSS with the following

* {
margin: 0;
text-decoration: none;
}

/* hr {
    border-style: solid;
    border-color: #cacaca;
    position: relative;
    top: -40px;
} */

/* header styles */

header {
    display: flex;
    align-items: flex-end;
    height: 80px;
    font-family: 'Open Sans', sans-serif;
    /* overflow: auto; */
    /* border-bottom: solid #cacaca 1px; */
    border-bottom: 1px solid #cacaca;
}

header a {
    color: #332e2d;
}

.header-text {
    font-family: 'Montserrat', sans-serif;
    font-size: 3.5rem;
    letter-spacing: -0.01em;
}

header nav {
  padding: 10px;
  display: flex;
}

header nav ul li {
  display: inline;
  align-items: flex-end;
  margin: 0 20px;
}

I've included comments on certain properties in your CSS file. For a working example, check out this pen:

https://codepen.io/danyadsmith/pen/mKjyKQ

If you're facing challenges due to the grid system you're using, consider moving to flexbox which has broader browser support. Check the flexbox section on Can I Use for more information:

https://caniuse.com/#feat=flexbox

Hope this advice helps you. Good luck!

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

Conceal Tooltips with Materialize CSS

I'm trying to figure out how to hide the tooltip that appears when hovering over this element using Materialize CSS. <li><a class="btn-floating green" onclick="window.print();return false;"><i class="material-icons tooltipped" data-pos ...

Difficulty in implementing jQuery accordion height style using either content or fill option

What I am looking for is to have only one specific div in my accordion (device properties) change its height based on the content. I have also noticed that if I use Firebug to remove the height property of the device div, it adjusts the height correctly. ...

Using jQuery-Ajax to fetch MySQL data in Perl

Currently, I am in the process of developing a webpage that consists of three essential components: a select box, a button, and a table. At a high level, the user makes a selection from the element and then clicks the button. Subsequently, a PERL script is ...

When attempting to render HTML containing multiple CSS classes within a JSON request parameter, the styles are not being applied as expected

In my API, I'm dealing with a JSON request parameter that includes an HTML string. This HTML string references CSS styles from a separate .css file. However, when an HTML element has two CSS classes assigned to it, neither of the classes' styles ...

Adding a watermark or overlay to an image using JavaScript and PHP

I am working on a game where users have to guess which quadrant a meteor will hit. After each round, I want to display an image of a "crater" on the map based on the randomly generated quadrant using PHP's rand(1,4) function. The map is represented a ...

Problem with Bootstrap 3 navbar on mobile devices - not tappable or responsive

After years of using Bootstrap, I've come across a new issue with my implementation of a Bootstrap 3 Nav. While testing on a desktop browser with device emulation, the nav collapses and functions properly. However, when tapping on the header on an ac ...

Margin in Bootstrap Panel Not Set to 0 as Needed

My bootstrap panel's margins are set to 0, but it doesn't seem to actually be 0. In the image attached, the margin shows as "-", which I assume means 0. However, when I highlight it, I see a large block of orange. Does this indicate that the marg ...

How can we initiate a script once the scroll has reached the designated block using jQuery?

I am using a unique jQuery script that I created myself, and I want it to activate when the scroll reaches the tab block (the blue and grey block at the end of the page). Check out the live version This is my HTML: <section id="Block" class="containe ...

Encountering an issue with Masonry's container.append that is causing an Uncaught TypeError: Object does not possess the filter method

I have implemented infinite scroll on my website to display images. The images are arranged using a tool called masonry. Initially, I only load 10 images into the #container div when the page loads. These images are aligned perfectly with no errors in the ...

Passing a value from a prop to a click event that is dynamically created within an SVG Vue.js

Currently, I am in the process of developing a map component using a JSON array and implementing a click event handler for each item. The objective is to toggle the CSS style to color the item when clicked, which is functioning as expected. However, my goa ...

Refresh a specific div element utilizing jQuery

I am facing a challenge with my data table in my Spring MVC project. I want to be able to update or remove data from the table without having to reload the entire page. Below is an example of the HTML div element: <div id="datatable"> </div> ...

CSS3 Word Wrapping Tutorial

Are there alternative methods to word-wrap text within a div element? I am limited to using only CSS1 and some CSS2, so I cannot utilize word-wrap in CSS. *Consider using javascript or CSS Thank you! .test_wordWrap { position: absolute; top: 45px; ...

Having difficulty in closing Sticky Notes with JavaScript

Sticky Notes My fiddle code showcases a functionality where clicking on a comment will make a sticky note appear. However, there seems to be an issue with the Close Button click event not being fired when clicked on the right-hand side of the note. I have ...

Refreshed page causing hide/show div to reset

Hello there, I'm currently working on a web application and I need to implement some JavaScript code. The application consists of three sections, each with its own title and button. When the button is clicked, a hidden div tag is displayed. Clicking t ...

Height that is determined in real-time

I am attempting to adjust the height of a div based on the size of the screen. Within this div, there is a calendar that contains multiple lines of content, which can be displayed or hidden based on user preference. The height of the calendar is not fixed, ...

Ways to incorporate a floating label

https://i.sstatic.net/vwnjl.jpg Can anyone provide guidance on how to incorporate the floating label as depicted in the image? ...

How can I modify CSS styles in AngularJS with Bootstrap UI?

Utilizing bootstrap UI in conjunction with AngularJS directives, I am looking to customize the default styles that bootstrap applies to its elements. Is it recommended to target the HTML contents within the template? Referring to the examples provided in ...

When the form is submitted, use jQuery to smoothly transition the page to a specific

I have a form and a div called "success". When the form is submitted, the "success" div is displayed. I am attempting to make it so that when the form is submitted, the page slides to the "success" div. Here is the code I am using: $.ajax({ type: "P ...

Libraries that provide webkit support for all browsers

Looking for a library that supports CSS webkit across various browsers, including older ones like ie6. Preferably written in JavaScript. Any recommendations? ...

The class [AdminController] being targeted does not exist

https://i.sstatic.net/r6c7q.pngI encountered an issue where a user is redirected from login to the admin page (e.g. ), and a 403 error should be triggered if the user is not logged in as an admin. Interestingly, even the admin experiences the same error. ...