LibWeb: Make default CSS font settings match other browsers better

Let's make 16px the default font size instead of 10px. This makes our
layout results match those of other engines in many more cases.

Also make the h1-h6 element styles use relative (em) font sizes, also
matching other browsers.
This commit is contained in:
Andreas Kling 2022-09-08 12:41:42 +02:00
parent 3dc82d2fa5
commit 8f0a48ef23
Notes: sideshowbarker 2024-07-17 07:21:21 +09:00
3 changed files with 33 additions and 9 deletions

View File

@ -15,7 +15,7 @@ namespace Web::CSS {
class InitialValues {
public:
static float font_size() { return 10; }
static float font_size() { return 16; }
static int font_weight() { return 400; }
static CSS::FontVariant font_variant() { return CSS::FontVariant::Normal; }
static CSS::Float float_() { return CSS::Float::None; }

View File

@ -11,13 +11,37 @@ body {
margin: 8px;
}
h1,
h2 {
font-family: Pebbleton;
font-size: 14px;
font-weight: bold;
h1 {
font-size: 2em;
margin: 0.67em 0;
}
h2 {
font-size: 1.5em;
margin: 0.83em 0;
}
h3 {
font-size: 1.17em;
margin: 1em 0;
}
h4 {
margin: 1.33em 0;
}
h5 {
font-size: 0.83em;
margin: 1.67em 0;
}
h6 {
font-size: 0.67em;
margin: 2.33em 0;
}
h1,
h2,
h3,
h4,
h5,

View File

@ -855,7 +855,7 @@ void StyleComputer::compute_defaulted_values(StyleProperties& style, DOM::Elemen
float StyleComputer::root_element_font_size() const
{
constexpr float default_root_element_font_size = 10;
constexpr float default_root_element_font_size = 16;
auto const* root_element = m_document.first_child_of_type<HTML::HTMLHtmlElement>();
if (!root_element)
@ -921,7 +921,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
bool bold = weight > Gfx::FontWeight::Regular;
float font_size_in_px = 10;
float font_size_in_px = 16;
if (font_size->is_identifier()) {
switch (static_cast<IdentifierStyleValue const&>(*font_size).id()) {
@ -930,7 +930,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
case CSS::ValueID::Small:
case CSS::ValueID::Medium:
// FIXME: Should be based on "user's default font size"
font_size_in_px = 10;
font_size_in_px = 16;
break;
case CSS::ValueID::Large:
case CSS::ValueID::XLarge: