Spaces ahead and beneath the text

I'm struggling to style a small block of text within its element perfectly. Despite my efforts, there always seems to be unnecessary space in front and below the words. One workaround I found was adjusting the line height to remove the bottom gap, but this feels like a messy solution as it depends on whether the browser decides to use 'arial' or 'helvetica' (I've set the font type as 'sans serif') which could potentially mess up any alignment I have achieved.

CSS

    html, body {
        margin: 0;
        border: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        font-family: Sans-Serif;
    }

    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
    }

    li {
        display: inline-block;
    }

    #title {
        font-size: 36px;
        font-weight: bold;
        background-color: red;
        display: inline-block;
    }

HTML

    <!DOCTYPE HTML>
    <html>
        <body>
            <div id="header">
                <ul id="title">
                    <li>
                        Test title
                    </li>
                </ul>
            </div>
        </body>
    </html>

This is what currently happens:

This is what I would like to happen:

JSFiddle:

http://jsfiddle.net/kyuLqed8/

Answer №1

To adjust the spacing between lines of text in css, use the "line-height" property. See example below:

html, body {
margin: 0;
border: 0;
padding: 0;
width: 100%;
height: 100%;
font-family: Sans-Serif;
}

ul {
list-style-type: none;
margin: 0;
padding: 0;
}

li {
display: inline-block;
}

#title {
    line-height: 25px;
font-size: 36px;
font-weight: bold;
background-color: red;
display: inline-block;
}
<body>
<div id="header">
<ul id="title">
<li>
Test title
</li>
</ul>
</div>
</body>

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

Is there a way to dim and deactivate a button after it has been clicked once?

Hello, I am attempting to disable and grey out a button after it has been clicked once in order to prevent the user from clicking it again until they refresh the page. I hope my question is clear enough and that you can understand me. Below is the HTML cod ...

Show HTML form elements on the page using jQuery or JavaScript

Is there a jQuery or JS library that can perform the following task: If the user inputs 'x' in A01, then make A01_1 visible. Otherwise, do nothing. <form id="survey"> <fieldset> <label for="A01">A01</label&g ...

Guide to launching a web browser within a Phonegap app with a button click event

We are developing a PhoneGap application using HTML and JavaScript. Our goal is to integrate PayPal's website so that users can make payments with a simple button click event within the app, and then seamlessly return back to the application afterward ...

Can microdata be applied to an element that embodies a pair of data points?

Can itemprop="name" and itemprop="contentURL" be included in the same element? For example: echo '<li itemscope itemtype="http://schema.org/AudioObject">'; echo ' <a itemprop="name" itemprop="contentURL" href="http://wav ...

Guide on accessing the text content within a div element in HTML by triggering a button click

To extract specific text from multiple div tags, I need to trigger an event when clicking a button. <div class="col-lg-3 col-md-6 mb-4"> <div class="pricing-table pricing-secondary"> <div class="price-hea ...

Ways to receive notification during the user's selection of an option by hovering over it

Is there a way to receive an event when a user hovers over a select option? I thought that using the onMouseOver or onDragOver props on the option component would work, but it seems like they only trigger for the parent select component. Below is a simpli ...

How can you incorporate a tag at the end of an HTML link, such as edit.php?id=0, to retrieve the value 0 as a variable in PHP?

Recently, I created a page that prints data from a SQL server. In addition, I developed an edit page (edit.php) where users can modify individual lines by entering new information into a textbox and submitting it for updating in the database. My current o ...

Leveraging Ajax to fetch JQuery

Currently, I am utilizing Ajax to trigger a PHP file for processing upon form submission. The JQuery form validation mechanism evaluates the variables' values to determine whether to proceed with submitting the form or to return false while displaying ...

Using jQuery to submit data via POST method without having the page reload

I have a link in the footer that, when clicked, jumps to the header with a # in the address bar. Is there a way to prevent this and stay in the footer? Here is the code snippet: <a href="#" class="clickIn" id="1" attrIn="Like"><span style="color ...

Aurelia TypeScript app experiencing compatibility issues with Safari version 7.1, runs smoothly on versions 8 onwards

Our team developed an application using the Aurelia framework that utilizes ES6 decorators. While the app works smoothly on Chrome, Firefox, and Safari versions 8 and above, it encounters difficulties on Safari 7.1. What steps should we take to resolve th ...

JavaScript can be used to manipulate buttons and interact with them on a webpage

In my search for examples for my webpage, I stumbled upon a strange JQuery selector. Could someone please explain how this works and if I can use it to target unique indexed IDs in HTML? //The mysterious selector that puzzles me //What does "^" actually ...

Achieving precise alignment of div content through Css techniques

body { margin: 0; font-family: Arial, Helvetica, sans-serif; } .topnav { overflow: hidden; background-color: #333; } .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: ...

What is the best way to conceal all input elements in a form?

I have been attempting to conceal input elements within my form by using the code snippet below. Unfortunately, it doesn't seem to be functioning as expected... <html lang="en"> <head> <title>example</title> < ...

Attempting to utilize jQuery for altering the background URL leads to the unexpected removal of the -webkit-background-clip:text; effect

Can the -webkit-background-clip:text; effect be preserved when using jQuery to switch the background url? I am experiencing issues where changing the URL removes the text clipping effect. jQuery(function($) { var whatToSwitch = $('.homepage_ove ...

One-of-a-kind Design: Linear Gradient Background Image

Can you help me with Linear Gradient? Is it feasible to incorporate an actual image instead of just displaying a color like #000000 or #ffffff? background-image: -webkit-linear-gradient(30deg, #000000 50%, #ffffff 50%); In the scenario mentioned above ( ...

What is the best way to incorporate sub HTML projects into a Django project?

Currently, I am working on a Django project as well as some small HTML projects, including a few HTML5 games. How can I integrate the HTML site into my existing Django project? Each HTML project has its own folder containing numerous CSS, image, and JavaS ...

Prevent selection on all elements except for input fields with the type of text

I am facing a challenge where I need to prevent selection on a website page for everything except input[type=text] elements. The answer provided in this accepted response to a similar query almost solves the issue. However, it doesn't stop users from ...

Using jQuery to enhance the functionality of the drop-down select feature

I am facing an issue with my index file code. When I select something from the drop-down menu, I expect to see a related dropdown appear. Although I have added this code to my file, I am unable to get the drop down to show after selecting the main type. ...

The implementation of an onclick event in a freshly created HTML element is functioning solely on the final element

One issue I encountered was that when I generated page number buttons at the bottom of a page, the onclick event only worked with the last button created. Below is an example of how the page buttons were displayed: https://i.stack.imgur.com/wHwI0.png ...

Difficulty Aligning Angular Material Expansion Panel with mat-nav-listI am facing an issue with

Currently, I have implemented a mat-nav-list to showcase the Menu items on my webpage. However, there seems to be an alignment issue with the 4th Menu item which is an Angular Material Expansion control. Refer to the screenshot provided below for clarifica ...