What is the best way to reduce the spacing between text?

I am trying to figure out how to reduce the spacing between my text so that it aligns like the example below. Take a look at the text "Welcome to my portfolio".

Currently, when I run my code, there is a large gap between "Welcome to my" and "Portfolio".

Below is the HTML snippet:

<h1 class="title4">WELCOME TO MY</h1>
<h1 class="title5">PORTFOLIO</h1>

Here is my CSS for styling:

.title4 {
text-align: center;
font-family: Arial;
color: white;
font-size: 45pt;
}
.title5 {
text-align: center;
font-family: Arial;
color: white;
font-size: 45pt;
}

Best regards, Liam.

Answer №1

Ensure that you add margin: 0; to all of your classes for consistency.

It's important to note the repetition in your code. Why not combine classes title4 and title5 into one single class?

body {
  background-color: black;
}


.title {
  text-align:middle;
  font-family:Arial;
  color:white;
  font-size:45pt;
  text-align:center;
  margin: 0;
}
<html>
    <body>
       <h1 class="title">WELCOME TO MY</h1>
       <h1 class="title">PORTFOLIO</h1>
    </body>

</html>

Answer №2

It's interesting that when discussing width, people often focus on adjusting the margin between titles. However, another aspect you can tweak is the spacing between letters.

If you include letter-spacing: 2px; in the h1 for "PORTFOLIO," you can increase the distance between letters and align it better with the width of "WELCOME TO MY." In my example using your code, I incorporated a 5px spacing to highlight the impact.

body {
  background-color: black;
}


.title {
  text-align: middle;
  font-family: Arial;
  color: white;
  font-size: 45pt;
  text-align: center;
  margin: 0;
}
.title2 {
  text-align: middle;
  font-family: Arial;
  color: white;
  font-size: 45pt;
  text-align: center;
  margin: 0;
  letter-spacing: 5px;
}
<html>
    <body>
       <h1 class="title">WELCOME TO MY</h1>
       <h1 class="title2">PORTFOLIO</h1>
    </body>

</html>

Answer №3

give this a shot

.style123 {
text-align:center;
font-family:Helvetica;
color:blue;
font-size:30pt;
margin-bottom:20px;
}
.style456 {
text-align:center;
font-family:Times New Roman;
color:green;
font-size:35pt;
margin-top: 10px
}

Answer №4

body {
  background-color: black;
}

.title4 {
  font-family: Arial;
  color: white;
  font-size: 45pt;
  text-align: center;
  margin: 0px;
}
.title5 {
  font-family: Arial;
  color: white;
  font-size: 45pt;
  text-align: center;
  margin: 0px;
}
<html>
  <head>
  </head>
  <body>
    <h1 class="title4">WELCOME TO MY</h1>
    <h1 class="title5">CHECK OUT MY WORK</h1>
  </body>
</html>

Answer №5

If you want to adjust the distance between your two div elements, simply include this code:

padding-top: -15px;

Add this line to your .title5 class. You can see the changes in action by checking out this live demo: https://jsfiddle.net/h6s7fg3m/1/

It's important to understand the distinction between padding and margin, as they serve different purposes and have their own unique benefits.

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

What is the best way to center align an element vertically in my specific situation

Struggling to vertically align elements within a div? Here's a snippet of code that might help: Here's a sample of what you might have: html <div class="test"> <a href="#"><img src="test.png"/></a> <a href="# ...

Mastering the Art of Line Breaks in WordPress

I am looking for a way to break a WordPress site title over two lines at a specific point in the text. Since the WordPress content filter 'wpautop' disables the ` ` tag (also known as ` ` or ` `), I'm wondering what the best alternative ...

What is the best way to organize large amounts of data into an array?

I am currently working on developing a unique version of wordle using javascript and html. In order to do this, I require a comprehensive list of all possible wordle words stored in an array format. Although I have the words listed within a document contai ...

Issues with the creation of an AngularJS table are causing functionality to malfunction

2021 UPDATE: Note: This question was drafted when I was still learning HTML and JS. If you are seeking assistance for an issue, this might not be very useful as my code was messy. Sorry for any inconvenience caused. The question will remain posted in acco ...

