Delete the line-height property from the initial line

I have created text that is aligned using the "justify" option, and I would like to add some leading to the text. However, I want the first line of the text to remain at x:0px y:0px.

Does anyone know how to remove the line-height from the first line of a paragraph tag?

Check out this link for more information

body {
    margin:0;   
    padding:0;
}
.test {
    font-family:"verdana";
    font-size:25px;
    line-height:150px;
    background:yellow;
}
p::first-line {
    //line-height:0 !important; //this code doesn't seem to work
}

https://i.sstatic.net/FDmzr.jpg

EDIT: The solution needs to be compatible with all browsers,

p:first-line { DOESN'T WORK IN MOZILLA FIREFOX
    line-height:100% !important;
}

Answer №1

After experimenting with the jsfiddle you provided, I discovered that the solution below was effective.

p:first-line {
    line-height:100% !important;
}

I trust that my response has addressed your concern. Wishing you a fantastic day ahead!

Answer №2

To adjust the layout, you can use a negative margin to move the content upward.

body {
margin:0;
padding:0;
}
.test {
font-family:"verdana";
font-size:25px;
line-height:150px;
background:yellow;
margin-top:-60px;
}
p::first-line {

}
<p class="test" align="justify">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare odio metus, ut volutpat turpis mollis id. Aliquam sed risus congue, pulvinar erat a, fringilla ipsum. Duis posuere facilisis mauris vel fringilla. Etiam vel urna pharetra, vestibulum lectus eget, semper velit. Morbi eget nibh fringilla, hendrerit sem sollicitudin, aliquam enim. Quisque pulvinar felis vel lacinia cursus. Sed ullamcorper nisi nec sapien aliquet, et consequat nibh ultricies. Nullam et faucibus ante. Nam nec lectus varius, gravida purus et, faucibus justo. 
</p>

Answer №3

To achieve the effect of line-height: 0; on the first line, you can also utilize a pseudo element with a vertical negative margin matching the line-height value. This will shift the content upwards:

body {
  margin: 0;
  padding: 0;
}
.test {
  font-family: "verdana";
  font-size: 25px;
  line-height: 150px;
  background: yellow;
}
p:before {
  content: '';
  display: block;
  margin: -3em 0;/* 25px = 1em/font-size  150/25 = 6 . margin-top/bottom -3em = 6em */
}
<p class="test" align="justify">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare odio metus, ut volutpat turpis mollis id. Aliquam sed risus congue, pulvinar erat a, fringilla ipsum. Duis posuere facilisis mauris vel fringilla. Etiam vel urna pharetra, vestibulum
  lectus eget, semper velit. Morbi eget nibh fringilla, hendrerit sem sollicitudin, aliquam enim. Quisque pulvinar felis vel lacinia cursus. Sed ullamcorper nisi nec sapien aliquet, et consequat nibh ultricies. Nullam et faucibus ante. Nam nec lectus
  varius, gravida purus et, faucibus justo.
</p>

Link to example

Answer №4

One way to format paragraphs is to enclose each one in a P tag and utilize the first-child pseudo option.

To see an example, you can visit this link.

body {
  margin: 0;
  padding: 0;
  font-family: "verdana";
  font-size: 25px; 
  background: yellow;
  text-align: justify;
}

#wrap p.test {
  line-height: 150px;
}

#wrap p.test:first-child {
  line-height: normal;
}




<div id="wrap">
  <p class="test">
    Lorem ipsum dolor sit amet, consectetur adipiscing
  </p>
  <p class="test">
    Lorem ipsum dolor sit amet, consectetur adipiscing
  </p>
  <p class="test">
    Lorem ipsum dolor sit amet, consectetur adipiscing
  </p>
  <p class="test">
    Lorem ipsum dolor sit amet, consectetur adipiscing
  </p>
</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

What is the best way to showcase a blank div element using CSS?

