Dynamically expand div upon hiding another - html

I am new to posting on this site, so please excuse any errors I may make.
So as my question states, I'm essentially looking for a way to dynamically expand divs. So far I have a container div with three columns inside it. Each of the columns have a link to some javascript that sets it to disply:none. What I'm looking for a way to do is, for example, if I was to click the hide button in the center column, I want the two outer columns to expand to take up the space left behind. Perhaps a way to increase the width of the two from 33% each to 50% upon hiding the middle one.
So that the two other divs essentially share the newly created space between them.
Here is my html and css as it is just now:
HTML:
<div id="col2outer">
<div id="col1">
<p>test</p>
Hide
</div>
<div id="col2mid">
<p>test</p>
Hide
</div>
<div id="col2side">
<p>test</p>
Hide
</div>
</div>
CSS:
#container #col2outer {
height:200px;
width: 870px;
float: left;
margin: 0;
padding: 0;
}
#container #col1 {
height:200px;
width: 33%;
float: left;
border-width: 0.5mm; border-style: groove;
-moz-border-radius: 15px;
border-radius: 15px;
}
#col2outer #col2mid {
height:200px;
width: 33%;
float: left;
border-width: 0.5mm; border-style: groove;
-moz-border-radius: 15px;
border-radius: 15px;
}
#col2outer #col2side {
height:200px;
width: 33%;
float: left;
border-width: 0.5mm; border-style: groove;
-moz-border-radius: 15px;
border-radius: 15px;
}
Thank you in advance for any help, and apologies if this question has already been asked

Hy!
You can try something like:
Click on hide button:
$(document).ready(function(){
$('button').click(function(){
$('#col1').css("display","none");
$('#col2mid').css("width","49%");
$('#col2side').css("width","49%");
})
});
This is very simple way for resizing divs...
if you want to click on coloumn and then hide/show and resize you will need to rename your columns, or your code will be long...
EDIT:
Something like this:
http://jsfiddle.net/pbnkH/

Related

CSS: how to make scrollbar appear outside div's border?

I'm creating some kind of chat box for my website and I can't make vertical scrollbar to appear outside the border.
This is what I'm getting:
All I want is that scrollbar to appear outside the border, on the right. It's not really pretty as it is now, is it.
The main HTML code (with one message insise the chatbox) of thix box looks like this:
<div id="sb_body">
<div id="sb_messages_set">
<div class="sb_message">
<div class="sb_message_header">
<div class="sb_message_author">PookyFan</div>
<div class="sb_message_hour">12:11</div>
</div>
<div class="sb_message_content">test</div>
</div>
</div>
<!-- Some other chatbox's elements -->
</div>
My CSS code looks like this:
div#sb_messages_set
{
border: 2px solid black;
border-radius: 10px;
background-color: #0080E0;
overflow: auto;
height: 300px;
}
div.sb_message
{
margin: 2px 4px 5px 4px;
border-bottom-style: dashed;
border-width: 1px;
border-color: black;
}
div.sb_message_header
{
clear: both;
display: block;
margin-bottom: 3px;
}
div.sb_message_author
{
display: inline;
text-align: left;
font-weight: bold;
}
div.sb_message_hour
{
display: inline;
float: right;
}
div.sb_message_content
{
clear: both;
text-align: left;
padding-bottom: 5px;
}
Is there any way to achieve what I want? I was looking for answer but didn't find anything that would solve my problem.
Oh, and if there's anything wrong with my code but it's not connected with my issue, please share your thoughts, I started having fun with creating websites pretty recently so it's possible that I make some newbie mistakes here and am not really aware of it.
Edit: important thing I forgot to mention about - I want the border to be fully visible all the time, I mean - I want just the messages to be scrolled, but wihout making the border be scrolled with it.
In other words, I don't want anything like that:
In this picture the chatbox has been scrolled a little and the top and bottom frame isn't visible. But I want the entire frame to be visible despite div's content being scrolled.
Well, if that won't work, and you're married to the design, I think you have to use a bg image. I can't find a way to style the scrollbar with CSS. I made another jsfiddle with this solution demonstrated: http://jsfiddle.net/jlmyers42/mrx46geg/
But basically, you just move some of your CSS around:
#sb_body {
width: 272px;
height: 300px;
overflow: auto;
padding: 0;
margin: 0;
background: url("http://arcsuviam.com/play/random/bluebg.png") no-repeat left top;
}
div#sb_messages_set {
margin: 5px;
}
div.sb_message {
padding: 2px 4px 5px 4px;
border-bottom-style: dashed;
border-width: 1px;
border-color: black;
}
I'd put the whole thing in a container that has the overflow:auto style applied.
See this fiddle: http://jsfiddle.net/jlmyers42/8tptqt19/
<div id="sb_body">
<div id="sb_container">
<div id="sb_messages_set">
<div class="sb_message">
<div class="sb_message_header">
<div class="sb_message_author">PookyFan</div>
<div class="sb_message_hour">12:11</div>
</div>
<div class="sb_message_content">test</div>
</div>
</div>
</div>
<!-- Some other chatbox's elements -->
</div>
CSS
div#sb_container {
overflow: auto;
}
Simple.
With your div
Put the static width like below:
#divID{
overflow: hidden;
width: calc(1024px + 0);
}
#divID:hover{
overflow-y:scroll;
}
Stumbled across it and works for me. My div is positioned absolute if that makes a difference.
The scroll bar appears outside the div when hovered on
so you can check out that site - it describes you the solution precisely. I created a small jsfiddle for you. Note here that the text-div inside the "li" has a width in "vw". This makes the effect of scrolling outside the content. Hope this helps!
HTML
<ul><li id="lio" class="open"><div class="text">
Lorem..
</div></li></ul>
<button>
Halo
</button>
CSS
.open {
overflow: hidden;
display: block;
width: 100%;
height: 100px;
background-color: red;
}
.text {
padding: 15px;
background-color: orange;
width: 30vw;
}
ul {
display: table;
}
JQUERY
$(document).ready(function() {
http://jsfiddle.net/fcLzqp5o/#run
$("button").click(function() {
$("#lio").css("overflow-y", "scroll");
});
});

