Issues arise when attempting to display articles using inline-block styling

I have been diving into the world of HTML and CSS in an attempt to broaden my skillset. However, while working on an exercise, I encountered a roadblock. The challenge lies in having the 4 articles within the

<section id="news">
to display side by side. Alas, I couldn't quite crack the code to unravel what's causing this issue.

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

body {
  font-family: Arial, Helvetica, sans-serif;
  background-color: #1A4575;
}

header {
  background-color: #2F5075;
  width: 600px;
  text-align: center;
  margin: 10px;
}

nav {
  display: inline-block;
}

nav>a {
  text-decoration: none;
  background-color: #2B71C2;
  color: white;
}

nav>a:hover {
  color: #80B7F7;
}

header>h1 {
  display: inline-block;
}

section#breaking>article {
  width: 700px;
  background-color: rgba(172, 35, 35, 0.719);
  color: white;
  font-size: 20px;
  margin: 5px;
  padding: 3.5px;
}

section#news {
  background-color: #2B88C2;
}

section#news>article {
  width: 400px;
  height: 250px;
  display: inline-block;
  background-color: white;
  color: black;
  border: 3px solid black;
  margin: 5px 5px 5px 5px;
  padding: 5px 5px;
}

section#news>h1 {
  text-align: center;
  padding: 5px;
}

aside {
  background-color: #1A4575;
  color: white;
}

footer {
  background-color: #2F5075;
  text-align: center;
  color: #368FF5;
}
<header>
  <h1>Menu</h1>
  <nav>
    <a href="#">a</a>
    <a href="#">b</a>
    <a href="#">c</a>
    <a href="#">d</a>
    <a href="#">e</a>
  </nav>

</header>
<main>
  <section id="breaking">
    <article>
      <h2>Breaking news</h2>
      <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Assumenda culpa asperiores voluptate. Eius pariatur vero, at repellendus sunt sequi ad qui doloribus excepturi provident ipsam, libero deleniti culpa nihil et.</p>
      <aside>
        <p>Written by João Marcelo</p>
      </aside>
    </article>
  </section>
  <section id="news">
    <h1>Daily News</h1>
    <article>
      <h2>Title 1</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Impedit amet facilis officia ex eos quae possimus nisi, nostrum saepe, debitis obcaecati ea doloribus adipisci, soluta veritatis! Deserunt quam molestias ut.
      </p>
      <aside>
        <p>Written by Pedro Henrique Vasconcelos</p>
      </aside>
    </article>

    <article>
      <h2>Title 2</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Commodi asperiores quo omnis fugit error ipsum provident aut libero consequatur minima illo, distinctio sed, culpa temporibus deserunt obcaecati quidem. Quia, assumenda.
      </p>
      <aside>
        <p>Written by Leonardo Alves de Paiva</p>
      </aside>
    </article>
    <article>
      <h2>Title 3</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Commodi asperiores quo omnis fugit error ipsum provident aut libero consequatur minima illo, distinctio sed, culpa temporibus deserunt obcaecati quidem. Quia, assumenda.
      </p>
      <aside>
        <p>Written by Beatriz halfd</p>
      </aside>
    </article>
    <article>
      <h2>Title 4</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Commodi asperiores quo omnis fugit error ipsum provident aut libero consequatur minima illo, distinctio sed, culpa temporibus deserunt obcaecati quidem. Quia, assumenda.
      </p>
      <aside>
        <p>Written by Joana Bohemia</p>
      </aside>
    </article>
  </section>
</main>
<footer>
  <p>Developed by Leonardo</p>
</footer>

Answer №1

Adjust the alignment to top for the articles. The default setting is baseline.

body {
  font-family: Arial, Helvetica, sans-serif;
  background-color: #1A4575;
}

header {
  background-color: #2F5075;
  width: 600px;
  text-align: center;
  margin: 10px;
}

nav {
  display: inline-block;
}

nav>a {
  text-decoration: none;
  background-color: #2B71C2;
  color: white;
}

nav>a:hover {
  color: #80B7F7;
}

