8

当我更改 div (id="home") 中的文本大小时,它也会更改 div 的大小。我希望能够更改文本大小而无需每次更改 div 大小。

这是HTML:

<!DOCTYPE html>
<html>
    <head>
        <link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
        <link type="html/css" rel="stylesheet" href="websiteCSS.css"/>
        <title>PROTOTYPE</title>
    </head>
    <body>
        <div id="sidebar"></div>
        <div id="home" class="header">Home</div>
    </body>
</html>

和CSS:

body{
    margin: 0; 
    background: #d5e9d7;
}

#sidebar {
    z-index: 1;
    position: fixed;
    width: 20%;
    height: 100%;
    margin-top: 0;
    margin-left: 0;
    #background-color: light blue;
    background-image: linear-gradient(to bottom, #545454 0%, #424242 100%);
    margin-bottom: 10px;
}

.header {
    position: fixed;
    width: 2.5em;
    height: 1em;
    padding: 8px;
    background-color: #b2b2b2;
    margin-top: 0.5%;
    margin-left: 20.5%;
    font-family: 'Josefin Sans', sans-serif;
    font-size: 2em;
    color: #333333;
}

.header:hover {
    font-size: 2.1em;
}
4

2 回答 2

1

您可以设置您的 div 大小px或设置一个min-widthmin-height属性。

于 2013-07-02T01:19:04.110 回答
0

将容器 div(宽度和高度)设置为能够容纳最坏情况(最大)的字体大小。这将停止根据字体大小调整 div 的大小。

于 2013-07-02T01:17:18.337 回答