Aligning two divs next to each other with scrollable feature - html

I started to learn HTML / CSS and I am having a problem with aligning two divs in a scrollable div. For better understanding I am going to share my code. If someone can help me I am going to be really grateful. Thank you in advance.
The idea is every "Test" class to have 100% width and to be aligned one after another in a row while the class "Box" have a scrollable feature.
.Wrapper{
position:relative;
width:90vw;
background-color:blue;
}
.Box{
display;
position:relative;
width:100%
overflow-x:scroll;
}
.Test{
width:100%;
background-color:red;
}
<div class="Wrapper">
<div class="Box">
<div class="Test">
Test 1
</div>
<div class="Test">
Test 2
</div>
</div>
</div>
Best regards,
George S.

I'm not sure if I understood you correctly, but this is one solution to achieve it. This solution forces every child element of box to be in one row (white-space: nowrap), if it is an inline or inline-block element. Here is a jsFiddle: https://jsfiddle.net/rq98w432/1/
HTML:
<div class="Box">
<div class="Test">
Test 1
</div>
<div class="Test">
Test 2
</div>
</div>
CSS:
.Box{
width:90vw;
background-color:blue;
white-space: nowrap;
overflow-x:scroll;
color: white;
padding: 10px;
}
.Test {
display: inline-block;
width: 100%;
}

Related

CSS Layout: One side scrolls, other side sets height

It seems like it should be simple, but I'm having trouble achieving this layout. It's a set of two columns using CSS display:table-cell. The right column has a responsive image that should set the height for both. The left column has text that should scroll if needed. Please see the JSFiddle: http://jsfiddle.net/xThB7/
<div class="details-wrap">
<div class="details">
<div class="scroll">
Lorem ipsum
</div>
</div>
<div class="details-image">
<img src="http://lorempixel.com/output/city-q-c-640-480-6.jpg" />
</div>
</div>
I'm open to any solutions, although I'd like to avoid using JS
You just need to add height: 100% to .details and .scroll class:
.details {
display:table-cell;
vertical-align:top;
width:50%;
background:#ccc;
line-height:1.5em;
height: 100%;
}
.scroll {
padding:15px;
overflow:auto;
height: 100%;
}
fiddle: http://jsfiddle.net/xThB7/2/

aligning nested div's left and right inside container

I am trying to create a div which is as wide as the page and has two div's inside it, one which is aligned left and one aligned right. Its' turning out to be a lot more difficult than I expected. With the code below, both div's align left. I have made a jsFidle to demonstrate the problem. Thanks for reading.
<style>
#container{
border:1px solid;
}
#left{
text-align:left;
border:1px solid red;
display:table-cell;
}
#right{
text-align:right;
border:1px solid blue;
display:table-cell;
}
</style>
<body>
<div id = "container">
<div id = "left">far left</div>
<div id = "right">far right</div>
</div>
</body>
There's no need to use floating elements or absolute positioning in general for something like this.
It's an approach that should've stopped along with using tables for general layouts.
Sample Jsfiddle
CSS:
#container {
display: table;
width: 100%;
}
#container > div {
display: table-cell;
}
.right {
text-align: right;
}
HTML:
<div id="container">
<div>
<p>Left</p>
</div>
<div class="right">
<p>Right</p>
</div>
</div>
You need to use
float: left
and
float: right
on the divs.
A cooler way of aligning things is to use
display:flex
on the container, but you'll have to check the browser compatibility for that I'm afraid.

Using CSS, how do I keep a "frame" centered, and align things within the frame

On the webpage, I would like to create a virtual frame (centered about the page) and be able to align elements (e.g images, text, etc) within the frame using CSS properties.
Since a picture is worth a thousand words, this is what I mean:
I'd want to be able to align "Text1" to the left with respect to the virtual frame which is kept centered about the webpage. Similar idea with "CenteredText" and the blue box being aligned to the right relative to the frame.
I'd really appreciate suggestions on how I'd be able to do this.
This may help you:
HTML:
<div class="frame">
<div>Text1</div>
<div class="centered">Centered text</div>
<div class="box"></div>
<div class="clr"></div>
</div>
CSS:
.frame{width:80%; margin:0 auto; border:1px solid #444; height:500px}
.centered{text-align:center}
.box{background:blue; height:50px; width:50px; border:2px solid black; float:right}
.clr{clear:both}
jsfiddle: http://jsfiddle.net/ashishanexpert/fqaDQ/
margin: 0 auto;
in your css.
You need a div with a class or id you can attack to and then give it the above property.
This will centre the div in the page.
<body>
<div id="wrapper">
<div id="left">left</div>
<div id="centered">centre</div>
<div id="right">right</div>
</div> <!--close wrapper-->
css:
#wrapper{
margin: 0 auto;
width: 960px;
position: relative;
}
#left{
float: left;
}
#right{
float: right;
}
Good luck!