header>h1 {
  display: inline-block;
}

section#breaking>article {
  width: 700px;
  background-color: rgba(172, 35, 35, 0.719);
  color: white;
  font-size: 20px;
  margin: 5px;
  padding: 3.5px;
}

section#news {
  background-color: #2B88C2;
}

section#news>article {
  width: 400px;
  height: 250px;
  display: inline-block;
  background-color: white;
  color: black;
  border: 3px solid black;
  margin: 5px 5px 5px 5px;
  padding: 5px 5px;
  vertical-align:top;
}

section#news>h1 {
  text-align: center;
  padding: 5px;
}

aside {
  background-color: #1A4575;
  color: white;
}

footer {
  background-color: #2F5075;
  text-align: center;
  color: #368FF5;
}
<header>
  <h1>Menu</h1>
  <nav>
    <a href="#">a</a>
    <a href="#">b</a>
    <a href="#">c</a>
    <a href="#">d</a>
    <a href="#">e</a>
  </nav>

</header>
<main>
  <section id="breaking">
    <article>
      <h2>Breaking news</h2>
      <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Assumenda culpa asperiores voluptate. Eius pariatur vero, at repellendus sunt sequi ad qui doloribus excepturi provident ipsam, libero deleniti culpa nihil et.</p>
      <aside>
        <p>Written by João Marcelo</p>
      </aside>
    </article>
  </section>
  <section id="news">
    <h1>Daily News</h1>
    <article>
      <h2>Title 1</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Impedit amet facilis officia ex eos quae possimus nisi, nostrum saepe, debitis obcaecati ea doloribus adipisci, soluta veritatis! Deserunt quam molestias ut.
      </p>
      <aside>
        <p>Written by Pedro Henrique Vasconcelos</p>
      </aside>
    </article>

    <article>
      <h2>Title 2</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Commodi asperiores quo omnis fugit error ipsum provident aut libero consequatur minima illo, distinctio sed, culpa temporibus deserunt obcaecati quidem. Quia, assumenda.
      </p>
      <aside>
        <p>Written by Leonardo Alves de Paiva</p>
      </aside>
    </article>
    <article>
      <h2>Title 3</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Commodi asperiores quo omnis fugit error ipsum provident aut libero consequatur minima illo, distinctio sed, culpa temporibus deserunt obcaecati quidem. Quia, assumenda.
      </p>
      <aside>
        <p>Written by Beatriz halfd</p>
      </aside>
    </article>
    <article>
      <h2>Title 4</h2>
      <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Commodi asperiores quo omnis fugit error ipsum provident aut libero consequatur minima illo, distinctio sed, culpa temporibus deserunt obcaecati quidem. Quia, assumenda.
      </p>
      <aside>
        <p>Written by Joana Bohemia</p>
      </aside>
    </article>
  </section>
</main>
<footer>
  <p>Developed by Leonardo</p>
</footer>

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

Tips for displaying NoOptionsText in MaterialUI Autocomplete based on a specific condition

When using a Material UI autocomplete feature, the items are selected based on the first 3 letters typed. For example, if you're searching for all "Pedros" in your database, typing "Ped" will bring up results starting with those letters. The issue ar ...

iOS now supports hardware-accelerated CSS3 transitions for seamless and

I can't seem to get hardware acceleration working with my translate3d for top/bottom positioning. What could be causing the issue? .image { background:yellow; -webkit-perspective: 1000; -webkit-backface-visibility: hidden; ...

CSS positioning alignment

Could someone please explain to me why changing the position to relative causes the "facebook and Facebook helps you connect and share with the people in your life" text to display at the top of the page? I've only been studying CSS for three days. Th ...

having trouble transferring the password field in PHP to phpMyAdmin

My HTML form collects the user's first name, last name, username, and password. I am trying to upload this data to my local phpMyAdmin, but I'm facing an issue with storing the password in the database. Below is my HTML code: <input type="te ...

Having issues with jQuery's .fadeIn function not functioning properly

