Scroll floating div inside main div - css

I am working on responsive design. I have div (WebPage_NavigationWrapper) and inside I have floating-left divs (function_block). Now I want to scroll bar in case floating divs cannot adjust in single line; meaning main div height remain same. Due to responsive design I am not using PX so I believe I am not providing height of div, unless I am wrong!
<div id="WebPage_NavigationWrapper" class="TitleHeaderBar_Style_L2">
<div class="function_block">
New-Award
</div>
<div class="function_block">
New-Award
</div>
<div class="function_block">
New-Award
</div>
<div class="function_block">
New-Award
</div>
</div>
</div>
CSS
#WebPage_NavigationWrapper{
display: table;
table-layout: fixed;
width:100%;
padding:10px;
overflow-x: scroll;
}
.function_block{
float:left;
padding:2px;
width:120px;
height:60px;
}
.function_block:hover{
background-color:#CDE5F2;
}
.CreateNewEntry_Icon{
margin-left:10px;
width:85px;
line-height:5;
display:inline-block;
background:url("../ImagesAndIcons/Icons/Add_New.png") no-repeat top center;
}

i think this will help you,
replace your code with following
#WebPage_NavigationWrapper{
width:400px;
height: 100px;
padding:10px;
overflow-x: scroll;
overflow-y: hidden;
border: 1px solid black;
}
.function_block{
display: table-cell;
padding:2px;
width:120px;
height:60px;
}

Related

overflow-x prevents overflow-y on top of container

Of course I realize that this question has been asked, and I'd thought I had the solution with this: https://stackoverflow.com/a/15971409/295133
But that answer only allows content overflow at the bottom, not at the top.
See this example (http://jsfiddle.net/7y2cb/251/):
.wrapper{
width: 400px;
height: 200px;
border: 2px solid red;
position:relative;
top:200px;
}
.inner{
max-width: 100%;
overflow-x: hidden;
border:1px blue solid;
}
.example{
width:600px;
height:500px;
background:green;
position:relative;
left:100px;
top:-200px;
}
<div class="wrapper">
<div class="inner">
<div class="example"></div>
</div>
</div>
I'm wondering there are any workarounds because it affects my site when viewed on an iPad and its scaling.

Make text container to fit content automatically

I want to achieve this particular display by CSS:
I need to put there various texts and the lines to fill the white space that is left on right and left.
So far I got to this http://jsfiddle.net/g5jtm/, however there are several issues that I encounter:
the width of the text is variable and if I get out the width:40%; it will reset the width of the other 2 lines
The display:table does not allow me to align the lines through the middle of the text
HTML:
<div class="container">
<div class="lines l1"></div>
<div class="copy">Consumer review</div>
<div class="lines l2"></div>
</div>
CSS:
.container {width:100%; display:table; position:relative; height:100px;}
.lines, .copy {display:table-cell;vertical-align: middle;width:auto; }
.copy { white-space: nowrap; padding:3px; text-align:center; font-size:24px; width:40%;}
.l1,.l2 {border-bottom:1px solid red; height:50px; }
Here's one way with pseudo-elements
Codepen Demo
HTML
<div class="wrapper">
<h1 class="line">Consumer Review</h1>
</div>
CSS
.wrapper {
width:50%;
margin:0 auto;
}
.line {
display: table;
white-space: nowrap;
}
.line:before,
.line:after {
background: linear-gradient(to bottom, #9FD35F, #4F8C31) no-repeat center / 98% 3px;
content: '';
display: table-cell;
width: 50%;
}
How about a horizontal line tag
html:
<div class="container">
<div class="lines l1"><hr></div>
<div class="copy">Consumer review</div>
<div class="lines l2"><hr></div>
</div>
css:
.container {width:100%; display:table; position:relative; height:100px;}
.lines, .copy {display:table-cell;vertical-align: middle;width:auto; }
.copy { white-space: nowrap; padding:3px; text-align:center; font-size:24px; width:40%;}
hr {color:red}

Div occupying all the space of the margin from another div

I have one content div with 960px of width and margin 0 auto (centralized), i want put one div occupying all the space of the left margin, how can i do that?
demo jsBin
#container{
position:relative;
width:300px;/*change this*/
margin:0 auto;
height:200px;
background:#cf5;
padding-left:50%;
margin-left:-150px; /*half the width*/
}
#centered{
width:300px;
height:100%;
position:absolute;
right:0px;
background:#eea;
}
HTML:
<div id="container">
<div id="centered">centered</div>
</div>
HERE: http://jsbin.com/oluwos/3/edit is another way to do it.
Use display: table, like this:
http://jsfiddle.net/yVFzh/
<div class="wrapper">
<div class="left-column"> </div>
<div class="centre"></div>
<div class="right-column"> </div>
</div>​
html,
body{
width:100%;
}
.wrapper{
display:table;
width:100%;
}
.wrapper > div{
display: table-cell;
background: blue;
height:400px;
}
.wrapper .centre{
width: 960px;
background: yellow;
}​

