Tips for incorporating extra space into a website design

I am in the process of building a webpage for my resume. To help me achieve a responsive design, I have turned to Bootstrap 4 but I am facing challenges when it comes to spacing different collapsible (div) elements.

After researching on w3schools, I discovered that using the HTML br tag can create a new line within a paragraph. However, this does not create a visible space between various elements.

Below is a snippet of my code:

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo">Simple collapsible</button>
  <div id="demo" class="collapse">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit,
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  </div>
  <p></p>
  <p>Some text here.</p>
</div>

</body>
</html>

Currently, I am utilizing an empty p tag (as shown above) to create space between a collapsible element and the subsequent one. Are there any other methods to add space? Or is this approach independent of the viewport/device?

Answer №1

Inject Your Own CSS into the Web Page

<style>
#custom{
     color: red;
}
</style>

Answer №2

If you are utilizing Bootstrap, take advantage of Bootstrap's spacing utilities to easily add spacing as needed.

For instance:

Transform

<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo">

into

<button type="button" class="btn btn-primary mb-3" data-toggle="collapse" data-target="#demo">

Notice the addition of the mb-3 class to the button? This creates space below it.

To learn more about bootstrap's spacing utilities, visit this link.

Answer №3

First of all, it's great that you are delving into learning HTML.

As I analyze your code, some issues stand out:

The use of div#demo to wrap text is recommended for content layout purposes as explained in the div documentation. If you require a text wrapper, it is better to utilize p (block) or span (inline), among other options.

By referring to the Browser DefaultValues, you will notice that the p tag automatically applies margins that may be missing from #demo.

To resolve this issue effortlessly, consider enclosing the first paragraph with the p tags:

<div id="demo" class="collapse">
  <p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  </p>
  <p>Some text here. </p>
<div>

Answer №4

You have the option to swap out the empty < p > tag with a line-break < br > tag

<div class="container">
  <button type="button" 
          class="btn btn-primary" 
          data-toggle="collapse" 
          data-target="#demo">
    Simple collapsible
  </button>
  <div id="demo" class="collapse">
   Lorem ipsum dolor sit amet, consectetur adipisicing elit,
   sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
   quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  </div>
  <br>
  <p>Additional content may be inserted here. </p>
</div>

Answer №5

My go-to is always <br />. Typically, I throw in around 3 or 4 to create some breathing room between the various components.

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 to style 1 out of every 3 div elements using absolute positioning in CSS

Imagine a setup where there is a banner at the top, with 3 divs placed side by side underneath it. The interesting part is that when you scroll down, only the center and right div should move along. #banner { background:blue; color:white; position ...

How can I make a jQuery function accessible globally or at the document level?

As a newcomer to jQuery and javascript, I am experimenting with different things and facing a specific issue. Let me break it down for you: -I have multiple individual .js files that contain code. However, I am struggling to load them before the code in t ...

Having trouble with HTML code displaying correctly in R leaflet for labels instead of popups

While working with leaflet in R Studio, I encountered an issue when trying to add HTML code to the labels of the icons. Strangely enough, it works for the popups but not for the labels. Below is the code snippet causing the problem: library(leaflet) libr ...

Showing the space between columns inline

.row { background: gray; margin-top: 20px; } .col-md-6 { border: solid 1px red; padding: 10px; } <!-- Bootstrap docs: https://getbootstrap.com/docs --> <div class="container"> <div class="row"> <div class="col-md-6"&g ...

Is the fixed div not behaving as expected inside a parent with relative positioning?

Seeking help to troubleshoot an issue I'm facing - I have two divs positioned relatively, with child elements positioned fixed within them. As I scroll the page, these two divs are supposed to become fixed to the top of the browser using the following ...

Generating dynamic colors from a map in SASS within a media query function

Utilizing @include-media for SASS breakpoints (). Seeking to create a dynamic breakpoint helper text that changes background color on various media sizes. Important Breakpoint mixin - https://raw.githubusercontent.com/eduardoboucas/include-media/master/d ...

Interactive horizontal web design with center alignment and dynamic scrolling feature

We have designed a unique web layout that is centered horizontally and includes an animated scrolling effect. There are 5 menu options that use simple anchor links to navigate between different pages. Our layout features static content with only the body s ...

How can I avoid columns from breaking in Bootstrap?

<div id="mydiv" class="bg-danger row"> <div> <img src="https://www.discoservicemusicheria.com/shop/wp-content/uploads/2013/03/Michael-Jackson-Thriller-25th-Anniversary.jpg" class="rounded float-left" width="280" height="280"> ...

Tips on personalizing buttons within Telerik form or Kendo form

Having recently started working with Telerik UI, I am struggling to customize a Kendo form in ASP.NET Razor Pages. Specifically, I am trying to rename a button but cannot locate the button field within the code. Despite following the guidelines provided in ...

dividing Handlebars HTML content into different files or sections

I am looking to design a single route webpage, but I would like to divide the HTML code into multiple files. When rendering this particular route, my goal is for the rendered file to pull content from different template files and combine them into one coh ...

Generate real-time dynamic line charts using data pulled directly from a MySQL database

I am in search of guidance on developing a real-time line chart that can dynamically update based on data fetched from MySQL. I need an example or reference on how to achieve this functionality without having to refresh the webpage every time new data is ...

As you scroll, this smooth marquee effect gently shimmers with each movement

I've been trying out this code to create a scrolling marquee text, but the issue is that after 7000 milliseconds it starts to jitter, which doesn't make the text look good. Any suggestions on how I can fix this problem? Let me know! <script ...

Use jQuery or Javascript to transform URLs within paragraphs into clickable hyperlinks

As someone who is new to javascript but familiar with jQuery, I've been attempting to utilize the following code to convert instances of www. and http in p tags into clickable links. The issue I'm facing is that while I can implement this code, ...

What are some effective ways to restrict users from downloading the HTML template from a demo site?

I'm looking to start selling HTML templates online, but I'm realizing that creating a demo page may lead users to simply download the template without purchasing it. How do other sellers prevent this from happening? What strategies can ...

What is the best way to display the most recent 5 posts with associated images after uploading them from a MySQL database?

The main objective is to display the most recent 5 posts along with their images after they are uploaded to the MySQL database. The project consists of 4 essential files: connection.php - successfully connects to the database new_post.php - allows adding ...

Utilizing the map function in React to create a button reference

I am currently facing an issue that is relatively simplistic and doesn't have any real-world application. My goal is to locate a 'green' button and make it blink for a duration of 3 seconds. How can I achieve this using React? const btnLay ...

How to Display an Element Using AngularJs

I'm facing an issue with angularjs where I am attempting to display an element by clicking a checkbox, but it isn't working. I suspect the problem lies in the ng-model, but I'm unsure why. Here is the HTML code in index.html: <body ...

Is there a way to assign a value to a select option in Angular 7?

The issue arises when attempting to modify the value, as it consistently displays the initial option selected. Here is the structure of my HTML code: <div class="col-lg-4 col-md-4 col-sm-12 mt-4"> <div class="form-group"& ...

Misalignment of Font-awesome icons in the footer section

I've implemented a footer on my website. My goal is to have the icons centered both vertically and horizontally, with the colored area: Always positioned at the bottom of the screen No taller than the icons themselves Here's the code snippet: ...

The input field stubbornly refuses to conform to the specified width

I have been working on making the search bar in the top right container responsive so that it shrinks down enough to prevent overlap with other icons. Here is an example of what I am trying to achieve: Image showing issue at 600px window size To achieve ...