CSS positioning problems thoroughly elucidated

I'm facing two issues that I can't seem to resolve. My goal is to recreate a design similar to the one found at https://i.sstatic.net/XfPqm.jpg.

My first issue is with adjusting the box in the header to stay aligned next to my headline tags. The second issue is related to positioning all of my content elements in a single line, where one appears above and another 5 pixels below the other. I have attempted to visually present these issues using Paint at https://i.sstatic.net/USBIk.jpg. Here is my code, any help would be greatly appreciated.

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="main.css" type="text/css" />
    <title>Newspaper</title>
</head>
<body>
    <header>
        <hgroup>
            <h2>THE OLD POST</h2>
            <h3>ILLUSTRATED WEEKLY NEWSPAPER</h3>
            <div class="header-Box">
                <strong>This is a story about one pig</strong>
            </div>
        </hgroup>
    </header>

    <div class="infoBorder">
        <span>Est.1896</span>
        <span>Wednesday,November 24,1892</span>
        <span>Price 6d</span>
    </div>

    <div id="main-Content">
        <h1>INSERT YOUR HEADLINE</h1>
        <div class="parent-content">
        <div class="content">
            <strong>Bacon ipsum dolor amet beef strip steak beef ribs ham, porchetta ground round ham hock turducken prosciutto kevin swine.</strong>
            <p>
            Flank turkey venison frankfurter spare ribs drumstick ball tip rump porchetta kielbasa swine pork turducken. Turkey frankfurter leberkas flank pork belly porchetta pork landjaeger beef ribeye alcatra picanha hamburger tongue. Cow bacon ribeye sirloin pancetta sausage pork loin jerky short ribs corned beef biltong hamburger.
            </p>
        </div>
        <div class="content">
            <strong>Hamburger pastrami strip steak turkey landjaeger sirloin tail pig shoulder tri-tip. Tail swine flank meatball turkey andouille drumstick pancetta sausage tri-tip spare ribs ribeye.</strong>
            <p>
            Jowl turkey tri-tip salami. Porchetta fatback corned beef, andouille ham hock chuck cow short loin bresaola. Landjaeger sausage spare ribs kielbasa filet mignon capicola biltong. Sausage t-bone doner hamburger, tri-tip cupim andouille.
            </p>
        </div>
        <div class="content">
            <strong>Jerky cow meatloaf pastrami landjaeger bacon ground round shank venison jowl pork belly biltong capicola kevin pig. Filet mignon alcatra pancetta strip steak pork belly.</strong>
            <p>
            Alcatra pastrami shoulder doner brisket spare ribs turducken chuck kevin tenderloin flank. Pig hamburger tenderloin, pork cow pancetta ground round kielbasa bresaola shank fatback sirloin beef ribs tail beef. Chicken ham hock salami shoulder, andouille fatback filet mignon bresaola venison.
            </p>
        </div>
        <img src="http://www.gif-favicon.com/images/flowers/pink-flowers-transparent-clipart-0400-10054.gif" />
    </div>
    </div>
</body>
</html>

Below is my CSS code for reference:

body {
  background-image: url("img/news_background.jpg");
}
header {
  border-bottom: 2px solid #000;
  padding: 20px;
}
div.header-Box {
  border: 2px solid #000;
  display: inline-block;
}
h1,
h2,
h3 {
  text-align: center;
}
h2 {
  font-size: 40px;
  margin: 0px;
}
h3 {
  font-size: 15px;
  margin: 0px;
}
div.infoBorder {
  border-top: 2px solid #000;
  border-bottom: 2px solid #000;
  margin-top: 5px;
  margin-bottom: 5px;
  padding: 5px;
}
span {
  font-weight: bold;
  margin: 160px;
}
div#main-Content {
  border-top: 2px solid #000;
}
div.content {
  display: inline-block;
  width: 240px;
  height: 280px;
  border: 1px solid #000;
  padding: 10px;
}

Answer №1

Describe your css like this

See Demo Here

div.content {
    vertical-align: top;
}

=== The second issue can be resolved with this

Make changes to your html as shown below

<header>
        <hgroup>
            <h2>THE OLD POST</h2>
            <h3>ILLUSTRATED WEEKLY NEWSPAPER</h3>

        </hgroup>
        <div class="header-Box">
                <strong>This is a story about one pig</strong>
            </div>
    </header>

Update the CSS code like this

header {
    text-align: center;
}
hgroup {
    display: inline-block;
    vertical-align: top;
}
div.header-Box {
    display: inline-block;
    vertical-align: top;
}

View Updated Demo Here

Answer №2

float: right;

Remember, this simple code can make a big difference in your design.

Answer №3

<header> {
    positon: relative;
}

append:

div.navbar-Box {
    position: absolute;
    top: 50px;
    right: 40px;
}

div.main-body {
   vertical-align: top;
}

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

Implement a delay for updating the style of a button by using the setTimeout function