Center DIV Within a DIV?

I need help in centering one DIV withing a DIV.
I want to have one container DIV that is auto width to take up the whole width of the screen (lets call it headerContainer.
Within headerContainer, I want 3 more DIVs:
A Left DIV (400px wide)
A Center DIV (100px wide)
A right DIV (200px wide).
I want the center DIV directly in the middle of the screen. Right now I can only get it to center between the left and right DIV.
Thanks for any help.
CSS:
.leftDiv{
float: left;
width: 400px;
}
.rightDiv{
float: right;
width: 200px;
}
.centerDiv{
width: 100px;
margin: 0 auto;
}
HTML:
<div>
<div class="leftDiv">left</div>
<div class="rightDiv">right</div>
<div class="centerDiv">center</div>
</div>
DEMO:
Code: http://jsfiddle.net/Xxwrm/6/
Fullscreen: http://jsfiddle.net/Xxwrm/6/show
This works.
.headerContainer{
width:auto !important;
}
.leftDiv{
float:left;
width:400px;
}
.rightDiv{
float:right;
width:200px;
}
.centerDiv{
display:inline;
width:100px;
margin-left:auto;
margin-right:auto;
}
.
<div class="headerContainer">
<div class="leftDiv"></div>
<div class="centerDiv"></div>
<div class="rightDiv"></div>
</div>
What you could do is add another div at the end which makes both sides equal, and set visibility: hidden; (not display: none;); this way it would centre the middle div.
For example in this case you'd have one # 400px, another # 100px, another # 200px and another one, hidden, # 200px.
Regards,
Richard
<div class="headerContainer">
<div class="leftDiv">left</div>
<div class="rightDiv">right</div>
<div class="centerDiv">center</div>
</div>
This HTML with this CSS will work. I colored the DIV's to make it obvious.
.headerContainer{
width:auto;
}
.leftDiv{
float:left;
width:400px;
background:pink;
}
.centerDiv{
width:100px;
/*
margin-left:auto;
margin-right:auto;
*/
margin:0 auto;
background:cyan;
}
.rightDiv{
float:right;
width:200px;
background:lightgray;
}
However, if the screen is not 700px wide, you will get some wrapping.
Here is a fiddle for it, too: http://jsfiddle.net/johnpapa/9bN2p/
You can use a modern solution due the flex concept of css3.
.parent {
display: flex;
height: 300px;
/* Or whatever */
background-color: green;
}
.child {
width: 100px;
/* Or whatever */
height: 100px;
/* Or whatever */
margin: auto;
/* Magic! */
background-color: yellow;
}
<div class="parent">
<div class="child ">Div1</div>
</div>

How to center div

I want to set center an outer div alignment. There is some inner div which float is set to left. So outer div is not aligned center
my inner div css is :
.inner {
float:left;
margin:10px;
border:1px solid #898989;
padding:4px;
width:200px;
background-color:#f2f2f2;
}
why is the inner div floated, if it's not needed just center the inner div?
.inner {
margin:10px auto;
border:1px solid #898989;
padding:4px;
width:200px;
background-color:#f2f2f2;
}
OR if inner is floated so it contains further floats.. then you could add overflow hidden to it
.inner {
overflow: hidden;
margin:10px auto;
border:1px solid #898989;
padding:4px;
width:200px;
background-color:#f2f2f2;
}
or you could make inner into an inline block- and wrap it in a div with text-align: center;
<div class="outer">
<div class="inner"><span>float</span>the inner text</div>
<div class="inner"><span>float</span>the inner text</div>
<div class="inner"><span>float</span>the inner text</div>
<div>
.inner {
display: inline-block;
margin:10px;
border:1px solid #898989;
padding:4px;
width:200px;
background-color:#f2f2f2;
}
.inner {display: inline !ie7;}
span {float: left; width: 50px; height: 50px; background: #ffe;}
.outer {text-align: center;}
Without any more detail in your question all I can suggest is
<div style='margin: 0px auto;'>Blah</div>
But it does rather depend on what else you have going on.
The easiest way is to set the horizontal margins to auto:
<div style="margin-left: auto; margin-right: auto;">Content</div>
But it depends on its float attribute as well. Since I don't know what else you have on your site, I can only recommend for you to try different float attributes (left, right, none).
Good luck! :)
try:
<div align="center" style="clear:left">
...
</div>
This is the simplest method:
Provided you set a fixed width,
and the proper DOCTYPE of course, try this
Margin-left:auto;
Margin-right:auto;
Hope it helps.

Resources