Inline display of divs with child overlapped divs

I'm a noob, trying everyday to learn more about CSS (even though I'm clumsy and "not a natural", my brain steams out like an old computer). I want to find out how to code a set of independent modules which share the same style and are displayed inline in two rows of two columns. I want to recreate a paper stack for each module, using z-index and absolute positioning for it.
I made this image to show what I'm looking for:
I tried display:inline for the top div - but this way, I had to code individual overlapped divs for each module, using position:absolute and coordinates. What would be most desirable is that a single module+overlap could be repeated, using the same class (without having to change each module's overlapped div coordinates).
Does anyone have an idea about how to do this using CSS? Thank you in advance :)
Yes, you could do the following. You'll want to resize to whichever dimensions serve you best. JSfiddle here: http://jsfiddle.net/CNPJ9/2/
<div class="contain">
<div class="box">
<h1>A</h1>
</div>
<div class="behind"></div>
</div>
<div class="contain">
<div class="box">
<h1>B</h1>
</div>
<div class="behind"></div>
</div>
<div class="contain">
<div class="box">
<h1>C</h1>
</div>
<div class="behind"></div>
</div>
<div class="contain">
<div class="box">
<h1>D</h1>
</div>
<div class="behind"></div>
</div>
.contain {
margin:25px 25px;
float:left;
}
.box h1 {
font: 8em normal Futura, sans-serif;
text-align:center;
color:#f1f1f1;
}
.box {
width:400px;
height:300px;
background:#000;
z-index:1;
float:left;
position:absbolute;
}
.behind {
width:350px;
height:325px;
margin-left:25px;
background:#333;
z-index:2;
}
Something like this may help you.
Fiddle
.abc{
width=300px;
height:200px;
margin:50px;
border:solid 2px black;
border-bottom: 5px double blue;
}

Positioning 3 divs such that they appear as if placed inside a table row of 3 columns

Previously, I was using <table> to split up my page layout into 3 parts, the left sidebar, right sidebar & the main centre panel. Now, after having learnt the disadvantages of overusing/misusing <table>, I want to avoid using tables for this purpose & I am looking to style these 3 divs in such a way that they look like 3 columns of a <table> row.
Any inputs on how I can achieve the 3 divs in same row, would be highly appreciated.
Currently my all the three div s are shown in linearized fashion, one after another.
Maybe something easier, what about:
HTML:
<div id="main">
<div>content</div>
<div>content</div>
<div>content</div>
</div>
CSS:
#main{
margin: 0 auto 0 auto;
width: 960px; /*just an example*/
}
#main div{
float: left;
width: 320px; /* a third of the main width*/
}
I hope this will help you.
Typically sidebars have fixed width and the middel content area takes up the rest of the space. Considering that, here's the best approach:
<style>
#left {
width:200px;
float:left;
} #right {
width:200px;
float:right;
} #main {
margin:0px 200px;
}
</style>
<div id="container">
<div id="left">content</div>
<div id="right">content</div>
<div id="main">content</div>
</div>
Resize the window and all is well.
Working JSFIDDLE: http://jsfiddle.net/7ayqe/
Give them "float:left" properties and corresponding width to make it the size you want.
Example (I know these are inline styles, used for demonstration purposes only):
<div id="left-sidebar" style="width:30%;float:left"><!--Left Sidebar--></div>
<div id="content" style="width:50%;float:left"><!--Content--></div>
<div id="right-sidebar" style="width:20%;float:left"><!--Right Sidebar--></div>
Something like this should get you started:
<div>
<div class="column">column one</div>
<div class="column">column two</div>
<div class="column">column three</div>
<div class="last"></div>
</div>
.column { float: left; padding: 5px }
.last { clear: left}
Here is a live example
<div class="col1"></div>
<div class="col2"></div>
<div class="col3"></div>
<div class="clear"></div>
CSS:
.col1 {
float:left;
width:250px;
}
.col2 {
float:left;
width:600px;
}
.col3 {
float:left;
width:20px;
}
.clear {
clear:both;
}