Establishing a foundational grid system

I'm having trouble setting up a baseline grid for my webpage. When I adjust the font scale, the text no longer aligns with the grid.

What am I doing incorrectly? Could this issue be related to the font scaling?

You can view the Fiddle here: http://jsfiddle.net/3stut/

And here is the code snippet:

HTML

<body>

  <h1>Your Name</h1>
  <h2>Your Name</h2>
  <h3>Your Name</h3>
  <h4>Your Name</h4>
  <h5>Your Name</h5>
  <h6>Your Name</h6>
  <p>Paragraph</p>

</body>

CSS

body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td { 
  margin: 0;
  padding: 0;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
fieldset, img {
  border: 0;
}
address, caption, cite, dfn, th, var {
   font-style: normal;
   font-weight: normal;
}
caption, th {
  text-align: left;
}
h1, h2, h3, h4, h5, h6 {
  font-size: 100%;
  font-weight: normal;
}
q:before, q:after {
  content: '';
}
abbr, acronym {
  border: 0;
}

h1,h2,h3,h4,h5,h6,hgroup,ul,ol,dd,p,figure,pre,table,fieldset,hr,.header,.media,.island{
margin-bottom:1.5rem;
}


html {
  font:1em/1.5 Cambria, Georgia, "Times New Roman", Times, serif;
  background: url(http://media.smashingmagazine.com/wp-content/uploads/technical-type/img/css/grid.png) center -6px repeat-y #fff;
  color: #333;
  width: 940px;
  padding: 0 10px;
  margin: 0 auto;
 }

body {
  width: 460px;
  margin: 0 auto;
  padding-top: 72px;
 }

h1 {font-size:48px;}
h2 {font-size:30px;}
h3 {font-size:24px;}
h4 {font-size:21px;}
h5 {font-size:18px;}
h6 {font-size:16px;}

Answer №1

If you're familiar with the concept of a "baseline grid" in typography, you'll notice that the code here doesn't quite adhere to it. A true baseline grid requires ensuring that element heights (including margins) are multiples of the grid line height. Without this alignment, elements like headings and images won't sit neatly on the grid.

For headings, assuming a pixel-based sizing approach and a CSS reset with zero margins, you can adjust the font sizes and line heights to meet the requirements:

* { font-size:16px; line-height: 18px; }
h1 {font-size:48px; line-height: 54px;}
h2 {font-size:30px; line-height: 36px; }
h3 {font-size:24px; line-height: 36px; }
h4 {font-size:21px; line-height: 36px; }
h5 {font-size:18px; }
h6 {font-size:16px; }

In this setup, all line heights are multiples of 18px. You can adjust by making some line heights slightly smaller and adjusting top margins accordingly.

Aligning heading baselines with normal text baselines in another column is challenging with CSS due to limitations in determining the distance between the font's bottom and baseline. However, if you're working with specific fonts and can fine-tune positioning, you may achieve better alignment. The key is to ensure that normal text baselines match by setting element heights as described above.

Answer №2

Enjoy this

check it out

styling

h1 {font-size:48px; margin:0; padding:0;}
h2 {font-size:30px;  margin:0; padding:0;}
h3 {font-size:24px;  margin:0; padding:0;}
h4 {font-size:21px;  margin:0; padding:0;}
h5 {font-size:18px;  margin:0; padding:0;}
h6 {font-size:16px;  margin:0; padding:0;}

--

Do you like this?

try this one


give this a go


explore more

styling

h1{
font-size:30px;
}

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

"Enhancing Your Web Pages: Generating and Inserting HTML Elements on the Fly Using

For my master's degree project, I am working on developing a shopping web app. The issue I am facing is that I need assistance with creating a div and adding it to the HTML file with an ID matching the category name from the .ts file when the addCate ...

Avoid Scrolling within an iFrame in HTML with the Use of #

I have a menu loading in an iframe with links using # like http://<location>/page.html#part1. When I click inside the iframe, the entire page outside of the iframe scrolls to the location of #. How can I stop this from happening? I only want the me ...

Designing tables and adherence to WCAG 2 accessibility standards

I'm aware that WCAG 2.0 allows tables for layout purposes, but I keep encountering an error in achecker despite this: Error 245: Data table with multiple rows/columns of headers does not utilize id and headers attributes to identify cells Resolution ...

Tips for creating scrollable popovers in Bootstrap 4

I came across a similar question, but the solution provided didn't work for me and I'm not sure why. Why is my popover content not scrolling when it exceeds 50px? Also, a side question: I'm facing an issue with newlines within the popover wh ...

SweetAlert html is not recognizing ng-app, but it functions correctly within the html body

When inserting a bootstrap table inside a SweetAlert, I encountered an issue where using ng-app or ng-repeat to populate data inside the table's rows did not call ng-app. However, when populating the table outside of the SweetAlert in the body, ng-app ...

Challenges arise when utilizing the foundation 6 grid for image overlays within a React application

Having some trouble using the foundation 6 xy grid for the first time and aligning three images with text overlays at the bottom of each image. I am struggling to make the background of the text fill the full width of the image while also ensuring it is re ...

Manipulate NSMutableAttributedString on iOS while retaining HTML attributes

Incorporating HTML-formatted text into an iOS app using NSAttributedString for preserving text properties can sometimes pose challenges. The issue arises when the conversion function initWithData:options:documentAttributes:error: defaults the font to Times ...

Page resizing is disabled in Chrome after an Ajax load

I've been tirelessly working on the CSS for a website I'm building, and I've encountered a strange issue that only seems to affect Chrome. Firefox and Internet Explorer work perfectly fine. I am using jQuery to load HTML stubs and a signifi ...

jQuery can be used to mask phone numbers with three input fields

I am looking to implement phone field masking using jQuery or JavaScript. I have tried a few jQuery mask plugins, but I am still searching for a better solution. Specifically, I need three input fields for the USA (it is a requirement). The inputs needed ...

Beginner experiencing website overflow problem

After completing a basic web development course, I decided to create my first homepage. While I am satisfied with how it looks on a PC or laptop, the layout gets messy on mobile devices. I tried using <meta name="viewport" content="width= ...

The getimagesize functionality seems to be malfunctioning

I have developed a function that resizes images to fit as a background image for a div. I provide the function with the div size and the image path. It works perfectly when the height is larger than the width, but it fails when the width is larger than the ...

Creating a responsive carousel that is not yet designed

As a beginner, I'm facing what seems like a simple problem that I just can't solve. Here is the HTML code I've written: <div class="discs container"> <ul> <li><div class="arrowleft"><a href="#" >< ...

Issues with the input element: Transition, border-color, and :focus functionalities are not functioning as

Currently, I am in the process of developing a search box similar to Google's for an e-commerce platform. Unfortunately, I am facing difficulties with the border-color, transition, and :focus properties. To further elaborate on the issues: border-col ...

Retrieve all text within a <div> element excluding the content within an <h5> tag using XPath

I have been researching and experimenting with different solutions for the issue at hand, but unfortunately, none of them have proven successful so far. Here is the HTML code that I am working with: <div class="detalhes_colunadados"> <div clas ...

How can jQuery be used to target a specific class based on its inner value?

For instance, within a div of the same class, there are 6 "p" tags - some containing 'member' text and others not. I aim to use jQuery to select all "p" tags with 'member' as their inner text and apply an additional class to them. Here ...

Automatically adjust column sizes using Bootstrap's responsive width feature

While I have a feeling this question might have been asked before, my search has turned up no similar issues. I am currently working on styling a menu bar using a standard bootstrap row and columns setup (flexbox). The menu is dynamically generated by Wor ...

How to set the default value of a select dropdown in PHP

I came across this snippet of code: <td> <select class="versionSelect"> <option value="5" <?php if($item->version === "5") echo "selected='selected'"; ?>>5</option> <option value="6" <?php ...

Navigating to a precise location on initial page load using Angular 11

Within the structure of my app, I have a parent component that displays a large image from a child component. When the parent component loads, I want the browser window to automatically scroll to a specific position in order to center the image. Currently ...

Issue with login form in IONIC: Form only functions after page is refreshed

Encountering an issue with my Ionic login form where the submit button gets disabled due to invalid form even when it's not, or sometimes displays a console error stating form is invalid along with null inputs. This problem seems to have surfaced afte ...

Troubleshooting problem with navigation tabs in Bootstrap version 3.x

My bootstrap component nav-tabs works fine on desktop when the page width is larger than necessary for the row. However, on mobile devices, the responsive design doesn't behave as expected and the tabs become misaligned. You can see the issue in the c ...