Currently, I'm developing a website and I am aiming to achieve a specific effect where a text fades in every time the webpage is opened. To achieve this, I have implemented the following code snippet: $(document).ready(function() { $('#title ...

show information on a separate screen following the selection of a choice

After selecting an option, how can I make #formid appear where the form is filled in with the stock selected in the option section? <div class="form-group"> <label for="exampleFormControlSelect1">Item Name</label> <select clas ...

Unable to modify the selector to "Remove preview files" on click in PHP and JavaScript

During the process of uploading multiple files (using <input type="file" multiple/>) with preview image file and successfully removing the image preview and file data, I encountered a problem. The issue arises when attempting to change the selector ...

Receive alerts in Swift from WKWebView when a particular screen is displayed in HTML

Check out this sample HTML file I have. I'm currently using the WKWebView to display this HTML. My goal is to receive a notification in our Swift code when the user finishes the game and the "high score" screen appears, so we can dismiss the view and ...

How come JavaScript's history.back() method does not display form values?

I have been developing an HTML form that submits values to a PHP script. When encountering errors, I currently display the error message along with a link containing javascript:history.back(). In Chrome, the form reopens with all values retained from the ...

Adaptable triple-column design

After completing the layout of my website, everything seems to be functioning well. However, I would like to ensure that I haven't overcomplicated it or used poor techniques. The structure involves a main DIV with a nested table DIV, inside of which ...

Custom sized box causing Bootstrap Navbar to be unresponsive

I am having trouble loading the Bootstrap 3 navbar inside a .box class with specific CSS rules: .box { height: 600px; width: 320px; position: relative; border: 2px solid #eee; } Unfortunately, it is not displaying re ...

Tips on utilizing jQuery to trim and manipulate the current URL

Suppose the current URL I am working with is: https://example.com/test?id=W2FiY11beHl6XVsxMjNd . The data following ?id is [abc][xyz][123] and it is base64 encoded. My objective is to manipulate the current URL in such a way that the content displayed on ...

Easily updating a SQL row with the click of an HTML button using PHP

I am in the process of creating a basic comment system that includes a rating for each comment. After reading a comment, users will be asked if they liked it with two options, "Yes" and "No". I am seeking a straightforward method to update the number of ...

Issue with uploading files on remote server using PHP

Below is the code I am currently using: <form action="index.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" id="file"><br><br> <input type="submit" value="submit" name="submit"> </form> ...

When attempting to execute a function when a hidden div is not displayed, JQuery encounters an

I'm currently attempting to modify the text color of the h2 title with the id ticketSearchTitle when the ticketSearch div is not visible. However, the code I have been using to achieve this seems to cause issues (such as the absence of a pointer icon ...

I am interested in updating the color of the navigation bar displayed on this website

I am having some trouble with manipulating the appearance of - Specifically, I'm struggling to change the color of the black bar at the top to blue. I have scoured the CSS files and examined the HTML, but I can't seem to locate the relevant code ...

What is the best way to hide certain buttons from specific users in Angular using the If condition?

I am facing an issue with my array of blocked_users, where I need to hide certain buttons if a user is in the blocked_users list. Below is the code snippet from my angualr.component.html: <div *ngIf="!(userId in event.blocked_users)"> ...

Update the class name by utilizing template literals

I'm currently in the process of mastering template literals as I have a project where I need to utilize them. However, I seem to be encountering an issue that I can't quite figure out. Here is the code that is currently working: const classes = ...

Using jquery ajax to add new rows to a MySQL table at the bottom, creating a repeating pattern

Using AJAX jQuery, I am constantly updating a table with data from a MySQL database at regular intervals. The refresh rate is set to 1 second. Below is the PHP file responsible for successfully creating the JSON data: <?php $servername = "localhost"; ...

using javascript to dynamically color rows in a table based on the value in the status field

Hi, I'm new to javascript and seeking help for my table coloring issue. I have a dynamic table where data is inserted through an Ajax call. The goal is to color specific records based on their status. I attempted a solution but only one record gets c ...