Two different divs sharing css attributes

Im creating a website for a guild I am apart of, and whilst creating this page, Im trying to have a div within a div, the dark div (contentBox) for holding the lighter divs (contentSection), which in turn, hold text. However, when altering padding of the contentSection div, it also moves the contentBox div. Ill provide screen shots so you can see what I mean.
Html is simply:
<div class="contentBox">
<div class="contentSection">
<h2> We have TeamSpeak!</h2>
</div>
</div>
CSS is:
.contentBox{
background-color: #1E1E1E;
border-color: #080808;
border-right-style: solid;
border-left-style: solid;
border-width: 1px;
height: 100vh;
width: 70%;
margin: 0 auto;
}
.contentSection{
background-color: #4B4B4B;
height: 30%;
width: 85%;
margin: 110px auto;
padding-top: 5px;
border-radius: 2px;
padding-left: 15px;
}
What I want it to look like:
What it ends up looking like:
I apologise if im too vague, just ask if you have questions.
Question has been Solved, adding overflow: auto fixed the problem!
Why this is happening
The effect you are seeing is due to collapsing margins. Adding overflow: auto creates a new block formatting context which keeps borders within the edges of the containing block.
Adding padding also prevents margins from collapsing. In your top image, you have padding, so the margin on h2 and the inner div are contained within the outer block. With no padding, the margin of inner elements collapse with the margins from the outer div's.
try this
is it ok?
.contentBox {
background-color: #1E1E1E;
border-color: #080808;
border-right-style: solid;
border-left-style: solid;
border-width: 1px;
height: 100vh;
width: 70%;
margin: 0 auto;
}
.contentSection {
background-color: #4B4B4B;
height: 30%;
width: 85%;
margin: 110px auto;
padding-top: 5px;
border-radius: 2px;
padding-left: 15px;
padding-top: 50px;
}
<div class="contentBox">
<div class="contentSection">
<h2> We have TeamSpeak!</h2>
</div>
</div>

Margin between two boxes in CSS

First, I'm a newbie on front-end development. I just want to hear about possible "professional" solutions of my problem from professionals.
Now, firstly check out this fiddle: http://jsfiddle.net/SB7yR/
Here is what I want: create two boxes on each row. I can't do that right here because I want to make margin between two boxes too.
I have solutions for that situation for example create a class like "last" and give it margin-right: 0; then apply it last boxes for each row. But I don't want to do that. It sounds .. hmm.. an amateur solution.
Thanks for advices.
You can add a text-align: justify; to .addresses and remove the margin-right on address_box.
.addresses {
margin-top: 30px;
text-align: justify;
}
also, you should use a class for .addresses #address-box instead of an ID. ID's are supposed to be unique on a page, so only one element is allowed to have a particular ID. Use this instead .addresses .address-box.
Try below code:-
.addresses #address-box {
height: 123px;
width: 298px;
border-color: black;
border-style: solid;
border-width: 1px;
float:left;
margin-right: 20px;
}
#address-box:nth-child(2n) {
margin-right:0;
}
My suggestion would be to make a class for all boxes (assuming each box would be the same size), then float all the boxes left. You would then make the width (in actual physical size or percentage) to be less than the width of the containing div. This would accomplish you having two boxes in each row. Hope this helps.
.box{ float:left; width:48%; margin-right:5px; }
Something like that. Experiment with the margin right amount.
for cross browser compatibility, how about an additional html element:
http://jsfiddle.net/SB7yR/8/
html:
<div id="addresses-wrap">
<div class="addresses">
<div class="overflow">
<div id="address-box"></div>
<div id="address-box"></div>
<div id="address-box"></div>
<div id="address-box"></div>
<div id="address-box"></div>
</div>
</div>
</div>
css:
#addresses-wrap {
width: 620px;
height: auto;
border:1px solid green;
overflow:hidden;
}
.addresses {
width:100%;
float:left;
margin-top: 30px;
}
.addresses .overflow {
width:650px;
overflow:hidden;
}
.addresses #address-box {
height: 123px;
width: 298px;
border:1px solid #000;
float:left;
margin:0 20px 20px 0;
}
You'll need to use a float to make this work. Try replacing your .addresses #address-box definition with the following:
.addresses #address-box {
height: 123px;
width: 288px;
border-color: black;
border-style: solid;
border-width: 1px;
display: inline-block;
margin: 10px;
overflow: hidden;
float: left;
}

