Fluid css floats - html

I'm trying to create a fluid element for a site i'm working on, Check out this JS fiddle and make your browser a bit wider, you will see a grey line, a black box, and then a grey line.
When the browser's width is lower the right side line breaks down to the next line, but i want this to stay together no matter how wide the browser is. I generally use float's but have tried a few things, as you can see some css is commented out cause i'm playing with it.
Does anybody have some cool tricks to show me? Any help would be greatly appreciated! Let me know if you need any info.
http://jsfiddle.net/r8Xka/
CSS
header .lower{
overflow:hidden;
width:95%;
margin:40px auto 0 auto;
}
header .lower .line{
/*float:left;*/
display:inline-block;
background:#eaebeb;
width:35%;
height:8px;
/*display:block;*/
position:relative;
top:18px;
}
header .lower a{
/*float:left;*/
display:inline-block;
margin:0 20px;
/*display:block;*/
background: #000;
width: 141px;
height: 42px;
}
HTML
<header data-behavior="randomHeader">
<div class="lower">
<div class="line"></div>
Play Video
<div class="line"></div>
</div>
</header>

You have 3 column: left - fluid, middle - fixed, right - fluid. You would need some js to make it work.
Or some html/css trick like this:
<header data-behavior="randomHeader">
<div class="lower">
<div class="line"></div>
<div class="center">
Play Video
</div>
</div>
</header>
Css:
header .lower{
width:95%;
margin:40px auto 0 auto;
position: relative;
}
header .lower .line{
background:#eaebeb;
height:8px;
}
.center{
text-align: center;
position: absolute;
top: -20px;
left: 0;
width: 100%;
}
header .lower a{
border: 10px solid #FFF;
display:inline-block;
background: #000;
width: 141px;
height: 42px;
}
See working fiddle

Related

How to cut divs both ways to keep the objects in center?

I am trying to build a nav-bar that stays on top, fixed and in the middle. But if the screen size is large enough some unused space can be used left and right according to my needs and also there's a bit of space in the middle.
Now, if someone resizes the browser window, I need to start stripping off the unused space from the screen and keep only the essential divs of the parent div.
For reference have a look at Facebook's Desktop navbar.
How do I achieve this with html and css?
Also, if someone resizes so much that the objects will be affected anyway, I would want them to just getting cut off the screen without altering their positions.
<html>
<head> <style>
.navbar {
position:fixed;
background: #000;
height: 30px;
width: 100%}
.logo_div{
margin-left:7%;
float:left;
width:32px;
display:inline-block;
height:32px;
}
.search_div {
width: 450px;
display: inline-block;
margin-left:15px;
float:left;
}
#search_box {
width:100%;
border-radius:5px;
border:1px solid #819597;
padding:4px;
border-bottom-right-radius:0px;
border-top-right-radius:0px;
border-right:none;
height:24px;
font-family: Arial;
font-size:16px;
font-weight:lighter;
outline:none;
}
#search_box:focus {
border-right:none;
background-color:#FCFCDA;
}
li {
text-decoration:none;
padding:5px;
padding-bottom:0px;
margin:1px;
margin-top:0px;
list-style:none;
display:inline-block;
}
.menu {
padding:3px;
float:left;
display:inline-block;
padding-left:10px;
}
ul {
margin-top:0px;}
#static_head{
width:1024px;
margin:0 auto;
position:absolute;
text-align:center;
}
.user_controller {
display:inline;
margin:0 auto;
height:100%;
width:auto;
}
</style>
</head>
<body>
<div class="container">
<div class="navbar" id="dHeaderfixed">
<div id="static_head">
<div id="logo_div" ></div>
<div class="search_div">
<form action="search.php" method="get" id="search_form" name="livesearch">
<input type="text" id="search_box" name="query"></form>
</div>
<div class="menu">
a list of things
</div>
<div id="ui_user_control">some stuff</div></div>
</div></div></div>
Now, the blank unused spaces should be in the navbar at the left of the logo div, this will be as long as required according to screen size. Again there will be unused space between the search box and the menu div and another unused space at the right of the menu div, so when the user resizes the browser window, all of those elements stay in the middle,and if resized further, the screen just cuts them out instead of altering their positions. Thanks!
https://jsfiddle.net/xhzxduz2/2/
CSS
nav {
position: fixed;
left: 0;
top: 0;
background: red;
height: 48px;
min-width: 320px;
width: 100%;
}
.content {
max-width: 960px;
margin: 0 auto;
color: white;
background: blue;
height: 100%;
}
HTML
<nav>
<div class='content'>
YOUR MENU HERE
</div>
</nav>