Is it possible to create a button that, when clicked, changes color to green and then reverts back to its original style after 3 seconds? I am able to change the button color using an onClick event in my script. However, I encounter scope errors when tryi ...

Using the on-change event with a textfield can help ensure that the field is cleared if the min-date condition is not met

I recently encountered an issue with an input field that had the type "datetime" and a min-date condition set to today's date. The flow was such that if a valid date was entered, the submit button would be enabled, otherwise it would remain disabled. ...

AmCharts Axis renderer mistakenly renders an additional grid line

I have successfully created a basic XYChart using amcharts4. To get rid of the grid lines on the x-axis, I changed the stroke opacity for the x-axis grid to 0 using the following code: xAxis.renderer.grid.template.strokeOpacity = 0; Everything was workin ...

Updating the value of a localStorage key after each successful AJAX call in JavaScript

I'm currently facing a challenge with my local storage key value. The issue is that it doesn't update the value when the AJAX call successfully returns data. It only retains the old stored data, requiring me to manually refresh the page by pressi ...

What is the best way to create a border of white space around the background color of a table cell using CSS?

Is there a way to create a white space around the background color of a table cell using CSS? My current code has the background color extend all the way to the edge, and padding only affects the content, not the background color. #main-monitor { widt ...

Detecting media queries for the Samsung Galaxy S3 and S4 devices

I have been working on implementing media queries to show text boxes with different styles for iPhone 5, iPhone 6, Samsung Galaxy SIII, and Samsung Galaxy S4. Initially, everything was working fine for iPhone 5 and iPhone 6, but when I switched from an i ...

The HTML image file input restricts the user's selection to images stored in the gallery

On mobile devices, when I press the input it displays two options: camera and gallery. However, I only want to select from the gallery. How can I disable the camera option? ...

The information in the table quickly appears in its raw format before being formatted and enhanced by jquery DataTables

I have encountered an issue where table data loads briefly and unformatted before jquery DataTables kicks in. After doing some research, I found that many suggest hiding the table using CSS and then showing it using jQuery with initComplete. However, des ...

Ways to conceal all components except for specific ones within a container using JQuery

My HTML structure is as follows: <div class="fieldset-wrapper"> <div data-index="one">...</div> <div data-index="two">...</div> <div data-index="three">...</div> < ...

Accessing a key from an AJAX JSON response and applying it within a .each() loop in jQuery

I'm struggling with a seemingly simple task that I just can't seem to get right. My goal is to convert multiple text inputs into select fields using AJAX and jQuery. Everything works smoothly, except when trying to make the $.each function dynam ...

Having trouble with Isotope masonry functionality

While experimenting with Isotope from , I tested the reLayout method using the provided example found at . I copied the css and js to my page () but encountered an issue where clicking on the first element caused all other elements to move to the first col ...

The Angular overlay panel remains open consistently

I recently developed an Angular component similar to p-overlaypanel, but I'm facing an issue where it remains open for every item I click. What I actually want is for only one overlay panel to be clicked and shown at a time - if I click on another ove ...

Tips on positioning an element absolutely so that it stops right before another element as the screen width is adjusted

Imagine a scenario where there is a 'parent' block containing various elements, including a button. When the user clicks this button, a 'slide' element should appear and cover the parent block but only up to the button itself (as shown ...

Using Styled Components to achieve full width for input tag in relation to its parent

I am working with an input field that has a specific width set. My goal is to increase the width of this input field to 100% by selecting it from its parent component. Is there a way to achieve this without passing an explicit width prop in the styled c ...

What is causing the div to not update until the for loop is completed?

I have an HTML page where I am trying to update a div while a for loop is running. However, the div does not update until after the loop finishes. Why is this happening? <!DOCTYPE html> <html> <body> ...

Align the responsive image in the center of a container

I am facing a challenge in centering an image wrapped by an anchor tag inside a div. I have tried using display flexbox and justify-content:center for the image, which works to some extent. However, the height of the image remains constant while the width ...

Mysterious extra space appearing on the right side of the left scroll div in Chrome

I am currently working with a table that dynamically increases in content when a button is clicked. I have successfully implemented a scroll on the right side to handle overflow. However, I encountered an issue when trying to change the scroll to the left ...

Why is Bootstrap 4 causing these columns to stack vertically instead of horizontally?

After upgrading to bootstrap 4, I noticed that my gallery layout has changed from horizontal in bootstrap 3 to vertical. What could have caused this sudden change? To see the issue, here is a link to a fiddle. Here are my column settings: <div class= ...

Smooth scrolling feature malfunctioning in mobile view

While working on my website, I noticed that the smooth-scroll feature works perfectly on desktop browsers. However, on mobile devices, when I click on a link, it does not scroll to the correct position. It always ends up much lower than expected. Any idea ...

Utilizing jquery and ajax to submit a form seamlessly without the need to refresh the web page

I've been struggling to submit a form without refreshing the entire page. I integrated some source code that I found, but for some reason, it's not working! Here is the HTML form I'm trying to submit: <form method="POST" action="" name= ...