How to arrange floating elements vertically - javascript

I have 3 fieldsets.
What I would like to make is this layout:
I want the bottom right fieldset to be bottom aligned, so it's bottom would be aligned with the left fieldset.
It should work in different resolutions.
Is there an easy way? or I will have to use javascript to add to it a margin-top dynamically?
code:
<div class="fieldSetsContainer">
<fieldset class="leftFieldSet">test
<br/>test
<br/>test
<br/>test
<br/>test
<br/>test
<br/>
</fieldset>
<div class="rightFieldSets">
<fieldset>test2</fieldset>
<fieldset class="bottomRightFieldSet">test3</fieldset>
</div>
css:
.rightFieldSets {
float:left;
width:34%;
}
.rightFieldSets fieldset {
clear:left;
width:89%;
}
.leftFieldSet {
width:62%;
float:left;
margin-right:1px;
}
.bottomRightFieldSet {
margin-top:6px;
}
here is the a link:
http://jsfiddle.net/bbryK/

My solution assumes two things:
The right column has a fixed width.
The left column must always be the highest.
See http://jsfiddle.net/c3AFP/2/
Html structure:
<div class="container">
<div class="right">
<fieldset class="top"></fieldset>
<fieldset class="bottom"></fieldset>
</div>
<fieldset class="left"></fieldset>
</div>
Css styles:
.container {
position: relative;
}
.top, .bottom {
width: 300px;
}
.left {
margin-right: 300px;
}
.right {
float: right;
margin-left: 10px;
}
.bottom {
position: absolute;
bottom: 0;
}
EDIT:
Here is a solution with the right column sized by percentage: http://jsfiddle.net/c3AFP/5/
EDIT 2:
Here is a table based solution which removes the requirement of the left column being the tallest. Using vertical-align you can adjust where the smaller elements should align in relation to the tallest one: http://jsfiddle.net/c3AFP/7/

I'm giving you a start point on fiddle. Please play around, make some code and do share the same.
http://jsfiddle.net/vY462/
#one{width:200px;height:70px;border:2px solid black;float:left;}
#two,#three{width:200px;height:25px;border:2px solid black;float:right;margin-top:5px;}
<div id="one">1</div>
<div id="two">2</div>
<div id="three">3</div>

Related

CSS only scroll middle container while there are still items in it