Center header inside parent

I use bootstrap and joomla.
I have a new design that requires my div and h2, to be 1920 pixels wide and have centered text. What i have done is:
.page-header {
background-color:#3c4547;
width:1920px;
top:0px !important;
position:relative;
margin-top:0px;
display:block;
padding:20px 0px 25px 0px;
z-index:999;
left:-385px;
}
.page-header h2 {
color: #white;
font-size:36px;
font-weight:400;
margin-left: auto;
margin-right: auto;
text-align: center;
}
The wrapper is only 1600 pixels wide or something, thats why i cheat with negative margin.
but it doesnt center the text right on resize - its need to be responsive aswell. Any suggestions?
This is my HTML code and i cannot edit it:
<div class="page-header"><h2 itemprop="name">Header text</h2></div>
It has a as parents.
This is basicly what i want and have, but it doesnt center on responsive:
.
and this is how it looks just with just 100% width:
For Lion and others, to explain the whole code:
<div class="parent">
<div class="page-header>
<h2>testest</h2>
</div>
</div>
.parent {
width:1000px;
}
.page-header {
width:100%;
background:red;
}
.h2 {
color: #ffffff;
text-align:center;
}
** try to use this code, i hope this code will help you :)**
div h2 {
max-width: 1920px;
width: 100%;
height: auto;
display: flex;
justify-content: center;
}
UPDATED
please replace your code to this
.page-header {
background-color:#3c4547;
width:100%;
top:0px !important;
margin-top:0px;
display:block;
padding:20px 0px 25px 0px;
z-index:999;
left:-385px;
}
.page-header h2 {
color: #white;
font-size:36px;
font-weight:400;
margin-left: auto;
margin-right: auto;
text-align: center;
}
no need of position..
Sorry if i did not get your point but if you want to make your h2 center align then why don't you use margin..
see this
.page-header{width:100%;}
h2{margin-left:auto;margin-right:auto;width:auto;text-align:center;}
.section{ margin-left: auto;margin-right: auto;text-align: center; width: 100%;}
i am assuming that you wanted to make your h2 text center align with responsiveness so i typed code like this..correct me if m wrong..
For Testing
<div class="page-header">
<h2 itemprop="name">Header text</h2>
</div>
<div class="section">
<p>lalalala</p>
<p>lalalala</p>
<p>lalalala</p>
<p>lalalala</p>
<p>lalalala</p>
</div>
please check my example and let me know your structure is different.. ty
screenshot
You guys had some good answers, but didnt really solve my problem - i am sure one of yours can be a solution to another with a problem simular to this, but in my case i solved the problem by using javascript to expand the id tag.
if(jQuery('.page-header').length > 0){
pageHeader = jQuery('.page-header');
jQuery('#main').prepend(pageHeader);
}

CSS / HTML - Unable to place DIV to the right side

On our website, we have a container, with a DIV box inside which leaves a space along the right hand side so we can add some more boxes with images / text.
I got as close as the boxes to the right hand side but underneath the "main" div.
http://jsfiddle.net/Ug5pz/2/
Thanks!
CSS:
#container {
position: relative;
width: 600px;
height: 400px;
margin: 0 auto 0;
background: #FFF;
border-style:solid;
border-width:2px;
}
#main {
position:relative;
width: 450px;
height: 300px;
border-style:solid;
border-width:2px;
}
#sidebox {
position:relative;
width:120px;
height:50px;
float:right;
border-style:solid;
border-width:2px;
}
HTML:
<div id="container">
<div id="main">Welcome to our website!</div>
<div id="sidebox">Sidebox</div>
</div>
Try adding float:Left to the #main CSS
Alternatively you could modify the #sidebox CSS as follows:
position:absolute;
right:0px;
top:0px;

