CSS Table Elements With Double Size Border In Middle - html

I am trying to create a CSS Table based layout which has an even spacing/border around each table cell and making sure that the table-cells are always the same height. Here is an example of what I am trying to achieve:
My HTML currently looks like this:
.two-col.body-width {
max-width: 1138px;
}
.two-col {
display: table;
clear: both;
margin: 0 auto;
padding: 20px 0;
width: 100%;
box-sizing: border-box;
border-spacing: 25px 0px;
}
.two-col > .col_container.align-top {
vertical-align: top;
}
.layout .section-tout {
position: relative;
padding: 20px 40px 48px;
background: #f4f4f3;
border-left: 5px solid #da202a;
}
.two-col > .col_container {
width: 50%;
display: table-cell;
text-align: left;
vertical-align: middle;
box-sizing: border-box;
}
<section class="layout two-col body-width">
<div class="col_container align-top section-tout">
<!-- content goes here -->
</div>
<div class="col_container align-top section-tout">
<!-- content goes here -->
</div>
</section>
Here is a working example: https://jsfiddle.net/grzkgdp3/1/
What I have here is almost perfect, but as you can see from the image I updated I need the spacing / border to be doubled in the middle and I cannot see an intelligent way of doing this.
I can see a solution where I used border: 25px solid white; on the tabel-cell. This solves my spacing issue but because I need the red border on the left, I then have to apply this using the :after pseudo element which makes things a bit messy.
If anyone has a solid solution that can help it would be great to hear it.
Cheers!
Update
Unfortunately I cannot use a flexbox solution as I need to support all modern browser and IE9 and above.

Sometimes we must bend to support compatibility. I used linear-gradients to achieve the result.
body {
background: white;
}
.two-col.body-width {
max-width: 1138px;
}
.two-col {
display: table;
clear: both;
margin: 0 auto;
padding: 20px 0;
width: 100%;
box-sizing: border-box;
}
.two-col > .col_container.align-top {
vertical-align: top;
}
.layout .section-tout p {
position: relative;
padding: 20px 40px 48px;
margin: 0;
}
.two-col > .col_container {
width: 50%;
display: table-cell;
text-align: left;
vertical-align: middle;
box-sizing: border-box;
padding: 0px 25px;
background-image: linear-gradient(to right, transparent 25px, #da202a 25px, #da202a 30px, #f4f4f3 30px, #f4f4f3 calc(100% - 25px), transparent 0);
background-image: -ms-linear-gradient(to right, transparent 25px, #da202a 25px, #da202a 30px, #f4f4f3 30px, #f4f4f3 -ms-calc(100% - 25px), transparent 0);
}
<section class="layout two-col body-width">
<div class="col_container align-top section-tout">
<p>
See how there is different amounts of content, but the cells are always the same height, this is very important!
</p>
</div>
<div class="col_container align-top section-tout">
<p>
Hi!
</p>
</div>
</section>
Working Fiddle
Working fiddle (without calc)

Have you considered Flexbox
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background: white;
}
.two-col.body-width {
max-width: 1138px;
padding: 25px;
}
.two-col {
display: flex;
margin: 0 auto;
box-sizing: border-box;
}
.layout .section-tout {
position: relative;
background: pink;
padding: 20px;
border-left: 5px solid #da202a;
flex: 0 1 50%;
display: flex;
}
.two-col > div:first-child {
margin-right: 50px;
}
<section class="layout two-col body-width">
<div class="col_container align-top section-tout">
<p>
See how there is different amounts of content, but the cells are always the same height, this is very important!
</p>
</div>
<div class="col_container align-top section-tout">
<p>
Hi!
</p>
</div>
</section>

Related

How to make divs and div children with inset border are perfectly touching left and top vertically descending

I am trying to make a table, but I do not wish to use a table.
I have instead placed divs inside other divs just as shown below:
<div class="windows" id="head">
<div class="windows" id="location">
<div class="windows" id="character">
<div class="windows" id="buttons">
<div class="windows" id="textbox"></div>
</div>
</div>
</div>
<div class="windows" id="map"></div>
</div>
And I want to have them essentially look just like this:
Click image link
But as soon as I make the border in CSS for all divs to be :
border: 0px gold;
Then it lines them up with a 3px margin or padding:
Click image link
I've personally tried to set the margin and padding of *, body, #head, div and .windows to:
div {
padding: 0;
margin: 0;
}
This has been fruitless.
A big chunk of the CSS currently looks like this, where the remaining divs go by the same pattern as #location. Where the "top" is always the "height" of the previous .
html {
background-color: black;
font-family: gabriela;
text-color: black;
}
body {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
padding: 0;
}
div {
padding: 0;
margin: 0;
}
.windows {
box-sizing: border-box;
display: block;
position: relative;
border: 3px gold;
border-style: inset;
background-color: maroon;
}
#head {
width: max(500px, 100%);
height: max(150px, 15%);
}
#location {
background-color: purple;
width: 380px;
top: max(150px, 15%);
height: max(100px, 10%);
}
I think that you are too over complicating, try using grid-layout it will be much easier.
Here is a link of how to use grid-layout https://www.w3schools.com/css/css_grid.asp.

