Headlining the Border

My goal is to separate various headlines (along with their images) by using a bottom-border. I attempted this, but instead of putting a border between headlines, it ends up on the image.

Using jQuery

$(document).ready(function() {
  $.ajax({

    url: "https://newsapi.org/v2/top-headlines?sources=the-sport-bible&apiKey=7822ca100cdf43e1a85e1e101aa69c06",
    method: "GET",
    success: function(data) {
      processData(data);
    }
  });


  function processData(data) {
    var articleItems = [];
    for (var i = 0; i < 5; i++) {

      var author = data.articles[i].author;
      var title = data.articles[i].title;
      var description = data.articles[i].description;
      var urlToImage = data.articles[i].urlToImage;
      var artUrl = data.articles[i].url;


      var $author      = `<div class="author">Author: ${author}</div >`
      var $title       = `<a href="${artUrl}"><div class="title">${title}</div ></a>`
      var $description = `<a href="${artUrl}"><div class="description">${description}</div></a>`
      var $urlToImage  = `<a href="${artUrl}"><img class="urlToImage" src="${urlToImage}">`;

      $("#sport_news").append(`${author}${$title}${$description}${$urlToImage}`);
      $("#sport_news").append("<br />");

      console.log(artUrl);
    }
  }
});

When it comes to HTML

<div class="tab-pane fade" id="sport">
        <h3>SPORT</h3>
        <p id="sport_news"></p>
      </div>

Answer №1

Include the following lines at the top and bottom of your HTML code:

  $("#sport_news").append("<div style='border-bottom: 2px solid;' >");
  $("#sport_news").append(`${author}${$title}${$description}${$urlToImage}`);
  $("#sport_news").append("<br />");
  $("#sport_news").append("</div>");

To improve this code, it is recommended to add a class to the div and move the styling there.

The better approach would be to give the div a class attribute like this:

$("#sport_news").append("<div class='headline'>");

Then, define the 'headline' class in an external stylesheet as follows:

.headline
{
  border-bottom: 2px solid;
}

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 steps can I take to set a strict boundary for displaying the address closer to the current location?

While the autocomplete feature works perfectly for me, I encountered an issue where it suggests directions away from my current location when I start typing. I came across another code snippet that uses plain JavaScript to solve this problem by setting bou ...

Delicate seams break up the different sections of the webpage

I'm facing an issue with my website where thin lines are appearing between each section when previewed in Safari and Chrome, but not in Firefox (as shown in the images). I've checked the CSS code for each section in Dreamweaver, where the lines d ...

unexpected automatic scrolling that occurs when hovering over an element

a sudden scrolling takes effect simultaneously with hovering on an element. What confuses me more is that it does not happen every time I hover over the element but just occasionally or maybe there is a specific scrolling position that I can't see yet ...

Problem with overlapping content and navigation side bar in Bootstrap 4

Working on a project for my university, I utilized Bootstrap-4 to create various divisions - header, content-top-fat, content-bot-fat, and main-content. I aimed to fix the positioning of the header, content sections, and footer while allowing only the main ...

Combining jsTree with Treemodel for Enhanced Functionality

As someone new to Javascript, I'm looking for guidance on integrating jsTree on the front end with backend services in node.js. The backend utilizes the Treemodel library (http://jnuno.com/tree-model-js/) and includes additional functions like: funct ...

Snippets of the webpage peeking through before the Fakeloader takes over

After implementing fakeloader to preload my content here, I have noticed that my site header often appears before the fakeloader preload animation completes. Is there a way to delay showing the content until the fakeloader is finished loading? Here is the ...

Adjust the width of the dropdown menu for the v-combobox

I am currently working on creating a multiple search filter similar to the one found in Gitlab dashboard. https://i.sstatic.net/YHivl.png For this task, I am utilizing Vuetify's v-combobox like this : <v-combobox id="mycombo&quo ...

Ways to remain on the same page even after submitting a form

I've been searching for a solution to my specific issue for days, but haven't had any luck. Can anyone provide assistance? I have a form on my website that is supposed to send an email when clicked, while also converting the div from a form to a ...

The container's :before pseudo-element features a sleek white border

I have been experimenting with using the :before and :after pseudo-elements to generate diagonal lines within a container. However, I am encountering an issue where these pseudo-elements appear to have a white bottom border, and I am unable to determine t ...

Conceal a hidden element underneath a see-through layer featuring an adaptable background image spanning the entire webpage

Is there a way to create a "title bar" with text only, that stays fixed on top and the content below scrolls underneath it? Additionally, is it possible to make the title bar transparent for the background but not for the content below it? Also, can the s ...

Arrange three input fields horizontally with labels positioned above each

I am facing a minor problem with aligning three input fields in the same row while maintaining equal spacing between each of them. I attempted to accomplish this using display: flex and space-between, but then the label appears to the left of the input in ...

What is the button that switches the bootstrap modal?

With my bootstrap modal form, I have multiple buttons that trigger it as shown below: <a href="javascript:void(0)" data-toggle="modal" data-target="#specialoffer"> <button class="green full" id="button1">Ask Question</button> </a& ...

How do I change the 'CSS Theme' of my website?

With Halloween approaching, I am eager to transform my website's BODY css into a spooky Halloween theme. The challenge is that my .Net pages are Templates. Is there a way for me to ensure that the body class checks for an existing CSS theme override? ...

Tips for managing mouse over events in legends on highcharts

I have successfully implemented mouseover/mouseout event handling for donut slices. Please review my code below: http://jsfiddle.net/nyhmdtb8/6/ Currently, when I hover over a slice, it highlights that slice and greys out all others. Is it possible to ac ...

Dynamic horizontal div elements laid out in a repeating pattern using CSS Grid

I'm fairly new to CSS/Html/JS and I'd like to create a row of Boxes (loaded from a json file) displayed horizontally. Something similar to this: https://i.sstatic.net/ZgxMR.png Here's the code snippet I've been using: <style> ...

What is the best way to divide widgets in a Wordpress Sidebar?

I am looking to customize the spacing between widgets in my Wordpress sidebar, similar to what is shown on this example site. Currently, my sidebar does not have the desired spacing. I have tried various CSS codes found online, but none of them seem to be ...

What is the best way to extend a div to fill the full width of a webpage?

I'm struggling to align a div perfectly with the left, right, and top edges of the page. Despite trying various solutions suggested by others, I just can't seem to get it right! Any assistance would be greatly appreciated. Thank you. ...

Achieving uniform row height in CSS Grid Layout

How do I ensure all footers with a green background have the same height, while also keeping the content height consistent? Current result: https://i.sstatic.net/SrgFq.png Desired output: https://i.sstatic.net/4cr25.png CodePen: https://codepen.io/yas ...

Show a decimal value as an integer in Razor

Looking for assistance with razor code: @Html.DisplayFor(model => item.sepordan_melk_foroshes.ghamat_total) The current output is: 123.00 How can I remove the decimal and display it like this?: 123 Any help with this would be greatly appreciated. ...

Tips for personalizing the Bootstrap 5 color palette using CSS

After my previous question was closed as a duplicate, I am posting a new one as the previous answers did not solve my specific issue. The key points that need addressing are: The linked question addresses Bootstrap CSS customization here (9 answers). If ...