Hi Guys,
I’m new to css and html. I wanted to make a 3 column layout occupying equal space with border and margin.
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<meta charset="utf-8">
</head>
<body>
<h1 class="main">Our Menu</h1>
<div class="outer">
<div class="box">
<p class="heading">Dummy</p>
<p class="para">Borders and Colors: Each section should have a background color set to some color (of your choosing). Set the background color of each section title region to some unique color (of your choosing). Make sure that the background color still allows the user to view the text in the section and section title regions. Depending on the color you choose, you may want to change the color of the text so it can be easy to read. Set a black border on both the section and section title region that is 1px thick. Warning: While not specifying borders and colors according to the requirements does not hurt your grade so much, not doing so will make it much harder for your classmates to peer grade the rest of your assignment, possibly resulting in a much lower grade.</p>
</div>
<div class="box">
<p class="heading">Dummy</p>
<p class="para">Borders and Colors: Each section should have a background color set to some color (of your choosing). Set the background color of each section title region to some unique color (of your choosing). Make sure that the background color still allows the user to view the text in the section and section title regions. Depending on the color you choose, you may want to change the color of the text so it can be easy to read. Set a black border on both the section and section title region that is 1px thick. Warning: While not specifying borders and colors according to the requirements does not hurt your grade so much, not doing so will make it much harder for your classmates to peer grade the rest of your assignment, possibly resulting in a much lower grade.</p>
</div>
<div class="box">
<p class="heading">Dummy</p>
<p class="para">Borders and Colors: Each section should have a background color set to some color (of your choosing). Set the background color of each section title region to some unique color (of your choosing). Make sure that the background color still allows the user to view the text in the section and section title regions. Depending on the color you choose, you may want to change the color of the text so it can be easy to read. Set a black border on both the section and section title region that is 1px thick. Warning: While not specifying borders and colors according to the requirements does not hurt your grade so much, not doing so will make it much harder for your classmates to peer grade the rest of your assignment, possibly resulting in a much lower grade.</p>
</div>
</div>
</body>
</html>
The Dummy is the heading of the box.Once I add the margin, the last box moves to the next line. I wanted it to stay in the same line even after resizing the browser.
Any help would be appriciated !
Thank you
Without the accompanying HTML and more knowledge of how you are constructing the page, we can only guess. Based only on the slight amount of code presented, I would suggest that you delete the margin:2px; assigned to .box.
You have assigned a width of 33.3% to each column plus a margin of 2px. Added together that exceeds 100% which would make the third column wrap below the first two.
When you post code here, you need to format it so that it will display correctly.
You can highlight your code, then use the </> button in the editor window, which will format it, or you can place three backticks ``` (top left key on US/UK keyboards) on a line before your code, and three on a line after your code. (I find this approach easier, but unfortunately some European and other keyboards don’t have that character.)
I would agree with @Gandalf that css tables would be a much better way to do this.
Also you need to validate your code, I notice you are nesting <p> elements within <span>s in the Codepen, which is invalid.
The 3 Columns stay in the same line after deleting the margin: 2px .
After deleting different amount of text , the height of the boxes change.
I haven’t learnt about table/table-cell or flexbox.
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<meta charset="utf-8">
<title>Assignment</title>
</head>
<body>
<h1 class="main">Our Menu</h1>
<div class="outer">
<span class="box b1">
<p class="heading">Chicken</p>
<p class="para">Borders and Colors: Each span should have a background color set to some color (of your choosing). Set the background color of each span title region to some unique color (of your choosing). Make sure that the background color still allows the user to view the text in the span and span title regions. Depending on the color you choose, you may want to change the color of the text so it can be easy to read. Set a black border on both the span and span title region that is 1px thick. Warning: While not specifying borders and colors according to the requirements does not hurt your grade so much, not doing so will make it much harder for your classmates.</p>
</span>
<span class="box b1">
<p class="heading">Beef</p>
<p class="para">Borders and Colors: Each span should have a background color set to some color (of your choosing). Set the background color of each span title region to some unique color (of your choosing). Make sure that the background color still allows the user to view the text in the span and span title regions. Depending on the color you choose, you may want to change the color of the text so it can be easy to read. Set a black border on both the span and span title region that is 1px thick. Warning: While not specifying borders and colors according to the requirements does not hurt your grade so much, not doing so will make it much harder for your classmates to peer grade the rest of your assignment, possibly resulting in a much lower grade.</p>
</span>
<span class="box">
<p class="heading">Sushi</p>
<p class="para">Borders and Colors: Each span should have a background color set to some color (of your choosing). Set the background color of each span title region to some unique color (of your choosing). Make sure that the background color still allows the user to view the text in the span and span title regions. Depending on the color you choose, you may want to change the color of the text so it can be easy to read. Set a black border on both the span and span title region that is 1px thick. Warning: While not specifying borders and colors according to the requirements does not hurt your grade.</p>
</span>
</div>
</body>
</html>
You should not be using span there, divs would be better, like in the OP.
Spans are in-line, p is a block, you cannot have a block inside an in-line element.
Try this in a fork of your codepen. Remove the floats and widths.
On .outer set display: table; table-layout: fixed; and on .box set display: table-cell.