I have the following html:
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
<div id="div4"></div>
<div id="div5"></div>
<div id="div6"></div>
The output would be displayed as:
Div 1 Div 2
Div 3 Div 4
Div 5 Div 6
Given some information on page load Div 1 or Div 2 may be hidden. If Div 1 is hidden I want to move Div 2 to the placeholder for Div 1 and move Div 5 to the placeholder for Div 2. I always want Div 3 and Div 4 on the same line. Currently if I hide a div the next one moves up in its place causing Div 3 and Div 4 to be on two different lines. I have researched AngularJS and can't find a way to do this? Any thoughts?
UPDATE
<div id="placeholder1"></div> <div id="placeholder2"></div>
<div id="placeholder3"></div> <div id="placeholder4"></div>
<div id="placeholder5"></div> <div id="placeholder6"></div>
<div id="memid">Member ID</div> <div id="otherid">Other ID</div>
<div id="fName">First Name</div> <div id="lName">Last Name</div>
<div id="dob">DOB</div> <div id="otherInfo">Other Info</div>
Given the site the member id or other id may be hidden and I would like to move DOB to placeholder2 and OtherID to placeholder1 or leave member id in placeholder1 while keeping first and last name on the same row. I am also using bootstrap grid for the layout.
i dont understand, where is needed angular. The problem could be solved only with css:
div{
float:left;
width:50%;
}
Your best bet is likely going to be to use javascript to handle this. You can do this without Angular, though. You could manually move the elements around within the set of nodes containing the six divs. You could also try taking the html content from one div and moving it to another.
if (/*condition that hides div1*/){
Div1.html(Div2.html());
Div2.html(Div5.html());
Div5.hide();
}
You could also try applying css classes that manually place the elements on the page.
Related
I want to create a faq page like Twitter's FAQ. The left column stays on that position even though the user keep scrolling.
So far here's what I made but it doesn't work.
<template>
<div>header here</div>
<div class="container">
<div class="row">
<div class="col-lg-4">
<div style="position: sticky;">
1 of 2
</div>
</div>
<div class="col-lg-8">
2 of 2
</div>
</div>
</div>
</template>
According to this, we should add sticky property, but it doesn't work.
edit: I think it's because the two columns have the same height, so adding sticky property does not work. Any solutions on how to make the column height fit to the content only?
Any solution? Thank you!!
Position Sticky is not working on col-sm-4 because its parent class row has display:flex property. if you change
display:flex
to
display:block
then position Sticky property will work but it will change your design
I'm using the Bootstrap 3 grid to hide/show nav bar content based on whether or not the user is using an extra small device.
I'm using .hidden-xs and .visible-xs classes. These classes appropriately hide/show the content, but I'm running into two problems:
(1) Hiding the content also shrinks the column spacing by .col-xs-5 because the div is hidden. I tried adding .visible-xs to a subsequent div and using .col-xs-5 to make up the empty space. This works, but only if I place content inside the divs. I just want the columns to be spaced out.
(2) On XS view size, the final item on the Nav bar "Nav" jumps to the next row. I have only accounted for 12 total columns.
See this JSFiddle. I'm trying to nly show "Welcome" on large view and show nothing on XS view.
I here's an idea, you can try instead of adding content. This CSS trick uses :before and :after CSS pseudo-classes.
.no_content {
display: block;
content: "";
width: 151px;
height: 35px;
background: transparent url(tape.png) 0 0 no-repeat;
}
<div class="no_content"></div>
I would look at the grid system further. I believe there is an offset that you can use to offset the div like this:
<div class="row">
<div class="col-xs-5 col-xs-offset-5></div>
<div class="col-xs-2></div>
</div>
Use the pull-right bootstrap class instead of trying to make empty div's fill in the space.
Completely remove the div you added in item (1) to "make up the space". On the div containing "Nav" set the class as pull-right col-xs-1. So the code from your JSFiddle becomes:
<div class="container">
<div class="row" id="header">
<div class="col-xs-5" id="brand-wrapper">
<div class="brand">Brand</div>
</div>
<!-- Hidden on XS Devices -->
<div class="hidden-xs col-xs-5">
<p>
Welcome
</p>
</div>
<!-- Nav -->
<div class="pull-right col-xs-1" id="toggle-wrapper">
<p>Nav</p>
</div>
</div>
</div>
I'm trying to design a layout, on which I want to put one div into another. But, the problem is link of the back div is not working.
<div id="container" style="z-index:-10;position:relative;height:100px">
StackOverflow1
</div>
<div id="container1" style="margin-top:10px">
StackOverflow1
</div>
which means, if I'm trying to access link of div id container, then I can't. How to solve this problem.
Note : I can't remove z-index, because I want container1 above of container
Parse has got it right.
Without knowing what context you are using it in, just remove z-index:-10 or change it to a positive value like z-index:1;.
<div id="container" style="position:relative;height:100px;">
StackOverflow1
</div>
<div id="container1" style="margin-top:10px;">
StackOverflow1
</div>
Edit:
I just realised that you said that you wanted to put one div into another. That would be done like this:
<div id="container" style="z-index:1;position:relative;height:100px;background-color:#eee;">
StackOverflow1
<div id="container1" style="margin-top:10px;background-color:#ddd;">
StackOverflow1
</div>
</div>
I put some background-color on the divs to make it clearer.
The answer is, you can't. Because the parent container already been set to z-index:-10, so the child can't have the z-index value higher than that. Maybe you can try change a bit the markup like this one, since you have applied position:relative at the container div there
StackOverflow1
<div id="container" style="z-index:-10;position:relative;height:100px"></div>
<div id="container1" style="margin-top:10px">
StackOverflow1
</div>
Add position:absolute, so the link act like it is inside the parent container with the lower z-index and of course it is accessible. You can see your updated jsfiddle here http://jsfiddle.net/gyheE/2/
I have this html file
<div class="con" style="width:100px;height:200px;">
1
</div>
<div class="con" style="width:100px;height:200px;">
2
</div>
<div class="con" style="width:100px;height:400px;">
3
</div>
<div class="con" style="width:100px;height:400px;">
4
</div>
<div class="con" style="width:100px;height:100px;">
5
</div>
<div class="con" style="width:100px;height:100px;">
6
</div>
<div class="con" style="width:100px;height:100px;">
7
</div>
<div class="con" style="width:100px;height:100px;">
8
</div>
And I want with this html have this result :
But I write this css :
<style>
body {
width:440px;
height:440px;
}
.con{
float:left;
background:#bebebe;
margin:1px;
}
</style>
And I got this result! :-(
I repeat that I would have the result of the first image using only the html code that I wrote.
change the width of the body to 408px; then float:right; the div 3 & 4.
demo: http://jsbin.com/imire5
Updated demo with float left only: http://jsbin.com/imire5/2
Firstly, you shouldn't have multiple items with the same id. This is what class is for. id should be unique within the page.
The solution is to your problem is to float the two tall blocks to the right and everything else to the left.
This will of course only work if the boxes are in a container (ie the body) that is just the right width for all four, otherwise you'll just end up with a gap in the middle of your layout.
The trouble is that because you've got the same ID for everything, you can't easily specify which ones to float right and which ones to float left.
There are ways to do it, but the correct solution would be to use classes.
<div class="con" style="width:100px;height:200px;">
1
</div>
<div class="con" style="width:100px;height:200px;">
2
</div>
<div class="con tall" style="width:100px;height:400px;">
3
</div>
<div class="con tall" style="width:100px;height:400px;">
4
</div>
<div class="con" style="width:100px;height:100px;">
5
</div>
<div class="con" style="width:100px;height:100px;">
6
</div>
<div class="con" style="width:100px;height:100px;">
7
</div>
<div class="con" style="width:100px;height:100px;">
8
</div>
<style>
body {
width:408px;
height:440px;
}
.con {
float:left;
background:#bebebe;
margin:1px;
}
.tall {
float:right;
}
</style>
If you absolutely cannot (or will not) change the HTML code, there is still one other solution I could suggest - the CSS [attr] selector will allow you to specify a different CSS style for elements that have particular attributes. In this case, you could use it to pick out the tall blocks and float them right.
#con[style~='height:400px;'] {float:right;}
This will only affect the elements that have id="con" and where the style attribute includes height:400px;.
However please note that the [attr] selector does not work on older version of IE, so you may need to excersise caution if you decide to use it.
This solution also involves floating certain elements to the right, which you seem to be dead set against, but it is still the only viable CSS-only solution.
The basic issue you have is that CSS float works in a way that is different to how you want it to work.
Another answer to your problem might be to use Javascript to hack it.
There is a jQuery plug-in called Masonry which looks like it does what you're after. You can use float:left; for everything, and then use Masonry to close up the gaps.
It would mean relying on a solution that isn't entirely CSS-based though, which probably isn't ideal - especially since I've already given you a working CSS-only solution.
(also once you start using Javascript, you definitely need to fix your id vs class problem -- Javascript will disown you if you have all those elements with the same id)
I have a container div, inside which I want to pack a variable number of divs of unknown (variable) height but with a given min-width. My requirements are:
If the container is wide enough to accommodate two columns, I want them to distribute themselves nicely in two columns without unnecessary whitespace.
It not, they should just go above each other.
Currently, I've given the divs width:48% margin-right:2%;float:left; which works nicely in the one-column state but when I resize the browser window, making room for two columns, every div which ends up in the left column insists on aligning itself horizontally with the bottom of the last div which went to the right:
what I have http://img602.imageshack.us/img602/5719/whatihave.png
This is how I would like them to go (no wasted space):
what I want http://img96.imageshack.us/img96/6985/whatiwantu.png
I would like a pure CSS solution if possible.
Thank you! /Gustav
EDIT:
This markup illustrates my problem:
<html>
<head>
<style type="text/css">
.box {
width: 48%;
min-width:550px;
margin-right:2%;
margin-bottom: 1.5em;
background:blue;
color:white;
height:180px;
float:left;
}
.tall {
height: 250px;
}
</style>
</head>
<body>
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<div class="box tall">4</div>
<div class="box">5</div>
<div class="box">6</div>
<div style="clear:both"/>
</body>
</html>
The .boxes are generated dynamically, and so are their heights, I just threw in one taller to illustrate.
I don't think you can achieve the desired effect with pure CSS. I've used jQuery Masonry to replicate the effect you're after and it worked really well.
I'd love to see a pure CSS solution for this but haven't seen anything come close yet.
I believe that if you have a div for each column into which you put the numbered divs you will get what you want. Something like this:
<div class="containerDiv">
<div class="column">
<div class="content">
1
</div>
<div class="content">
4
</div>
</div>
<div class="column">
<div class="content">
2
</div>
<div class="content">
3
</div>
</div>
</div>
The next step appears to be "how do I balance my columns". Some code somewhere is generating the boxes you mentioned. It is deciding on the height of each box. This code will need to generate a balanced list of boxes for each column prior to forwarding the request to the JSP for presentation. By balanced, I mean "the height of column1 is similar to the height to column2"