The xModal window will only pop up once, after which a page refresh is required

My modal window opens when a user clicks on a div, but I'm having an issue. The modal window doesn't reopen when I click on the div again. Here is my code: <div onclick="document.getElementById('id01').style.display='block&apos ...

Move the footer down to the bottom of the page

I'm struggling to create a footer that consistently stays at the bottom of the page, regardless of the amount of content on the page. I've tried following various tutorials but haven't had much success. I'm starting to think I must be d ...

Finding text outside of a HTML tag with jsoup

I am working with the following HTML code: Data <div class="alg"></div> <div class="alg"></div> Pepsi 791 <div class="alg"></div> <div class="alg"></ ...

Challenges with z-index in Chrome/Safari and Firefox when nesting elements

In the current setup, it seems that .second needs to be positioned above .third, which is only happening in Firefox. Unfortunately, I am facing difficulty as I cannot separate .second from .fifth. Just to provide some context: .third is intended to act as ...

Steps for activating all iframes on an HTML page

Seeking a solution to enable all iframes on my webpage without encountering the 'refused to connect' error. Is it feasible with the implementation of a meta tag? If yes, could someone provide a code snippet for reference? ...

Can you explain the significance of this?

Some may find this question silly, but I'm curious about the meaning behind certain elements in an ASPX page. For example, when there is code like this: <%@ Page Title="[$TITLES_listevents{uneditable}]" Language="C#" MasterPageFile="~/sitebase ...

HTML is unable to recognize the CSS file. Maven and Spring are the solutions

I'm having some trouble connecting my CSS to my HTML. This is the structure of my folders: https://i.sstatic.net/B9bHx.png Here is my HTML code: https://i.sstatic.net/XyE4E.png I've tried several methods to make it work. Interestingly, every ...

Go back to the top by clicking on the image

Can you help me with a quick query? Is it feasible to automatically scroll back to the top after clicking on an image that serves as a reference to jQuery content? For instance, if I select an image in the "Portfolio" section of , I would like to be tak ...

Internet Explorer 10 offers 3D transformation capabilities

My 3D rotating image carousel works well in Chrome and Firefox but not in IE. I am aware that IE10+ does not fully support the preserve-3d tag, and although there are workarounds by applying transforms to the children instead, I have been unsuccessful in ...

Is there a way to ensure that the images in the slider all remain consistent in size?

I recently created a slider using bootstrap and encountered an issue with image display on mobile screens compared to laptop screens. On a Laptop screen: On a Mobile screen: The images on the mobile screen are not fitting properly within the slider, and ...

Time to reverse the string

I currently have a timestamp formatted like this: Thu Sep 12 04:28:37 +0000 2013 While I am aware that PHP's strtotime function allows for inputting things like '2 days ago' or 'last week', my goal is to take the existing timesta ...

What is the best way to showcase an image using CSS on my personal computer?

It's a bit embarrassing to admit, but I'm learning some new concepts and struggling with this one. On my computer, there's a folder named Test that contains an index.html file, a CSS subfolder with an index.css file, and an images subfolder ...

Showing the values of selected checkboxes in a select dropdown - here's how!

Link to the jsfiddle : https://jsfiddle.net/a1gsgh11/9/ The JavaScript code seems to not be working on the js fiddle platform. My main concern is that I would like the selected checkbox values to display immediately without needing to submit any buttons. ...

The desired hover effect on the navigation bar is not functioning properly

I have successfully created a hover effect for my navigation bar and the list inside it. However, I am facing an issue where the box shadow effect is only appearing in a small area when hovered (see image below). My goal is to extend the shadow effect to ...

Center the element vertically if its height is less than the container's height, but let its height become 100% if the container's height is

I am trying to achieve a layout where an element (.figure) is centered horizontally when it is shorter than its container (.timeline-content), but matches the height of its container when longer. The height of the container changes based on its parent. T ...

"Struggling with vertical alignment in my scenario, any tips on how to achieve

I'm trying to vertically align my texts while ensuring that the green background div covers the entire height of the red color div. Right now, the green div only covers 90% of the red div and I'm not sure why. Can someone please explain what&apos ...