Left border for dynamic div - html

I am struggling to get full length left border vertically on a div.
Problem is that i can not fix the height of div as content is loaded dynamically and it can be short and long.
I tried below approach:
Approach 1
CSS
div.right-col {
position: relative;
}
div.right-col:before {
content:"";
background: #ccc;
padding-left:2.5rem;
position: absolute;
bottom: 0;
left: 0;
height: 50%;
width: 1px;
}
HTML
<div class="left-col"></div>
<div class="right-col"></div>
Approach 2
CSS
.right-col {
position: relative;
}
#borderLeft {
border-left: 2px solid #f51c40;
position: absolute;
top: 50%;
bottom: 0;
}
HTML
<div class="left-col"></div>
<div class="right-col"><div id="border-left"></div></div>
Approach 3
CSS
.left-col {display:table-cell}
.right-col {
display:table-cell;
border-left: 1px solid #ccc;
padding-left: 2.5rem;
float: none;
height:auto;
}
HTML
<div class="left-col"></div>
<div class="right-col"></div>
But none of above things are working. Border is only till where content is present.

Is someting like that what you are looking for ?
<div>
<div style="height:100%;display:inline-block;background-color:#FF0000;">LEFT</div>
<div style="height:100%;display:inline-block;background-color:#0000FF;">RIGHT</div>
</div>
Otherwise, it may be easier to use bootstrap and the row & col-xx class.

Html
<div class="main">
<div class="left-col">sdfsdfsdf</div>
<div class="right-col">sdfsdfsdf
<br>
sdfsdfsdf
</div>
</div>
Css
.left-col {display:table-cell; width:100%; background-color: red;}
.right-col {
display:table-cell;
border-left: 1px solid #ccc;
padding-left: 2.5rem;
float: none;
height:auto;
background-color: green;
}
.main{
display:table;
}
Demo

This is sometimes referred to as the Holy Grail Problem and there are a number of hacks for it. However the first 'real' fix i believe is the flexbox. Here is how i would solve your problem:
Fiddle
HTML
<div class="container">
<div class="col left">Hi</br>Let's see how this works.</div>
<div class="col right">Hi</div>
</div>
CSS
.container, .col {
display:flex;
}
.container {
flex:1;
flex-direction:row;
}
.col {
flex-direction:column;
}
.col.right {
border-left: 1px solid black;
}
.col.left {
order:-1;
}

Related

Hide the border when div is on top [duplicate]

This question already has answers here:
Text in Border CSS HTML
(10 answers)
Closed 1 year ago.
I am using the following html and css to design a div with a title and a button at bottom:
.main-container {
height : 100%;
width : 100%;
position : absolute;
background-size : 100% 100%;
display : flex;
align-items : center;
background-color: lightgreen;
}
.content{
margin:auto;
border: 1px solid #0d0d63;
padding: 10px;
}
.title{
top: -21px;
position: relative;
border-bottom: 1px solid green;
}
.bottom-link{
position:relative;
top:19px;
background-color:green;
}
<div class="main-container">
<div class="content">
<div class="title">My Title</div>
test content
<div class="bottom-link">Bottom Link</div>
</div>
</div>
As you can see the title is crossed out because of the border. I can fix it by setting the background color to title class like I did for bottom-link. But the issue is I want the background-color ( or image if I add one) of the main-container to be visible throught the title. ie; I need the title div to be transparent. Is there any way to achieve this with css?
You can remove border top and give title ::before and ::after border bottom to get what you want
.main-container {
height : 100%;
width : 100%;
position : absolute;
background-size : 100% 100%;
display : flex;
align-items : center;
background-color: lightgreen;
}
.content{
margin:auto;
border: 1px solid #0d0d63;
border-top: none;
/* padding: 10px; */
}
.second-content{
padding: 10px;
}
.title{
top: -10px;
position: relative;
/* border-bottom: 1px solid green; */
}
.bottom-link{
position:relative;
top:19px;
background-color:green;
}
.separator {
display: flex;
align-items: center;
text-align: center;
}
.separator::before,
.separator::after {
content: '';
flex: 1;
border-bottom: 1px solid #0d0d63;
}
.separator:not(:empty)::before {
margin-right: .25em;
}
.separator:not(:empty)::after {
margin-left: .25em;
}
<div class="main-container">
<div class="content">
<div class="title separator">My Title</div>
<div class="second-content">
test content
<div class="bottom-link">Bottom Link</div>
</div>
</div>
</div>