I want to create a web page to show a list of doctors. I should call fetch to get an array of doctors with js, and then put them on my page. for instance, see this website (it is in the Persian language, but as you can guess, the middle container are doctors and there's one class for each doctor). I have two problems with styling the page when the object array is ready:
1st: How can I mimic this? I mean, while there are still doctors on the list, I want that the middle container is scrolled and left and the top container to stay right there. But when doctors are finished (at the end of the list), the user is able to scroll and see the rest of the page.
The site I want to mimic
As you can see in my webpage schematic, I want to implement the doctors div in a way that until there are more doctor classes to be seen, the doctors div will scroll. Only when the scrolling down is finished the user is able to scroll down to the next section, or vice versa, when he wants to scroll up, he should be able to do so when he has scrolled up to the top to see the previous section.
My second issue is a minor one. I'm not sure How to set the height of the doctors div because there could be an unknown number of doctors classes (each for one doctor) so the solution must also handle the unknown number of items to be placed in the doctors div (only after I fetched the doctors using the API would I be able to know the number of items to put in the doctors div)
Thanks.
I looked at the website you shared. You can do something like this.
Link: https://codepen.io/en0ndev/pen/RwGOgMX
header {
text-align:center;
padding:5pt;
background:black;
color:#fff;
}
footer {
text-align:center;
padding:5pt;
background:black;
color:#fff;
}
.main-div {
display:flex;
}
.left-div {
flex: 0 0 50%;
max-width:50%;
background:red;
display:inline-block;
max-height:200px;
overflow-y:scroll;
}
.right-div {
flex: 0 0 50%;
max-width:50%;
background:blue;
display:inline-block;
height:200px;
}
.doctor {
display:block;
color:white;
padding:5pt;
}
.menu {
display:block;
color:white;
padding:5pt;
}
<header>
Header
</header>
<div class="main-div">
<div class="left-div">
<div class="doctor">Doctor1</div>
<div class="doctor">Doctor2</div>
<div class="doctor">Doctor3</div>
<div class="doctor">Doctor4</div>
<div class="doctor">Doctor5</div>
<div class="doctor">Doctor6</div>
<div class="doctor">Doctor7</div>
<div class="doctor">Doctor8</div>
<div class="doctor">Doctor9</div>
<div class="doctor">Doctor10</div>
</div>
<div class="right-div">
<div class="menu">Menu1</div>
<div class="menu">Menu2</div>
<div class="menu">Menu3</div>
<div class="menu">Menu4</div>
<div class="menu">Menu5</div>
<div class="menu">Menu6</div>
</div>
</div>
<footer>
Footer
</footer>
It's not a perfect clean code but it'll give you the idea of how to do it. in your provided example the side column has a sticky position with a top:0; which stops it from scrolling while the rest of the page is scrollable. so i tried to make something like that as a simple how to.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
main {
background-color: #333;
height: 70rem;
width: 20rem;
}
.top {
background-color: yellow;
width: 100%;
height: 5rem;
}
.doctors {
display: inline-block;
background-color: green;
width: 80%;
height: 30rem;
}
.right-col {
float: right;
position: sticky;
top: 0;
display: inline-block;
background-color: red;
width: 20%;
height: 10rem;
}
<main>
<div>
<nav class="top"></nav>
<section class="doctors"></section>
<aside class="right-col"></aside>
</div>
</main>

CSS move element when hovering on previous div [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to make a site that uses a "grid" that looks just like the one on www.uve.info/en/ (middle of the page, under "Services") and has the same effect while hovering.
I've made divs with classes "black-cell", "grey-cell" and "white-cell" and ordered them the same way they did. White cells have a negative z-index and are moved left (odd rows) or right (even rows) by 33%. That way, they stay invisible under grey or black cells.
It's easy to get the desired result on odd rows:
.grey-cell:hover + .odd
visibility: visible
right: 0
, but the problem arises when I try to do the same thing with white cells in even rows because the HTML structure is different (white cell - black cell - grey cell) and I can't target the previous div.
Unfortunately, I can't use flexbox to change the order of elements due to some reasons that are not important for this topic. I've tried using jquery function "insertBefore", but it changes the HTML structure and doesn't help here.
So, is there a way to change the order of the elements without flexbox, OR to target the previous div with CSS/SASS?
In the site you're refering to, the structure seems to be the same for the two types of effects (move to the left & move to the right).
<div class="item [...]">
<div class="col [...]">[...]</div>
<div class="col [...]">[...]</div>
<div class="col-hover">[...]</div>
</div>
Actually, you can see that for the "Cycle hire" effect (2nd one), there is another "indent" class for the main container of the row (class "item").
<div class="item indent [...]">[same structure as above]</div>
It looks like this class is driving the animation to the left when it's written.
Then, if you take the element having class "col-hover", it's displayed "absolute" and positioned at left:50% inside the class "item".
.item .col-hover {
left: 50%;
}
But, for "item" and "indent", it's overwritten to be at left: 0.
That way, the element is positioned under the central block, which is the second for a transition to the right, and the first for moving to the left.
So when "item" is hovered, "col-hover" goes to the right :
.item:hover col-hover {
left: 100%;
}
But if the element which has the "item" class also has "indent" class, then the "col-hover" goes to left:-50% (to the left)
.item:hover.indent .col-hover {
left: -50%;
}
So you can keep the same structure and play with absolute position for the element you want to move.
I suppose you have noted the transition on "col-hover" for the animation, changing the left property making the element moving.
Hope this helps !
Please mind the code its a little dirty clean it but it works like you want.
<html>
<head>
<style type="text/css">
.box
{
width:200px;
height:200px;
background:rgba(0,0,0,120);
margin:0 auto;
color:White;
}
.big-box
{
height:200px;
width:600px;
color:White;
position:absolute;
border:1px solid black;
z-index:-1;
-webkit-transition:all 0.3s;
}
.big-box1
{
top:0px;
left:-200px;
text-align:right;
}
.big-box2
{
top:200px;
left:200px;
text-align:left;
}
.big-box > .box
{
display:inline-block;
}
.par
{
position:relative;
height:400px;
width:600px;
margin:0 auto;
border:1px solid black;
overflow:visible;
}
.b1:hover~.big-box1
{
left:0px;
}
.b2:hover~.big-box2
{
left:0px;
}
</style>
</head>
<body>
<div class="par">
<div class="box b1">One</div>
<div class="box b2">Two</div>
<div class="big-box big-box1">
<div class="box">OneC</div>
</div>
<div class="big-box big-box2">
<div class="box">TwoC</div>
</div>
</div>
</body>
</html>
Was messing around with this question for a warm up, it's not fully thought through but I'll post in case some of it helps.
fiddle
https://jsfiddle.net/Hastig/7Lb427m4/2/
css
.blocks-wrapper {
font-size: 0;
margin-bottom: 10px;
position: relative;
text-align: center;
}
.block {
display: inline-block;
height: 200px; width: 200px;
}
.hidey {
font-size: 15px;
z-index: -1;
color: red;
position: absolute;
left: 50%;
top: 50%; bottom: 50%;
transition: all 1s ease;
}
.blocks-wrapper:nth-child(odd) .block:nth-child(1) { }
.blocks-wrapper:nth-child(odd) .block:nth-child(2) { background-color: #222; }
.blocks-wrapper:nth-child(odd) .block:nth-child(3) { background-color: #111; }
.blocks-wrapper:nth-child(even) .block:nth-child(1) { background-color: #111; }
.blocks-wrapper:nth-child(even) .block:nth-child(2) { background-color: #222; }
.blocks-wrapper:nth-child(even) .block:nth-child(3) { }
.blocks-wrapper:nth-child(odd) .block:nth-child(2):hover ~ .hidey,
.blocks-wrapper:nth-child(odd) .block:nth-child(3):hover ~ .hidey {
left: 15%;
}
.blocks-wrapper:nth-child(even) .block:nth-child(1):hover ~ .hidey,
.blocks-wrapper:nth-child(even) .block:nth-child(2):hover ~ .hidey {
left: 75%;
}
html
<div class="blocks-wrapper">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="hidey">testerer</div>
</div><!-- end blocks-wrapper -->
<div class="blocks-wrapper">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="hidey">testerer</div>
</div><!-- end blocks-wrapper -->
Have tried using the previous sibling selector ~
.grey-cell:hover ~ .even{
visibility: visible;
left: 0;
}

Form element container heights

I'm building a form manager for my framework and want to add methods to create form elements based on parameters passed. Each "element container" has the following:
A validation row positioned at the top of the container. This row is turned off by default (display: none) and will only show if a javascript validation error occured.
A label container (situated on the left)
A form control container (situated on the right)
Here is a sample HTML:
<div class='control_container'>
<div class='validation'></div>
<div class='label_container'>
<label for=''>Label</label>
</div>
<div class='elements_container'>
<div class='element'>
<input type='text' name='' value='' />
</div>
</div>
</div>
My issue here is that I need to the control_container to seperate label and elements containers but also need the label_container and element_container to both have the same height irrespective of the content. These 2 containers may have different background colours so I need to ensure that the stretch to the bottom of the control_container and also keep in consideration that the validation div might show (so using position: absolute and top: 0 might not work).
I have tried the following:
Giving control_container a relative position and the 2 seperate containers both a position absolute. As the height of the containers would mostly be dictated by the height of the label (if the label is multiple lines or if the element_container has multiple elements within it this option does not work.
Floats (There I say more? :D)
I would prefer a CSS solution which is compatible with most browsers (including IE8 (am I pushing it to ask for IE7 haha)
Any ideas?
** ADDITIONAL INFORMATION **
I want the layout to look something like this:
--------------------- control_container ---------------------
[Potential validation message (this will be toggled on/off) ]
[label_container][ elements_container ]
------------------- end of control_container ----------------
So label_container (with the label) and elements_container (with it's elements) will be next to eachother. These 2 containers may have different background colours so they should both stretch (height) according to the biggest element. The only issue I see here is validation element which wont show by default so using absolute positioning might not work as the validation message might take the top area and have the elements overlap eachother.
HTML:
<div class="controls">
<div class="message">Test</div>
<div class="label_container">
<label for="">Label Label Label Label Label Label Label Label Label Label Label Label Label Label Label Label </label>
</div>
<div class="elements_container">
<div class="element">
<input type="text" name="test" value="" />
</div>
</div>
</div>
CSS:
.controls {
position: relative;
display: table;
width: 100%;
}
.controls .message {
background: red;
padding: 5px;
color: #FFF;
font-weight: bold;
height: 30px;
width: 100%;
display: table-caption;
box-sizing: border-box;
}
.controls .label_container {
display: table-cell;
background: #D3D3D3;
width: 150px;
height: 100%;
margin-top: 30px;
}
.controls .elements_container {
display: table-cell;
background: #A2A7DD;
color: #000;
width: 650px;
height: 100%;
margin-top: 30px;
margin-left: 150px;
}
All of them here in jsFiddle: Demo

Toggle display:none with div in front of another div?

I'm trying to make a div that I have on top of another div show up when you click on something.
This is the code for the two divs, without all the stuff that's within each:
<div id="randomarticle_enlarge">
<h1></h1>
<h4></h4>
<p></p>
<p></p>
</div>
<div class="bodybag">
<h1></h1>
<h4></h4>
<p></p>
<p></p>
</div>
Then I have css for each, of course:
.bodybag {
width:960px;
}
#randomarticle_englarge {
height:750px;
width:960px;
position:absolute;
z-index:2;
margin-top:1px;
padding-left:20px;
padding-right:20px;
display: none;
}
Am I supposed to have the bodybag class have a z-index and a position:relative? Because even though I don't it's working (at this point).
Anyway, I have this script written that's doing exactly what I want it to do:
$(document).ready(function() {
$('.popular').click(function() {
$('#textmask').fadeTo( 'fast', 0.1);
$('#backgroundmask').css('background-color', 'white');
});
});
And all I want to happen next is that as the textmask and the backgroundmask fade in/change as they should and do, is for the randomarticle_enlarge div to show up.
I've tried using .toggle and .toggleClass and .slideToggle and .show but nothing is working.
Absolute positioning must be relative to a container. In order to absolutely position something you need to indicate what it's absolutely positioned to. Something along these lines.
<div id="randomarticle_englargeContainer">
<div id="randomarticle_englarge">
</div>
<div class="bodybag">
</div>
</div>
#randomarticle_englargeContainer {
position: relative;
}
.bodybag {
position: absolute;
left: 0;
top: 0;
}
When copying everything from above I have no issues using $('#randomarticle_englarge').toggle();. Check your browser's console for errors; you might find the answers there.
I'm not exactly sure about what would you like to do with the divs, but I created an example for you, maybe this is what you want:
LIVE DEMO
So there is two divs. The 2nd div covers the 1st one. Clicking on a 'button' hides the 2nd div, so the 1st one reveals. Clicking again the 'button', the 2nd div appears and covers the 1st one again.
HTML:
<div class="popular">Click me!</div>
<div class="container">
<div id="randomarticle_enlarge">
<h1>A</h1>
<h4>B</h4>
<p>C</p>
<p>D</p>
</div>
<div class="bodybag">
<h1>E</h1>
<h4>F</h4>
<p>G</p>
<p>H</p>
</div>
</div>
CSS:
.container {
position: relative;
}
.bodybag {
width: 100px;
height: 200px;
background-color: red;
}
#randomarticle_enlarge {
width: 100px;
height: 200px;
background-color: green;
position: absolute;
top: 0;
left: 0;
}
.hide {
display: none;
}
jQuery:
$(document).ready(function() {
$('.popular').click(function() {
$('#randomarticle_enlarge').toggleClass('hide');
});
});

Jquery animation help

Is it possible to animate two divs widths at the same time (one increasing, one decreasing) so that the parent containers overall width remains exactly the same.
As an example, a container div contains 5 child divs. Teh container div is 1000px wide and 4 of the child divs are 150px wide and another is 400px. I want to be able to animate the 400px div down to 150px and one of the 150px divs up to 400px;
The problem I am getting is that the parent container shrinks and expands as the animation completes - and it happens noticeable.
I am not looking for a plugin or anything for this, simply some advice on the best way of achieving this.
Many thanks in advance for any help.
EDIT:
The main problem is that every div on the right of the one being animated gets pulled to the left and then sent back out when complete.
Here is the code I am using
<style type='text/css'>
.panel-wrapper {
width: 954px;
height: 372px;
background-color: #fff;
position: relative;
overflow: hidden;
}
.panel-wrapper .panel {
margin-right: 1px;
height: 100%;
width: 64px;
float: left;
background-color: #cacaca;
}
#home-panel {
width: 359px;
}
.panel.last {
margin-right: 0;
}
</style>
<script type='text/javascript'>
//<![CDATA[
jQuery(document).ready(function() {
jQuery('.panel').mouseenter(function() {
jQuery('.panel-wrapper .open').stop().animate({width:"64px"},400, 'linear');
jQuery('.panel-wrapper .open').removeClass('open');
jQuery(this).addClass('open');
jQuery(this).stop().animate({width:"359px"},400, 'linear');
});
});
//]]>
</script>
<div class='panel-wrapper'>
<div id='home-panel' class='panel open'>
</div>
<div class='panel'>
</div>
<div class='panel'>
</div>
<div class='panel'>
</div>
<div class='panel'>
</div>
<div class='panel'>
</div>
<div class='panel'>
</div>
<div class='panel last'>
</div>
</div>
Set the parent height to a fixed number of pixels will keep it from shrinking or expanding.
Include an empty div of 1000px width after the divs you want to antimate. That should keep the wrapper div from shrinking.

Categories

Resources