Can <p> be utilized without creating empty space at the top or bottom?

Is there a way to use paragraph breaks without any space at the top or bottom when there's no text above or below it?

body {
    font-family:arial;
    background:#222;
}

#wrapper {
    width:100%;
    margin-top:100px;
}

.post_container {
    background:#fff;
    border:1px solid red;
    width:500px;
    height:auto;
    text-align:justify;
    padding:15px;
    margin:0 auto;
    margin-bottom:50px;
}

.post {
    font-size:16px;
}

<body>
<div id="wrapper">

<div class="post_container">

<div class="post">

    <div style="height:auto;max-height:550px;overflow:auto;scrollbar-width:none;">

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Orci ac auctor augue mauris augue. Amet aliquam id diam maecenas ultricies mi. Mi quis hendrerit dolor magna eget est. Pharetra magna ac placerat vestibulum lectus. Sagittis vitae et leo duis. Id nibh tortor id aliquet. Nullam non nisi est sit. Urna molestie at elementum eu facilisis. Pellentesque id nibh tortor id aliquet. Eget nullam non nisi est sit. Velit sed ullamcorper morbi tincidunt. Ac auctor augue mauris augue. Velit aliquet sagittis id consectetur. Amet justo donec enim diam vulputate ut pharetra sit. Lobortis mattis aliq...
    
</div> <!-- scroll style  -->
</div> <!-- post -->
</div> <!-- post container -->
</body>

Answer №1

There is currently 15px of padding applied to the post_container. To eliminate the top and bottom padding, you can update it to padding: 0 15px;. Additionally, you will need to modify the default paragraph style with margin: 1em, as mentioned by others. Here is one approach:

body {
    font-family:arial;
    background:#222;
}

#wrapper {
    width:100%;
    margin-top:100px;
}

.post_container {
    background:#fff;
    border:1px solid red;
    width:500px;
    height:auto;
    text-align:justify;
    padding:0 15px;
    margin:0 auto;
    margin-bottom:50px;
}

.post {
    font-size:16px;
}
<div id="wrapper">
  <div class="post_container">
    <div class="post">
      <div style="max-height:550px;overflow:auto;scrollbar-width:none;">
        <p style="margin: 0;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
        <p>At lectus urna duis convallis convallis tellus id. Egestas sed sed risus pretium quam vulputate dignissim. Tristique senectus et netus et malesuada fames ac turpis. Volutpat commodo sed egestas egestas fringilla. </p>
        <p style="margin: 0;">Fringilla ut morbi tincidunt augue interdum velit euismod. Mi quis hendrerit dolor magna eget. Ultricies integ</p>
      </div> <!-- scroll style  -->
    </div> <!-- post -->
  </div> <!-- post container -->

Answer №2

Include the code snippet below in your .css stylesheet:

p {
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
}

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

Error: Unable to access the 'nom_gr' property of null - encountered in Chrome

<ion-col col-9 class="sildes"> <ion-slides slidesPerView="{{nbPerPage}}" spaceBetween="5"> <ion-slide *ngFor="let slide of lesClassrooms; let i = index" (click)="saveCurrentSlide(i)"> ...

storing a value in the browser's local storage

I am in the process of creating a new game that includes a high score feature. The idea is that when the current score surpasses the existing one stored locally, it will be replaced: localStorage.setItem('highScore', highScore); var HighScore = ...

Issues arise in mobile Safari when attempting to load JavaScript files, resulting in

Encountering an issue with my Angular app on mobile Safari during the initial load, where it hangs on a blank page for nearly 2 minutes. Interestingly, the app functions perfectly on other browsers, including Mac Safari and iPad Safari. Initially, I suspe ...

"I am looking for a way to retrieve dynamic data from a (click) event in Angular. Can

Within my component, I have a video loaded in an i tag on a click event. The challenge is accessing the video ID from the video.component.ts file in order to dynamically load a new video. The solution has been elusive so far. <li *ngFor="let video of c ...