Div Container with repeat background image and floating div

I've moved onto using divs rather than tables.
I have a container with a repeat image as a background. It needs to auto size due to my dynamic content.
The issue I'm having is I want to put two divs in this container side by side.
When I float these divs this causes my auto container div to not expand with them. The only way I can solve the issue is by setting the container to a height which I can't do as this will be different on each dynamic page.
http://www.blockdesigns.co.uk/html5.php this is my example.
Code:
<body>
<div id="main_wrapper">
<header id="top_header">
</header>
<div id="main_body">This part should go all the way down to the footer.<br>
<div id="leftside">Float left div here</div>
</div>
<footer id="footer">
</footer>
</div>
</body>
CSS
#main_wrapper{
width:1000px;
margin: 20px auto;
text-align:left;
}
#main_body{
background:url(Body1000.jpg);
background-repeat:repeat;
text-align:center;
width:1000px;
}
#leftside{
float:left;
width:200px;
height:300px;
margin:10px;
}
Add overflow: hidden; to main_body
example
#main_wrapper {
width: 1000px;
margin: 20px auto;
text-align: left;
}
#main_body {
background: url(Body1000.jpg);
background-repeat: repeat;
text-align: center;
width: 1000px;
overflow: hidden;
}
#leftside {
float: left;
width: 200px;
height: 300px;
margin: 10px;
}

Google Chrome: Text will not minimize correctly

Google Chrome is really throwing a roadblock at me and I need some help.
I am setting up a menu and the text is wrapping when zooming out (<50%). I do not want to use white-space: nowrap and I cannot make my menu wider. Safari, Firefox, even IE - no problems however when zooming out with chrome it forces a word wrap. Any ideas. Please let me know if more html/css is needed, i tried to simplify things:
CSS:
#page{
display: block;
overflow:visible;
font:"Times New Roman", Times, serif;
text-align: center;
margin: auto;
width: 100%;
height: 1000px;
background:#956e41;
}
#header{
width:auto;
max-width:1105px;
margin:auto;
position: relative;
overflow:visible;
}
#mainPicture{
height:475px;
width: 1105px;
background-image:url(images/main.jpg);
background-repeat:no-repeat;
margin: auto;
position: absolute;
}
#headerFrame{
height:80px;
margin: auto;
width: 1080px;
background-color: #a15535;
position: relative;
}
#logo{
height: 150px;
width: 340px;
margin: auto;
background-image:url(images/logo.png);
float: left;
}
#menuFrame{
width:auto;
max-width: 740px;
margin: auto;
width: 1080px;
display:inline-block;
}
#menu{
width:auto;
font-size:16px;
font-weight:600;
margin: 0 0 0 0 ;
text-align:right;
display:inline-block;
}
#menu ul{
margin-left: 80px;
}
#menu ul li{
list-style:none;
float:left;
margin: 0 0 0 10px;
padding: 0 10px 10px 0;
}
HTML:
<div id="page">
<div id="header">
<div id="mainPicture"></div>
<div id="headerFrame" class="borderSq">
<div id="logo">
<!--<img src="images/logo.png" />-->
</div>
<div id="menuFrame">
<div id="menu">
<ul>
<li class="border li">menu1<br /><span>text</span></li>
<li class="border li">THE menu1<br /><span>text</span></li>
<li class="border li">menu1<br /><span>text</span></li>
<li class="li">menu1<br /><span>text</span></li>
</ul>
</div>
</div>
</div>
</div>
</div>
Some of the CSS may look redundant, i lost my cool and started just throwing stuff at it... never good.
Demo: http://jsfiddle.net/X48ng/
^Open with chrome and zoom out.... you'll see (scroll right too for text)
John
Ok I think i see exactly what is causing it but its a bit of a fiddle with what you want from this,
After messing with the fiddle a bit I managed to stop the menu items being pushed to a new line when zooming out to 33% by removing the margin-left on the #menu ul{} item,
As shown here:
js Fiddle (still happens when zoomed out to 25% but now can zoom out to 33% instead of just 50%)
The only thing I can think of that is causing this is; as the page is resized the margin is being enlarged or something along those lines,
if anyone can help improve this answer, please do.
steve.