<p> The box is massive, and its size is a mystery to me

https://i.sstatic.net/xPoDz.png

Why is the box around my paragraph tag so large? I suspect this could be why I am unable to move the <p> tag down with margin-top: 50px;

.train p {
  margin: 0;
  font-size: 2.5vw;
}
<div class="train">
  <p class="train">In Training</p>
  <hr>
</div>

Answer №1

The <p> element is considered a block-level element. These elements take up the full width available and start on a new line within their containing parent. To style specific parts, consider using a span element for targeted styling.

Answer №2

Here is a simple example for you to observe the issue (also useful for debugging HTML/CSS). The <p> and <div> elements are by default considered as block level.

https://i.sstatic.net/2GWiE.png

I highly recommend spending 3 minutes to go through the following link:

REF:

p.train {
  margin: 0;
  font-size: 2.5vw;
  background: red;
}
<div>
  <p class="train">In Training</p>
  <hr>
</div>

Solution:

To resolve this, set the p element to inline-block.

or

You can also use a span, which is an inline element:

p.train {
  margin: 0;
  font-size: 2.5vw;
  background: red;
  display: inline-block;
}
.green {
  margin: 0;
  font-size: 2.5vw;
  background: red;
}
<div>
  <p class="train">In Training</p>
  <hr>
  <span class="green">In Training</span>
</div>

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

How can an SVG circular progress bar be created using stroke dasharray?

Can anyone help me with adding dashes between the line in this progress bar I'm trying to recreate? Any suggestions would be greatly appreciated. https://i.sstatic.net/KdwtzYGy.png This is my progress so far: https://i.sstatic.net/3KTjic5l.png I h ...

Encoding data using Angular

I have encountered a situation where my code needs to retrieve table numbers using Javascript and PHP as the database connector. However, when the code works successfully, it displays both the parameter name and value, but I only need the value. How can I ...

HTML input form - issue with combining multiple patterns

Below is a section of my HTML code: <input type="text" #version tabindex="1" class="form-control" id="version" name="version" placeholder="" [(ngModel)]="application.version" required minlength="1" pattern="\d{1 ...

AngularJS Filter from "start to finish" in values

I have been searching everywhere for a solution to this problem, but haven't found one yet. Any help would be greatly appreciated. Angular: var app = angular.module('app', []); app.controller('theController', ['$scope', ...

Tips for extracting data from cells within an HTML table using JavaScript

I am looking to extract the values from a cell of an HTML table in order to store them in a MySQL table using PHP. I prefer to utilize JavaScript instead of jQuery. I have assigned a unique ID to each TR based on the ID field in the MySQL table. Additiona ...

Develop a reusable block of Vue template when creating a new component

There are times when I find myself needing to repeat certain sections of HTML code in my Template just to keep it DRY. However, creating a new component and passing multiple props and dynamic data seems like too much work. Is there a simpler way to define ...

Click once to expand all rows in the table with ease

I have successfully created a basic table using HTML. The table includes nested elements that are designed to open individually when clicked on the assigned toggle. Essentially, clicking on a '+' icon should reveal a sub-menu, and clicking on a & ...

Is there a way to display the avatar image outside of the drawer in MUI ReactJS?

Currently, I am attempting to display the avatar image with a curved effect outside the border line of the sidebar. I have referenced the persistent drawer from MUI v5 for inspiration. You can view an example here: the codesandbox link The desired outcom ...

The utilization of bootstrap can lead to CSS interruptions

I am trying to create a navigation button that transforms from 3 horizontal lines to an X shape when clicked. var anchor = document.querySelectorAll('button'); [].forEach.call(anchor, function(anchor) { var open = false; an ...

What is the best way to avoid having multiple files in a JavaScript file input when a user selects a new file?

I am trying to implement a file input using vanilla JavaScript, and my goal is to restrict the user to uploading only a single file at a time. The issue I am facing is that if the user repeatedly selects a file and clicks the upload button, the file gets ...

Exploring the depths of HTML with the Agility Pack

Looking to extract specific elements from my HTML code: <div id="mailbox" class="div-w div-m-0"> <h2 class="h-line">InBox</h2> <div id="mailbox-table"> <table id="maillist"> <tr> ...

The header bar intrudes into the main content area

I am in the process of transitioning my landing page design from Bootstrap to Semantic-UI. The layout includes a fixed top navbar and main content split into two columns (3-cols and 9-cols) - the left column is reserved for a sidebar, while the right colum ...

The fixed table header is covering the navigation bar

Currently, I am building a website using Bootstrap and the DataTables library. The problem I am encountering is that the sticky table header is working fine, but it overlaps with the sticky nav bar. Is there a way to make the navbar "push down" the table h ...

showing the angular response data in a HTML table layout within a specific div element

I'm currently using the angular-fullstack generator and I've received data in response to a GET request in the form of integer values (1, 2 5, 6 134, 245 236, 567 415, 234 and so on). I'd like to display these values in an HTML t ...

When utilizing the tab key on Chrome, the iFrame fails to scroll

We are currently facing an issue with our web application that is embedded inside an iFrame. On one of our HTML pages, there are numerous textboxes with a large amount of content, requiring users to scroll down to navigate through it all. When using the ...

Determine whether the textfield is a number or not upon losing focus

I'm seeking advice on implementing a feature using jQuery and JavaScript. I want to create a text field that, when something is inputted, will automatically add .00 at the end if it's only a number. However, if someone inputs something like 2.00, ...

I am having trouble understanding why dropdown menus with the same content have varying widths

My issue is illustrated in the screenshots below: first-dropdown: second-dropdown: The second dropdown appears slightly wider on the right side. Despite Google Chrome's claim that the widths are the same. HTML code: <div class="row menu"> ...

I aim to have the capability to read numbers entered into text fields within a form prior to the form being submitted

I am currently working on a website where users can create brackets for the World Cup by guessing scores and winning teams. Right now, they have to manually fill in the bracket. I would like to implement a feature that reads what users are inputting while ...

Tips for selecting a dropdown item that shares the same data-testid

I am attempting to use Selenium to click on an option in a dropdown menu. The options all have the same 'data-testid', and the only unique identifier appears to be the link text. Does anyone know of a way to select a specific choice within the dr ...

The mobile website is not adjusting to the viewport size as expected

I'm currently working on a website and experimenting with responsive design. Unfortunately, I'm facing an issue where every mobile browser is not scaling the site properly. Regardless of the browser, the site appears as 1000px or wider. I have at ...