Formatted text displays outside of floating container

I created a container. Plain text in the container displays inside the container, however, formatted text displays outside of the container. Please give suggestions. My html and css are posted below.
This is my html:
.left-column {
text-align: left;
float: left;
width: 40%;
padding-left: 5px;
}
.right-column {
text-align: left;
float: left;
width: 50%;
padding-left: 200px;
}
#container {
width: 900px;
background-color: #ffffff;
border: 1.5px solid #FFCC99;
margin: 0;
padding: 10px;
}
.border1 {
width: 910px;
border: 3px solid #376092;
margin: 1px;
padding: 2px;
}
border2 {
width: 915px;
border: 2px solid #FFCC99;
margin: 12px auto 12px auto;
}
<main id="gap">
<div class="border2">
<div class="border1">
<div id="container">
<div class="left-column">
</div>
<div class="right-column">
</div>
</div>
<!-- End Container -->
</div>
<!-- End Border1 -->
</div>
<!-- End Border2 -->
</main>
because you are floating the .left-column and .right-column, you should use a clearfix
Also I would advise you to use box-sizing:border-box, see more about border box model
Here is a snippet:
.cf:before,
.cf:after {
content: " ";
display: table;
}
.cf:after {
clear: both;
}
*, *:before, *:after {
box-sizing: border-box;
}
.left-column {
text-align: left;
float: left;
width: 40%;
padding-left: 5px;
}
.right-column {
text-align: left;
float: left;
width: 50%;
/*padding-left: 200px; - this can be removed */
}
#container {
width: 900px;
background-color: #ffffff;
border: 1.5px solid #FFCC99;
margin: 0;
padding: 10px;
}
.border1 {
width: 910px;
border: 3px solid #376092;
margin: 1px;
padding: 2px;
}
.border2 {
width: 915px;
border: 2px solid #FFCC99;
margin: 12px auto 12px auto;
}
<main id="gap">
<div class="border2">
<div class="border1">
<div id="container" class="cf">
<div class="left-column">text left</div>
<div class="right-column">text right</div>
</div>
<!-- End Container -->
</div>
<!-- End Border1 -->
</div>
<!-- End Border2 -->
</main>
Set overflow:hidden in #container. This will force the container to respect the height of all elements within it, regardless of floating elements.
CSS
#container {
width:900px;
background-color: #ffffff;
border:1.5px solid #FFCC99;
margin: 0;
padding:10px;
overflow: hidden; /* Set this rule */
}
DEMO HERE
The problem is your padding on your #container.
Your css is :
padding: 10px and width: 910px
So, your padding add 20px (10px right, 10px left).
In the end, your #containter width is 920px and your parent div is 910px.
To fix your problem, you need to set the width of your parent to 920 or change the padding to : padding:5px;

Issue with DIV positions

