Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change the font size in HTML/css without the div size changing?

Tags:

html

css

When I change the text size in the div (id="home"), it also changes the size of the div. I want to be able to change the text size without the div size changing every time.

Here is the 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>

and the 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;
}
like image 700
user2540862 Avatar asked Jul 02 '13 01:07

user2540862


1 Answers

You could set your div size in px or set a min-width or min-height attribute.

like image 77
sebu Avatar answered Nov 15 '22 08:11

sebu