HTML/CSS shapes div layout one on top of the other

I've got this shape made:
https://jsfiddle.net/5vue1buj/1/
However, the way I'm doing this is by inserting:
<br /><br /><br /><br />
in between the top and bottom. How do I do this more elegantly?
Remove all inline styling.
DEMO
HTML
<div>
<div id="top">
<div class="triangle-down-right">
<!--empty-->
</div>
<div class="triangle-down-left">
<!--empty-->
</div>
</div>
<div id="bottom">
<div class="triangle-up-right">
<!--empty-->
</div>
<div class="triangle-up-left">
<!--empty-->
</div>
</div>
</div>
Then add this CSS:
#top, #bottom {
float: none;
overflow: hidden;
}
#top {
margin-bottom: 10px;
}
By using css styles margin/padding you can achieve this.
In your case you have to clear the space between the two containers [top and bottom]. By default div elements are left aligned. I have added an empty divwhich will remove the space in between the two container [using clear:both. height and overflow is added for Cross browser compatibility]
please check this Fiddle.
By using minimal of html and css
You can use only two div and two its psuedo elements :after and :before
.bottom {
position:absolute;
width:210px;
top:180px;
}
.upper {
position:absolute;
width:210px;
top:20px;
}
.upper:before {
content:'';
position:absolute;
left:0;
width: 0;
height: 0;
border-bottom: 100px solid #4679BD;
border-left: 100px solid transparent;
}
.upper:after {
content:'';
position:absolute;
right:0;
width: 0;
height: 0;
border-bottom: 100px solid #4679BD;
border-right: 100px solid transparent;
}
.bottom:before {
content:'';
position:absolute;
left:0;
width: 0;
height: 0;
border-top: 100px solid #4679BD;
border-left: 100px solid transparent;
}
.bottom:after {
content:'';
position:absolute;
right:0;
width: 0;
height: 0;
border-top: 100px solid #4679BD;
border-right: 100px solid transparent;
}
<div class="upper"></div>
<div class="bottom"></div>
Here's another way, with much less CSS...
#top, #bottom {
height: 200px;
position: relative;
}
.right, .left {
height: 0;
width: 0;
display: inline-block;
}
#top {
margin-bottom: 10px;
}
.left {
margin-right: 10px;
}
#top .left {
border-top: 200px solid transparent;
border-right: 200px solid #4679bd;
}
#top .right {
border-top: 200px solid transparent;
border-left: 200px solid #4679bd;
}
#bottom .left {
border-bottom : 200px solid transparent;
border-right: 200px solid #4679bd;
}
#bottom .right {
border-bottom: 200px solid transparent;
border-left: 200px solid #4679bd;
}
<div>
<div id="top">
<div class="left"></div><div class="right"></div>
</div>
<div id="bottom">
<div class="left"></div><div class="right"></div>
</div>
</div>
Just for fun, here another example.
It uses pseudo elements and some new css3 properties to minimize the html markup down to only one div. This div is relatively positioned, but could as well be positioned absolutely for easily placing it wherever you like on the page.
A sophisticated jsfiddle can be found here where you can play around if the values easily (using Sass).
#shape{
position:relative;
background:#4679BD;
width:200px;height:200px;
transform:rotate(45deg);
margin-top:50px;margin-left:50px;
overflow:hidden;
}
#shape::before,#shape::after{
content:"";display:block;
position:absolute;
width:300px;height:10px;
background:white;
transform:rotate(45deg);
transform-origin:5px 5px;
left:-5px;top:-5px;
}
#shape::after{
transform:rotate(-45deg);
bottom:-5px;top:auto;right:-5px;
}
<div id="shape"></div>
Size is easily adjustable by adjusting the width of the pseudo elements like: (dim of shape + 5) * 1,414 and the height determines the gap between the triangles.

Make parent div with absolute position take the width of children divs

