设置字体大小,使字母高度等于某个值

时间:2015-04-07 07:51:18

标签: css font-size

我想用CSS将字母缩放到另一个元素的确切高度。例如,我可能希望文本与某些图像一样高:

enter image description here

我怎样才能做到这一点?

当我将font-size设置为等于图像的高度时,字母会变小。我可以尝试手动调整,直到看起来相等,但我想计算它。


我目前的解决方案是将线条高度设置为图像的高度,并根据字体指标计算字体大小:

.the_image {
    height: 28px;
    }

.the_M {
    line-height: 28px;
    font-size: calc(28px * 2048 / 1490);
    }

在这种情况下,字体指标是2048 UPM(每个单位的单位),字母“M”是1490单位高。将em尺寸(2048单位)除以字母高度(1490)会产生一个将“M”缩放到所需高度的因子(此处:28px)。

在这种情况下我知道我使用的字体,因为我用@ font-face嵌入它,我知道字体的指标因为我在字体编辑器中查看它(我使用Fontforge和Glyphs来创建我的字体),但我仍然喜欢用户计算机上适用于未知字体的解决方案

1 个答案:

答案 0 :(得分:0)

首先,您需要设置位置然后继承高度 类似的东西:

public function laptops_toate_grid($filter = null){
    $this->db->select('*')
             ->from('laptop_notebook')
            ->join('brands','brands.id_brands = laptop_notebook.brand');

    if (isset($filter['price'])) { // make sure there is price key
        $filters = array(); // this is where we store the filters
        foreach ($filter['price'] as $price) { // iterate through prices
            if ($filter['price'][0] == '<') { // is less
                $filters[] = 'price < ' . (int)substr($price, 1);
            }
            elseif ($filter['price'][0] == '>') { // is more
                $filters[] = 'price > ' . (int)substr($price, 1);
            }
            else { // is between
                $expl = explode('-', $price);
                $filters[] = 'price BETWEEN ' . (int)$expl[0] . ' AND ' . (int)$expl[1];
            }
        }
        if ($filters) { // if there are filters, create the query
            $query = implode(' OR ', $filters);
            $query = '('. $query . ')';
            $this->db->where($query, false); // false makes sure the query is not escaped
        }
    }

    $query = $this->db->get()->result();

    return $query;
}