How can I make #content
sit next to #menu
while occupying the rest of the width of #container
;
<div id="container">
<div id="menu">
</div>
<div id="content">
</div>
</div>
Note: I need #menu
to have fixed 200px width
How can I make #content
sit next to #menu
while occupying the rest of the width of #container
;
<div id="container">
<div id="menu">
</div>
<div id="content">
</div>
</div>
Note: I need #menu
to have fixed 200px width
You could use flex:
#container {
display: flex;
width: 100%;
}
#menu {
width: 200px;
background: red;
}
#content {
flex: 1;
background: yellow;
}
<div id="container">
<div id="menu">
foo
</div>
<div id="content">
foo
</div>
</div>
Or grid layout
#container {
display: inline-grid;
grid-template-columns: 200px auto;
width: 100%;
}
#menu { background: red; }
#content { background: yellow; }
<div id="container">
<div id="menu">
foo
</div>
<div id="content">
foo
</div>
</div>
You can use calc() function in css.
#container { width:100%; }
#menu { background:red; float:left; width:200px; }
#content { background:yellow; float:left; width:calc(100% - 200px) }
<div id="container">
<div id="menu">
foo
</div>
<div id="content">
foo
</div>
</div>
You can add CSS to both of the divs, which is the float property.
#menu{
float: left;
width: 200px;
}
#context{
float: right;
}
I'm not shure whether I understood what you ment:
You want the div #menu to be the exact size of 200px, no matter what's inside?
Solution:
you need to do this in css:
There ar mainly 3 different types of including css
1.inside the body Tag: (used for small Websites with nothing looking the same, most programers hate if you do this)
<div id="container">
<div id="menu" style="width: 200px;">
</div>
<div id="content">
</div>
</div>
2.inside the head Tag: (used for small websites with things looking the same, most programers do this for small websites)
<head>
<style>
.menu{
width:200px;
}
</style>
</head>
<body>
<div id="container">
<div class="menu" id="menu">
</div>
<div id="content">
</div>
</div>
</body>
3.inside a .css file: (used for large Websites with unified look)
HTML:
<head>
<link rel="stylesheet" type="text/css" href="maincss.css">
</head>
<body>
<div id="container">
<div class="menu" id="menu">
</div>
<div id="content">
</div>
</div>
</body>
CSS:
.menu{
width:200px;
}