Problem with loading image from local path in Angular 7

I'm having trouble loading images from a local path in my project. The images are not rendering, but they do load from the internet. Can someone please help me figure out how to load images from a local path? I have already created a folder for the im ...

Positioning elements at the bottom of the container

There is a dilemma that only those in the world of web development will understand. Beware! I have envisioned a layout for a website I am constructing. The concept involves tilted <hr/> elements on the page, with text wrapping around them (refer to ...

Stop jQuery ajax from running any JavaScript code contained in a script or HTML response

As stated in the documentation: If html is specified, any embedded JavaScript within the retrieved data will be executed before returning the HTML as a string. Similarly, using script will execute the pulled back JavaScript before returning nothing. Is ...

"Placing the save button on top of a div - a step

I am trying to position a div with an ID below a save button in my HTML code. The current setup looks like this: <button id="item_new" data-action="create" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button- ...

CSS for two columns with a width of 50% each

Below is a table for reference: <table width="100%"> <tr> <td id="td1"></td> <td id="td2"></td> <td id="td3"></td> <td id="td4"></td> </tr> </table> Is there a wa ...

Stringified HTML code showcased

When working with Angular, I have encountered an issue where I am calling a function inside an .html file that returns a string containing a table element. My goal is to convert this string into HTML code. I attempted to use [innerHtml]: <p [innerHtml ...

Switching up icons using React Spring - a step-by-step guide!

Is it possible to change the icon when I click on it using react spring? For example, if I click on " ...

Confusion between Codeigniter's URL and base_url() function

$config['base_url'] = 'localhost/project'; <link href="<?= base_url(); ?>/css/bootstrap.min.css" rel="stylesheet"> An issue arises with the CSS not loading on the view due to a double '/' in the URL. This occur ...

Problem with AJAX updating CSS class

My HTML table features a column that displays a Yes/No option. When a user switches the option from Yes to No or vice versa, it triggers an AJAX call to a PHP script which updates the corresponding record in the database. Everything is functioning correctl ...

Tips for maintaining the fixed size of a table header and preventing it from resizing in width

My goal was to create a table using divs with fixed headers while scrolling vertically. However, I encountered an issue where the header width seemed to shrink and became misaligned with the rows. Even setting the width to 100% did not resolve this probl ...

V5 Modal & jQuery: troubleshooting the spinner problem during loading of content

I'm working on displaying a spinner while loading modal content with the use of bootstrap v5 modal and jQuery. However, I encountered some issues in my example. The spinner does not display again after closing the modal; it only shows for the first t ...

I am attempting to integrate a datetimepicker onto my website, but I keep encountering an error. Can

Once upon a time, my website had a perfectly functioning datetimepicker. However, one day it suddenly stopped working. After some investigation, I realized that the JavaScript file I was referencing had been taken down. Determined to fix the issue, I visit ...

Can you identify the specific name of the IE CSS bug affecting double vertical padding?

(Just when I thought I've encountered all the strange IE CSS bugs, here comes another one. Is there a name for this double-vertical-padding bug?) After creating a simple test case that worked perfectly in browsers like FF and Opera, I was surprised t ...

Adjust the font size of MaterialUI icons using CSS

I am currently facing an issue where I need to increase the size of my icons by 200px, but they are defaulting to 24px which is the standard for all Google Icons. Any suggestions on how to solve this? HTML <div class="col span-1-of-4 box"> <i ...

Steps for encoding a CSV export with HTML:

When I retrieve data from a string that is HTML encoded as Quattrode® I end up with Quattrode® after viewing it in Excel 2007. Here is the routine: Response.Clear(); Response.Buffer = true; Response.ContentType = "text/ ...

Transform a div's style when hovering over another div using absolute positioning without repetition

I am facing an issue with multiple divs positioned absolutely on top of a primary div with relative positioning. I want one specific div to change its background-color when hovering over another div within the same parent div. Though I know about ad ...