What is the method to align my text to the top of the page?

I'm working on a 4-column page and trying to insert content. Everything is functioning properly except for getting my first div to align to the top in inline-blocks. As a newbie, I feel like I must be overlooking something simple. (I've tried using padding: 0; in the divs). Thanks. Milt.

<html>
<style>

html, body, #content { margin: 0px;  height: 100%;  width: 100%; padding: 0px;}

div.outer { background-color: lightgreen }
div.inner { display: inline-block; }
div.WebTopic { width: 190px;}

.col {
  position: absolute;
  top: 0px; bottom: 0px;
  margin: left: 10px;
  border: 1px solid black;
  background-color: seashell;
}

.col-1 { left: 0px;         width: 400px;  top: 0px;}
.col-2 { left: 401px;     width: 200px;  top 0px; }
.col-3 { left: 601px;     width: 400px; }
.col-4 { left: 1001px;     width: 50px; }

</style>

<body>
<div id="content"> 
        <div class="col col-1">
              <div class="outer">
                <div class="inner">
                    <div class="WebTopic">
                           <p>??? Why is this at the foot of the frame? Would like it at top.</p>
                   </div>
            <p class="fanRating">HTML Fan rated #1</p>
</div>


<div class="inner">
<div class="WebTopic">
<p>CSS is used for describing the presentation of web pages. The CSS tutorial section will help you learn the essentials of CSS, so that you can fine control the style and layout of your HTML document.</p>
</div>
<p class="fanRating">CCS Fan Rated #3</p>
</div>

</div>        <!--  OUTER 1 END  -->

<p>Stuff here in usual block mode</p>

  <!--  OUTER 2  START   -->

<div class="outer">
                <div class="inner">
                    <div class="WebTopic">
                           <p>HTML is a markup language that is used for creating web pages. </p>
                   </div>
            <p class="fanRating">HTML Fan rated #1</p>
</div>


<div class="inner">
<div class="WebTopic">
<p>CSS is used for describing the presentation of web pages. Loads more words. Loads more words. Loads more words. Loads more words. Loads more words. Loads more words. Loads more words. </p>
</div>
<p class="fanRating">CCS Fan Rated #3</p>
</div>

</div>        <!--  OUTER 2  END -->


        </div>
        <div class="col col-2">
            COLUMN 2 -------------
        </div>

<!--  COLUMN 3 START -->

        <div class="col col-3">
               <div class="outer">
                <div class="inner">
                    <div class="WebTopic">
                           <p>??? Why is this at the foot of the frame? Would like it at top. Tons of text.  Tons of text.  Tons of text.  Tons of text.  Tons of text.  </p>
                   </div>
            <p class="fanRating">HTML Fan rated #1</p>
</div>

<div class="inner">
<div class="WebTopic">
<p>CSS is used for describing the presentation of web pages. The CSS tutorial section will help you learn the essentials of CSS, so that you can fine control the style and layout of your HTML document.</p>
</div>
<p class="fanRating">CCS Fan Rated #3</p>
</div>

</div>       
        </div>
        <div class="col col-4">
          COL 4
        </div>    

</body>
<html>

Answer №1

To ensure proper alignment, consider adding the CSS property vertical-align: top to your inline-block elements if it is not explicitly stated.

For example:

div.inner { 
  display: inline-block; 
  vertical-align: top;
}

See how this change affects your code:

Before: https://jsfiddle.net/hu6yosgq/1/

After: https://jsfiddle.net/hu6yosgq/2/

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

Using PHP foreach loop to create bootstrap 4 cards

I am attempting to showcase all of my shop items on my webpage using Bootstrap 4 cards. I want them to be displayed in a grid format, three wide and however many deep (I may consider adding pagination later). Currently, I have a PHP foreach loop that succ ...

Best practices for embedding Internal CSS and rectifying missing classes in mobile view for email templates on Gmail

I am currently facing an issue with my email template. While it works perfectly fine in Outlook web and the Outlook app, Gmail web and Gmail's internal CSS strip away certain classes automatically. In an attempt to hide the pre-header on mobile devic ...

Unable to override default styles with custom styles in React MUI 5

I've been attempting to replace the default MUI 5 Button styles with my custom styles using either withStyles or a className (created using makeStyles), but I'm running into an issue where the default styles take precedence over my custom ones. I ...