Is there a way to make this empty div tag display without having to add &nbsp;? Can it be achieved using only CSS? <div class="bar bg-success" title="2015-07-23,5.0000" height="50%"></div> .bar { background: green; width: 5px; float ...

If the user confirms it with a bootstrap dialog box, they will be redirected to the corresponding links

Firstly, I am not interested in using javascript confirm for this purpose. Please read on. For example, adding an onClick attribute to each link with a function that triggers a system dialog box is not what I want. Instead of the standard system dialog bo ...

Responsive on Mobile Devices

I'm seeking assistance in brainstorming a creative idea or method to convert the carousel indicators into a menu, or any alternative approach to ensure the entire section is mobile responsive while keeping all the indicators visible within the mobile ...

Dynamic CSS Changes in AngularJS Animations

I am currently working on a multi-stage web form using AngularJS. You can see an example of this form in action by visiting the link below: http://codepen.io/kwakwak/full/kvEig When clicking the "Next" button, the form slides to the right smoothly. Howev ...

Troubleshooting inconsistent htaccess changes across different pages?

After much trial and error, I have successfully managed to run PHP code within a document that has either an .htm or .html extension. The solution that worked for me was adding the following line of code: AddType application/x-httpd-php .php .html .htm N ...

Mobile phone web development using HTML5

I am currently facing an issue with playing sound on mobile browsers. In my code snippet, I have the following: Response.Write("<embed height='0' width='0' src='Ses.wav' />"); While this works perfectly fine on desktop ...

Ways to remove border when image is not present

I've been attempting to use JavaScript to hide the border, but it doesn't seem to be working. Is it possible to hide the border in HTML using Java? ......................... Check out my page here Here is a snippet of my HTML: <!-- Single P ...

Leverage JSON as the primary data source for Assemble.io

Can Assemble.io be used to compile json files into HTML using templates? If so, how can I configure my gruntfile to accomplish this? Overview of My Folder Structure: Data productlist1.json productlist2.json productlist3.json productdetail1.json product ...

Angular: "btn" class vanishes when the button is toggled

I am facing an issue with the button's class change functionality. I am using the [ngClass] directive to switch between Bootstrap classes for the button style. However, when I click the button, the "btn" class seems to disappear from the code. Instead ...

One way to create dynamic function parameters in JavaScript is by using

Currently, I am in the process of implementing a payment API checkout feature on my order.html page. However, I have encountered an issue where I need to add a script in the head of the HTML document. This script requires me to specify the subtotal amoun ...

Library for HTML styling in JavaScript

Is there a reliable JavaScript library that can automatically format an HTML code string? I have a string variable containing unformatted HTML and I'm looking for a simple solution to beautify it with just one function call. I checked npmjs.com but co ...

Is there a way to grab code from a different HTML page using JavaScript and jQuery when the user clicks on something?

After testing various codes for the intended purpose mentioned in the title, I have observed a peculiar behavior. The code from settings.html appears briefly and then disappears rapidly. Javascript: function load() { $("#paste").load("settings.html") ...

The minimum and maximum validation functions are triggered when I am not utilizing array controls, but they do not seem to work when I use array controls

Take a look at the stack blitz example where min and max validation is triggered: https://stackblitz.com/edit/angular-mat-form-field-icrmfw However, in the following stack blitz with an array of the same controls, the validation does not seem to be worki ...

An error has occurred in the Shadow Dom due to the inability to access the property 'style' of an

While working on a component using shadow DOM, I encountered the following error in the console: "Cannot read property 'style' of undefined". This issue seems to be related to my HTML code in PHP. The main challenge I am facing is figuring out ho ...

Setting predefined data in an HTML field from XML within the Odoo platform

In the model.py file of my project, I have defined an HTML field as follows: from odoo import models, fields class TestModel(models.model): _name = 'test.model' content = fields.HTML() To display the data from this model, I have used &l ...

Exploring Vue and Webpack's tree shaking functionality, side effects management, and its impact on CSS: Loading unused component CSS

We are currently grappling with the challenge of effectively implementing tree shaking for CSS within Vue Single File Components using Webpack. Within our package.json file, we have specified: "sideEffects": ["*.css", "*.less","*.vue"], which appears to b ...

A complete guide on utilizing *ngFor in Angular to display data rows

I am facing an issue with using *ngFor to create new "rows" for adding new categories dynamically. Although there are no errors displayed when I run the program, the intended functionality is not achieved. I have tried making some modifications but it see ...

Difficulty with aligning textfield controls to the right

I'm currently working on adding StaticTextField controls to a page. We are using ExtJS, but we incorporate VB.NET methods for implementing ExtJS so manual coding isn't necessary. So far, I attempted to align the text to the right by using this c ...

Automatically resize ui-select dropdown box to the left side

I've been tasked with incorporating AngularJS ui-select into my project, specifically creating a multiselect dropdown. Currently, the dropdown box automatically adjusts its width based on the length of the longest selectable text, causing it to extend ...

displaying an item within a text field

I have an input box created using Angular reactive forms <input type="text" formControlName="OrgName" placeholder="Enter name" maxlength="60"> <p class="fieldRequired" *ngIf="showNameMSg" ...