Trouble aligning DIVs on horizontal plane

I'm on Win XP but this problem occurs on Firefox, IE, and Google Chrome. I want to align two DIVs on the same horizontal plane. I want the div on the left to occupy 24% of the screen and the div on the right to occupy the rest. Everything looks fine when my browser is maximized, but when I click the resize button to make the window smaller, the two DIVs are no longer on the same plane. The top of the right DIV appears beneath the bottom edge of the left DIV (the left boundary of the right DIV is still correctly aligned just after the right boundary of the left div).
How can I make both DIVs appear on the same horizontal plane, even when the window is not maximized? Here is the HTML I'm using ...
<div class="header">
<img src="logo.gif"/>
</div>
<div class="container">
<div id="contents">
<div class="categoryPanel"></div>
<div class="productDetailsPanel"></div>
</div>
</div>
and here is the CSS ...
.header {
width: 100%;
height: 63px;
background-color: #333366;
}
.container {
width: 100%;
}
.categoryPanel {
height: 600px;
width: 24%;
float: left;
margin: 10px 5px 0px 0px;
background-color: green;
}
.productDetailsPanel {
height: 600px;
border-color: #BBBBBB;
border-style: solid;
border-width: 1px;
float: right;
margin: 10px 10px 0 5px;
}
Thanks, - Dave
One way to kind of achieve the layout you want is to stop floating .productDetailsPanel, and give it a left margin of 25% (i.e. the width of .categoryPanel, plus spacing between them). (You’ll also want to remove the top margin on .categoryPanel.)
http://jsfiddle.net/uSbAs/
But that does mean the spacing between your columns will be defined as a percentage of the .container, rather than a fixed number of pixels.
On .productDetailsPanel, remove float: right and add overflow: hidden, job done; it's exactly what you asked for.
http://jsfiddle.net/thirtydot/KjZ8Q/
The reason overflow: hidden helps in this case is not obvious, read this.
In order for it to take up the entire space you would need to either fill it with something or provide a width. I've create a jsfiddle to show the results. Essentially I modified the .productsDetailsPanel by adding a width: 75%; removing the float:right; and modifying your margin: 10px 0 0 0;
Here is the new css for .productsDetailsPanel
.productDetailsPanel {
height: 600px;
width: 75%;
border-color: #BBBBBB;
border-style: solid;
border-width: 1px;
margin: 10px 0px 0 0px;
float: left;
background-color: red;
}
http://jsfiddle.net/rhoenig/qXvag/
This could work (float: left):
.productDetailsPanel {
height: 600px;
border-color: #BBBBBB;
border-style: solid;
border-width: 1px;
float: left;
margin: 10px 10px 0 5px;
}

Is it possible you place text within another elements margin?

SO designing a website, I ran into a particular problem.
I want two columns of text next to each other. So I floated (left) the first set of text left, and set a margin of 50% to keep it to one side. But when I did the next column of text, and floated it right (I tried left too), but it appears under the former column of text. I also tried using position:relative and moving it, but it refused to move.
I am guessing this is becuase elements cannot be placed within another elements margin.
Please help, with no Javascript. It is evil.
html
<h1 id="firstcolumn">blahblahblahblahblahblah</h1>
<h2 id="secondthingy">foobarfoobarfoobar</h2>
css
#firstcolumn {
float: left;
margin: 20;
margin-left: 15px;
margin-right: 50%;
border-right-style: solid;
border-right-color: black;
border-right-width: 3px;
font-size: 200%;
}
#secondthingy {
float: right;
}
The following should get you two columns of left aligned text:
#firstcolumn {
float: left;
margin: 20;
max-width: 50%;
margin-left: 15px;
border-right-style: solid;
border-right-color: black;
border-right-width: 3px;
font-size: 200%;
}
#secondthingy {
float: right;
text-align:left;
width:45%;
}
use a <div class="wrapper"></div> and fix a width to it.
then put two <div class="column"></div> into that that are float: left and have those two columns set to 50% of the wrapper.
then put your text into each of the columns.
I believe this is what you were attempting to do. if not, please elaborate.
Absolutely.
#secondthingy {
left:50%;
position:absolute;
}
You can remove the 2 extra margin values on #firstcolumn to get the desired result:
#firstcolumn {
float: left;
margin-left: 15px;
border-right-style: solid;
border-right-color: black;
border-right-width: 3px;
font-size: 200%;
}
#secondthingy {
float: right;
}
I think the margining was taking up too much space and causing the h2 to be pushed down a line.