would you know why my red div (.block) is placed above the blue wrapper and not within? Also would expect the text to be within the red DIV as well. Thanks http://jsfiddle.net/B3CL6/
HTML:
<div class="wrapper blue-background ">
<div class="block width100">
<div class="block-left">
<h3>Block left </h3>
</div>
<!-- End DIV block-left -->
<div class="block-right">
<h1>block right</h1>
</div>
<!-- End DIV block-right -->
</div>
<!-- End DIV block width100 -->
</div>
<!-- End wrapper -->
CSS:
.wrapper {
position: relative;
display: block;
margin-right: auto;
margin-left: auto;
width: 980px;
overflow: hidden;
}
.block {
padding: 20px;
text-align: justify;
background-clip: border-box;
box-sizing: border-box;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
background: red;
}
.width100 {
width: 100%;
}
.top {
margin-top: 30px;
}
.blue-background {
background: #124191;
}
.block-left {
float: left;
box-sizing: border-box;
width: 50%;
}
.block-right {
float: right;
overflow: hidden;
box-sizing: border-box;
width: 50%;
}
As far as i understand is you want the Red Block inside the Blue Block. if so
try this. set the padding-top:10px to Padding:10px
.wrapper {
position: relative;
display: block;
margin-right: auto;
margin-left: auto;
width: 980px;
overflow: hidden;
padding: 10px;
}
and if you want the text inside that do something like this or add another style for the "Block Right" text
H1{
display: inline;
}
Red div(.block) is actually present inside Blue div(.wrapper). As suggested by JoshC you can check it by making your red background as semi-transparent.
To get the text to be within the red DIV,
Remove overflow: hidden; property from .wrapper class and add it to .block class.
That should solve your problem.

Setting the min-height of a div within the zurb-foundation

I've just been introduced to the Zurb Foundation 4 framework via a friend of mine. Interesting stuff. But i'm having a problem I can't seem to understand. I have a site based on 4 rows (header, navbar, content, footer);
<div class="row siteBase">
<div class="row siteHeader" id="siteHeader">
<div class="large-12 c7olumns">
<h2>Welcome to Foundation</h2>
<p>This is version 4.1.2.</p>
</div>
</div>
<div class="row siteNavbar" id="siteNavbar">
navbar
</div>
<div class="row siteBody" id="siteBody">
base
</div>
<div class="row siteFooter" id="siteFooter">
footer
</div>
</div>
here's my CSS
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.siteBack {
background-color: #545454;
}
.siteBase {
/*base size and color*/
width: 1280px;
min-height: 100%;
margin: 0 auto;
background-color: #f2f2f2;
/* exact fit the contents to the border */
padding-left:15px;
padding-right:15px;
/* border size and color */
border-style: solid;
border-left-width: 4px;
border-top-width: 0px;
border-right-width: 4px;
border-bottom-width: 0px;
border-color: #7da500;
/* add some shadows to the borders */
-moz-box-shadow: 0 0 10px 5px #272727;
-webkit-box-shadow: 0 0 10px 5px #272727;
box-shadow: 0 0 10px 5px #272727;
}
.siteHeader
{
width: 100%;
height: 250px;
background-color: #7da500;
}
.siteNavbar
{
height: 50px;
background-color: #1d1d1d;
}
.siteBody
{
min-height: 100% auto;
margin: 0 auto;
background-color: #f2f2f2;
}
.siteFooter
{
height: 50px;
background-color: #7da500;
}
The problem I have is that the sitebody div isn't stretched to to full 100%. The header and navbar is fixed size, as is the footer. But I wan't the sitebody div to take the remaining space so that the footer is always placed in the lower bottom of the screen (at minimum).
What am I missing here? Thanks a lot for your help.
Basically what you need is to stick your footer to the bottom of the page. In that manner you will have a full body even if your main content is small. You can take a look at this SO question to see how it is implemented. There could be a lot going on in there as that layout is a bit complex. So I did a sample for you that you can use for a more simple layout. Here is the modified css from the other SO question.
html, body, #wrapper{ height: 100%; }
body > #wrapper{height: auto; min-height: 100%;}
#main { padding-bottom: 75px; /* same height as the footer */
overflow:hidden;
top: 75px; bottom: 0; left: 0; right: 0;
background-color:yellow;
}
#footer {
position: relative;
margin-top: -75px; /* negative value of footer height */
height: 75px;
clear:both;
}
.clearfix:after {content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;}
.clearfix {display: inline-block;}

Floating two 50% width divs with a 10px margin between