Compel the browser to initiate a reflow by adjusting the CSS

I am currently in the process of building a responsive image slider without relying on jQuery, using CSS3 transitions. The setup is quite simple: there's a viewport with a UL inside, containing relatively positioned LIs that are left floated. Howeve ...

How come flex won't let me rearrange an image?

.nav { height: 500px; } .navphoto { height: 500px; display: flex; justify-content: flex-end; } <div class="nav"> <img class="navphoto" src="images/navphoto.jpg"> </div> Just wondering why I can't seem to move an image, bu ...

Static placement reacting promptly

I am currently experiencing an issue where the content keeps scrolling to the right with the page when resized. I would like it to remain in the same position when resized. To help illustrate the problem, I have created a Codepen. It seems that the div con ...

Shift the position of an HTML element with a border to account for a stationary header

My inquiry is closely tied to a previously resolved issue discussed on this page. Specifically, the solution offered by @harpo in the top-rated answer's comments partially addressed my concern. Nonetheless, I've discovered that it doesn't ef ...

Creating a basic jQuery button to switch an element's background color is a breeze

I'm new to this, so I hope this is a straightforward question. I'd like to use the bgtoggle class as a button to switch the background color of the metro class. I know I'm doing something wrong because it's not working as expected. Any ...

Styling with CSS based on the remaining width of the viewport relative to the height

If you're viewing this on a tablet browser, the dimensions are set relative to the viewport width and height. Let's assume a landscape orientation for simplicity. Inside a fullscreen container, there are two divs positioned absolutely, just like ...

Setting the background color in the navbar of a Laravel application

I'm having trouble changing the color of my navbar to blue in certain parts. I've tried using background: lightblue;, but for some reason, two sections remain white. How can I make them completely blue? (see screenshot below) Any help would be ap ...

Can PushState be used to Ajaxify CSS files?

Currently, I am in the process of developing a basic website and have decided to incorporate the Ajaxify library for seamless page transitions. One challenge I have encountered involves the combination of global CSS files (applied throughout the entire sit ...

Can Three.js be used to create a compact canvas?

I've successfully implemented a three.js scene on my website where users can drag to rotate an object. However, I don't want the scene to take up the entire webpage. I tried adjusting the field parameters with the following code: renderer.setSiz ...

Upon reaching a specific milestone on the page, automatically scroll to the designated anchor point

Here's the deal: I plan to showcase 4 divs on my page. Each div will have a specific height (around 1500px) but will span the full width of the screen. To add some flair, each div will be a different color. My goal is for JavaScript to kick in once ...

Can PHP be used to dynamically load a different stylesheet on a webpage?

Currently in the process of developing a mobile version of my website, I have determined that implementing an alternate stylesheet would be the most effective method to ensure compatibility with mobile devices. I am considering using a PHP script for use ...

Unusual padding anomaly seen with inline elements (bottom padding is applied correctly, while top padding is not)

I had a good understanding of how inline elements function. But I came across a helpful explanation here: CSS display: inline vs inline-block. Regarding inline elements: respect left & right margins and padding, but not top & bottom Inline elem ...

Ensure that the div expands to accommodate the content

I'm experiencing an issue where the content within a div with a blue border exceeds the boundaries of the div when it expands. How can I make sure that the div extends to contain all the content? Here is a demonstration of the problem: When I expand ...

Implementing a pop-up notification at the center of the display for empty fields

I am currently working on a task that requires me to display a pop-up message at the top-middle of the screen stating "please fill in all fields before submitting". This custom box should be stylable using CSS. Although the solution seems simple, I am str ...

Safari browser not supporting CSS @property --rotate functionality

This card's animation is functioning well in Chrome, but it is not compatible with Safari and Mozilla Firefox. I suspect the issue lies with the @property --rotate, as it is no longer supported by Safari. Therefore, I am searching for an alternative ...

A minuscule variation in width percentage due to a single pixel

I am experiencing an issue with a one pixel margin between two green colors on my website. I have been unable to locate the source of this problem. I am currently using display:inline-block. Here is the link to my website: ...

What method does the CSS standard dictate for measuring the width of an element?

In terms of measuring an element's width, Chrome appears to calculate it from the inner margin inclusive of padding. On the other hand, Firefox and IE determine the width of the box from the border, excluding padding but including the margin. Personal ...