Hello!
I’m having problems with my title bar not taking up the intended space. Here’s a diagram:
Diagram of my problem
The area I highlighted in red is where I want my title bar to be (Next to the existing buttons) but my title bar instead moves to the next line.
Here’s the code:
body, html{
margin: 0px;
height: 100%;
}
div.titlebar{
background-color: rgb(226, 147, 0);
color: white;
padding: 5px;
font-size: 20px;
line-height: 30px;
height: 30px;
font-family: 'Segoe UI', 'Arial', 'Helvetica', sans-serif;
display: inline-block;
cursor: default;
}
div.titlebutton{
cursor: pointer;
margin-left: 2px;
background-color: orange;
color: white;
padding: 5px;
font-size: 20px;
line-height: 30px;
height: 30px;
font-family: 'Segoe UI', 'Arial', 'Helvetica', sans-serif;
display: inline-block;
}
div.titlebutton:hover{
background-color: rgb(226, 147, 0);
}
#editor{
border: none;
resize: none;
font-size: 20px;
width: 100%;
height: calc(100% - 45px);
box-sizing: border-box;
}
div#rest {
background-color: orange;
color: white;
margin-left: 2px;
padding: 5px;
height:30px;
display: inline-block;
cursor: default;
width: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Editor</title>
<link rel="stylesheet" href="text.css">
</head>
<body>
<div class="titlebar">Text Editor</div><div class="titlebutton" id="save">Save</div><div class="titlebutton" id="load">Load</div><div id="rest"></div>
<br/>
<textarea id="editor"></textarea>
<script src="text.js"></script>
</body>
</html>
Attempts to fix
! (Please keep in mind that I’m a CSS beginner)
I tried usingwidth:100%;
along withdisplay:inline-block;
to make it go next to the buttons. I’m not familiar with other ways to do it, so that’s the only way I tried aside fromdisplay:inline;
, that ended up breaking the whole bar.
2
Answers
If you wrap it in a container that is block formatted and make the buttons inside inline-block, it should work as a base point.
You’ve made this quite hard for yourself by not including a wrapper element for the titlebar. The layout you’re going for is very flexbox and so naturally you’d want a flexbox parent for the items inside the titlebar:
This also allows you to get rid of the
<div id="rest">
, by simply giving the parent the appropriatebackground-color
.