I want to float a pair of fluid divs across my page, each taking up half of their container's width, but with a margin of 10px between them. I've done this JSFiddle http://jsfiddle.net/andfinally/sa53B/5/, and here's the HTML:
<div class="clearfix">
<a class="prev" href="#">Previous</a>
<a class="next" href="#">Next</a>
</div>
And CSS:
.prev {
background: black;
color: white;
font-size: 16px;
margin-bottom: 10px;
display: block;
float: left;
box-sizing: border-box;
width: 50%;
margin-right: 5px;
}
.next {
background: black;
color: white;
font-size: 16px;
margin-bottom: 10px;
display: block;
float: right;
box-sizing: border-box;
width: 50%;
margin-left: 5px;
}
The box-sizing rule isn't enough to make this work - the divs are more than 50% wide. In one of the answers to this question somebody suggested using CSS display-table. Can anyone explain how to make that work in this situation?
Thanks!
You can either a) lower 50% to 48% and make the margin 2% or b) use CSS3 calc, which is not supported everywhere, but should be an option in the near future. (Specifically, when IE8 is off the table) (See http://caniuse.com/#feat=calc for compatability)
Example using percentages: http://jsfiddle.net/sa53B/9/
.prev {
background: black;
color: white;
font-size: 16px;
display: block;
float: left;
box-sizing: border-box;
width: 48%;
margin: 0 2% 10px 0
}
.next {
background: black;
color: white;
font-size: 16px;
display: block;
float: right;
box-sizing: border-box;
width: 48%;
margin: 0 0 10px 2%
}
Example using calc: http://jsfiddle.net/sa53B/6/
.prev {
background: black;
color: white;
font-size: 16px;
display: block;
float: left;
box-sizing: border-box;
width: 47%;
width: -webkit-calc(50% - 5px);
width: calc(50% - 5px);
margin: 0 5px 10px 0;
}
.next {
background: black;
color: white;
font-size: 16px;
display: block;
float: right;
box-sizing: border-box;
width: 47%;
width: -webkit-calc(50% - 5px);
margin: 0 0 10px 5px;
}
Margin will add to your containers width. If you are using a width that is based on a percentage you should set your margin value a percentage as well.
For example, if you want two 50% divs. You need to account for the margin too. In order to do so, you need to subtract the margin from the total width. If you want 1% margin left and right, thats a total of 2% you need to remove from the total width.
div {
float: left;
width: 48%;
margin: 0 1%;
}
your updated fiddle: http://jsfiddle.net/sa53B/8/
Recently in my task i need two float columns with 8px fixed margin between them.
So, i used border and box-sizing properties without any calc magic.
So, the solition is:
.wrapper__col {
width: 50%;
box-sizing: border-box; // used to change box-model
overfow: hidden; // clearfix hack
}
.wrapper__col:nth-child(odd) {
float: left;
border-left: 4px solid transparent;
}
.wrapper__col:nth-child(even) {
float: right;
border-right: 4px solid transparent;
}
<div class="wrapper">
<div class="wrapper__col">1</div>
<div class="wrapper__col">2</div>
</div>
So, that's all ;)
It's late but someone might be interested in this way to fix :
Wrap the elements you wish to display in columns with divs :
<div class="left"><a ....></a></div>
<div class="right"><a ....></a></div>
And just set those styles :
.left {
float:left;
width:50%;
}
.right {
float:right;
width:50%;
}
Whatever the margin of divs contents it won't affect the 50% width.
I used to proceed this way before hearing of usefull css calc.
See JSFiddle
What you are trying to do does not work with fixed margins. You need to calculate using percentage margins.
Box sizing only affects padding and border space, not margin space. So 50% + 50% =100% +5px+5px > 100%.
Use % margins and your problem is solved.
Here's how I do it, but it uses variable gap between:
css:
.left {
float:left;
width:59%;
margin-right: 1%;
background-color:red;
}
.right {
float:left;
width:39%;
margin-left: 1%;
background-color:blue;
}
html:
<div>
<div class="left">left</div>
<div class="right">right</div>
</div>
jsfiddle:
http://jsfiddle.net/gkmjLfgx/
Sometimes you want the same 10px spacing horizontally and vertically and still have equally sized columns.
You can do this by adding a "border-left: 10px solid white" to an extra DIV inside each column and add a "margin-left: -10px" to the columns container to eat up the border of the left column.
fiddle 128psahu