I have the following html structure:
<div class="parent">
<div class="child1"></div>
<div class="child2"></div>
</div>
The parent is positioned absolutely, child1 and child2 are displayed side-by-side using inline-block.
I need this whole thing to be responsive based on the width of the 2 children divs. the problem is, if I increase the width of any of them, the parent's width remains the same. Changing its position to relative fixes this, but I have to have it in absolute.
Is there anyway to get it to be responsive?
EDIT:
I was hoping for this to be simple, but apparently not so much... :(
here's the actual HTML:
<div class="action_container">
<div class="action_inner">
<div class="action_title">Format Text</div>
<div class="action_body">
<div class="action_args_section"></div>
<div class="action_output_section"></div>
</div>
</div>
</div>
And the CSS:
<style>
.action_container {
display: block;
position: absolute;
}
.action_inner {
border: 1px solid black;
}
.action_inner {
min-width: 120px;
min-height: 50px;
background-color: white;
border: 1px solid #666;
border-radius: 5px;
}
.action_title {
font-size: 12px;
font-weight: bold;
text-align: center;
border-bottom: 1px solid #ccc;
padding: 3px;
}
.action_args_section {
display: inline-block;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 3px;
}
.action_output_section {
display: inline-block;
width: 50px;
vertical-align: top;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 3px;
}
</style>
.parent{
position: absolute;
display: table;
}
.child{
position: relative;
display: table-cell;
}
Use this trick to set children in single line and parent to get width from them. Don't apply floats to nothing. And remember about white-space: nowrap; if You need to keep single line in child elements.
Here is fiddle.
.parent {
position:absolute;
height:50px;
border:1px solid red;
}
.child1 {
width:100px;
height:30px;
border:1px solid green;
}
.child2 {
width:150px;
height:30px;
border:1px solid blue;
}
<div class="parent">
<div class="child1"></div>
<div class="child2"></div>
</div>
Is this what you're looking for?
JSFiddle
.parent{
position:absolute;
left : 60px;
top : 60px;
width : auto;
height:auto;
border:1px solid black;
}
.parent .child{
display:inline-block;
border:1px solid blue;
}
<div class="parent">
<div class="child">aaaaaassssssssssssss</div>
<div class="child">sssssssccccccccccccccccccc</div>
</div>
Try use a max-width to set a maximum width for the parent div so it doesn't get wider than specified.
I did this easily. Changing the width of the divs changes the parent as well.
<div class="parent">
<div class="child1"></div>
<div class="child2"></div>
</div>
<style>
div{border:1px solid black;}
.parent{
position:absolute;
width:auto;
height:auto;
}
.child1{
display:inline-block;
width:40px;
height:40px;
}
.child2{
display:inline-block;
width:30px;
height:40px;
}
</style>
If you want a responsive design, make sure you're using percentages, and not pixel values because the size of the divs will be calculated by the viewport width.
If you just want the parent to resize based on the absolute sizes of the child divs, add height:auto; width:auto to the parent. Then, change the child divs to display:block; float:left. The parent will resize accordingly.
Updated CodePen Demo
CSS
.action_container {
display: block;
position: absolute;
height:auto;
width:auto;
}
.action_inner {
border: 1px solid black;
}
.action_inner {
min-width: 120px;
min-height: 50px;
background-color: white;
border: 1px solid #666;
border-radius: 5px;
}
.action_title {
font-size: 12px;
font-weight: bold;
text-align: center;
border-bottom: 1px solid #ccc;
padding: 3px;
}
.action_args_section {
display: block;
float:left;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 3px;
width:300px;
border: 1px solid red;
}
.action_output_section {
display: block;
float:left;
width: 150px;
vertical-align: top;
box-sizing: border-box;
-moz-box-sizing: border-box;
padding: 3px;
border: 1px solid blue;
}
see the sample solution here in jsfiddle link
using this css:
.parent{
position:fixed;
background-color:blue;
height:auto;
width:auto;
}
.child1{width:200px;background-color:black;height:200px;float:left;}
.child2{width:200px;background-color:red;height:200px; float:left;}
if it is not what you're looking for,you can edit your css here then we can help
.parent{
float: left;
posetion: absolute;
background-color: yellow;
width:auto;
height: auto;
}
.parent div{
float: left;
display: inline-block;
width: 100px;
height: 100px;
background-color: red;
}
<div class="parent">
<div class="child1">this</div>
<div class="child2">this</div>
</div>
Here's The Code You Need :)

Position: relative and floating elements

I'm trying to set a simple page grid. Each row consists of an optional left column, plus a main content right column. I want the right column to remain the same size at the same position even if the left column isn't present.
I figured that floating the left column and using position: relative with left: on the right column would give me the behaviour I want.
My HTML looks like this:
<div class="row">
<div class="sidebar">I'm a sidebar!</div>
<div class="main">
<p>I'm main!</p>
</div>
</div>
and my CSS looks like this:
.sidebar {
float: left;
width: 200px;
border: 1px solid red;
}
.main {
position: relative;
left: 220px;
width: 500px;
border: 1px solid green;
}
Here's a fiddle: http://jsfiddle.net/ttr5k/1/
To my surprise, the content of .main is shifted right (as if .main had padding-left) seemingly due to the sidebar. Why is this, and how could I solve it?
I also suspect this isn't the best way to build a grid, is there a better approach?
Add position absolute instead of relative
http://jsfiddle.net/ttr5k/2/
As you can see the text aligns left again
.sidebar {
float: left;
width: 200px;
border: 1px solid red;
}
.main {
position: absolute;
left: 220px;
width: 500px;
border: 1px solid green;
}
I recommend doing something like this:
.row {
background:#eee;
width:90%;
overflow:auto;
border:1px solid #ccc;
margin:20px auto;
}
.sidebar {
float: left;
width: 200px;
border: 1px solid red;
}
.main {
float:left
width: 500px;
border: 1px solid green;
overflow:auto;
clear:right;
}
Now you will be able to remove the sidebar whenever you want without adding new CSS
DEMO: http://jsfiddle.net/ttr5k/5/
OR------
if you want that space even if no sidebar and still want to content to overflow:
http://jsfiddle.net/ttr5k/7/
.row {
background:#eee;
width:600px;
overflow:auto;
border:1px solid #ccc;
margin:20px auto;
}
.sidebar {
float: left;
width: 200px;
border: 1px solid red;
}
.main {
float:right;
width: 396px; /* This is due to box-model adding border as width */
border: 1px solid green;
overflow:auto;
clear:right;
}
Here is the FIDDLE on how I would do it: http://jsfiddle.net/mikea80/zJa5P/
<div class="row">
<div class="main">
<p>I'm main!</p>
</div>
<div class="sidebar"><p>I'm a sidebar!</p></div>
</div>
.row {
margin: 0 auto;
width:704px;
clear:both;
}
.main {
display:inline-block;
float:right;
width: 500px;
border: 1px solid green;
}
.sidebar {
display:inline-block;
float: right;
width: 200px;
border: 1px solid red;
}
With the row being 700px this code will center it
You have to add position absolute to sidebar class.
CSS:
.sidebar {
position: absolute;
float: left;
width: 200px;
border: 1px solid red;
}
.main {
position: relative;
left: 220px;
width: 500px;
border: 1px solid green;
}
Trust me, this way, you can add other row class without any problem. Here is the FIDDLE:
http://jsfiddle.net/asubanovsky/bVr6r/

CSS Problems with div at the bottom

I have a div that is at the bottom of my page. It's CSS is:
#news-bottom {
color: white;
position: fixed;
white-space: nowrap;
overflow: hidden;
height: 66px;
bottom: 0;
right: 390px;
left: 180px;
padding: 5px;
border: 1px solid #CCC;
background-color: black;
}
And I have the div's content like on the image:
content html:
<span>
<span><b>Teste</b></span>
<span>Teste com BBCodes</span>
<img style="border: 1px solid #CCC; padding:2px; margin-left: -3px;" src="images/news/empty.png">
</span>
How do I make for my div's content show up something like this:
I can't use line breaks or tables, because the div's position is fixed, and now I don't know what to do...
Something like this JSFiddle should work.
What we do is apply the background-color to the children of the container div. Then we give them some padding, which creates the space between them. Voila!
HTML:
<div id="news-bottom">
<span>
<span><b>Teste</b></span>
<span>Teste com BBCodes</span>
<img style="border: 1px solid #CCC; padding:2px; margin-left: -3px;" src="images/news/empty.png">
</span>
CSS:
#news-bottom {
color: white;
position: fixed;
white-space: nowrap;
overflow: hidden;
height: 66px;
bottom: 0;
right: 390px;
left: 180px;
padding: 5px;
border: 1px solid #CCC;
}
#news-bottom span span,
#news-bottom span img {
background-color: black;
padding: 5px;
}​​
If you want fixed position, you can make several divs and change their left property to what you like. You can use % positioning so they look almost the same on different resolutions.
But, I'd recommend using float in a fixed container <div>, and combine with #jmeas suggestion of margins. Something like this:
HTML
<div class='container'>
<div class='arrow'></div>
<div class='item'>One</div>
<div class='item'>Two</div>
<div class='item'>Three</div>
<div class='arrow'></div>
</div>
CSS
#container {
...fixed...
}
.arrow {
float:left;
width:10%;
}
.item {
float:left;
margin-left:5px;
width:20%;
}