Can't get dashboard fit into container on TB template - css

I'm trying to build a template using Twitter Bootstrap. Here is the live example. The problem I'm having is I can get positioned dashboard div next to sidebar menu and I don't know where my mistake is? Can I get any help from experts? This is the HTML:
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
Menu
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
dashboard
</div>
</div>
</div>
And this are the styles:
.sidebar {
display: none;
}
#media (min-width: 768px) {
.sidebar {
z-index: 1000;
display: block;
overflow-x: hidden;
overflow-y: auto;
background-color: #f5f5f5;
border-right: 1px solid #eee;
}
}
.nav-sidebar {
margin-right: -21px;
margin-bottom: 20px;
margin-left: -20px;
}
.nav-sidebar > li > a {
padding-right: 20px;
padding-left: 20px;
}
.nav-sidebar > .active > a,
.nav-sidebar > .active > a:hover,
.nav-sidebar > .active > a:focus {
color: #fff;
background-color: #428bca;
}
.main {
padding: 20px;
}
#media (min-width: 768px) {
.main {
padding-right: 40px;
padding-left: 40px;
}
}
.main .page-header {
margin-top: 0;
}

Basically you were offsetting your columns to go beyond the actual grid that Bootstrap offers (the normal grid only has 12 columns but you were extending to, at most, 15 with the offsets). Basically, just beware of going beyond the normal column boundaries and don't use an all around padding, it was shifting one column but not the other.
Take the following out of your code to make it re-align:
CSS:
.main {
/* padding: 20px; */
}
Then rearrange your HTML to the following:
HTML:
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
Menu
</div>
<div class="col-sm-9 col-md-10 main">
dashboard
</div>
</div>
</div>
DEMO JSFiddle
References:
I'm sure you have seen this before but it never hurts to overlook it again. Bootstrap offers an awesome example of how to use their grid system here.

Related

How to place columns and rows in mat-dialog box

I have mat dialog box in Angular project and I want to make 1 row at the top and 3 row at the bottom just like the picture below but some reason I can't make it work. Also I don't want horizontal scroll bar and trying to hide it by playing with the width but I'm not sure why it's still there. Any suggestion
HTML
<div mat-dialog-content class="dialog-container">
<div class="column">
<div class="header">Tops</div>
</div>
<div class="parent">
<div class="left">
<div class="sub-header">Left</div>
<div style="background-color: darkblue;">
<div></div>
</div>
</div>
<div class="center">
<div class="sub-header">Center</div>
</div>
<div class="right">
<div class="sub-header">Right</div>
</div>
</div>
</div>
CSS
.dialog-container{
width: 1000px;
height:1000px;
overflow-x:hidden;
}
.header{
position: relative;
font-size: 20px;
text-align: center;
font-family: 'Raleway';
}
.button{
margin-top: 15px;
align-items: center;
}
.clickable {
cursor: pointer;
}
.parent {
display: flex;
overflow: hidden;
}
.column{
display: flex;
flex-direction: column;
background-color: blue;
}
.left {
width: 200px;
background-color: green;
}
.right {
width: 300px ;
background-color: blue;
}
.center{
width: 300px;
background-color: red;
}
.header{
font-size: 30px;
font-family: "Raleway-ExtraLight";
padding: 30px;
}
.sub-header{
font-size: 20px;
margin-top: 25px;
font-weight: bold;
}
Right now it look like this
The final design I want to achieve
I'm not sure how many columns or rows will be needed to achieve it like the final design but I playing around for now. Any suggestion will be really helpful.
You could use mat-grid. You just have to define your row and cols and that's it.
You will have 4 cols and 4rows. Your buttons at the bottom will go in the mat-dialog-actions div made for this.
Here is how you could do with mat-grid-list : Demo on StackBlitz
If the demo is nto working, here the code so you can try it :
html:
<mat-grid-list cols="18" rowHeight="1:3">
<mat-grid-tile [colspan]="3">Map Insights</mat-grid-tile>
<mat-grid-tile [colspan]="7">
<input type="text" placeholder="blablabla" />
</mat-grid-tile>
<mat-grid-tile></mat-grid-tile>
<mat-grid-tile [colspan]="7"><i>Blablablabla your text in italic</i></mat-grid-tile>
<mat-grid-tile [rowspan]="5" [colspan]="3">Your side bar</mat-grid-tile>
<mat-grid-tile [rowspan]="5" [colspan]="7"></mat-grid-tile>
<mat-grid-tile [rowspan]="5">=></mat-grid-tile>
<mat-grid-tile [rowspan]="5" [colspan]="7"></mat-grid-tile>
</mat-grid-list>
css:
mat-grid-tile {
background: lightblue;
}
Css is just here to show the blocks ;)

Rearrange bootstrap grid into different numbers of columns without code duplications

I have a problem with dinamiacally rearranging my div boxes.
I need two version:
mobile (one column beneath each other):
<div>A</div>
<div>B</div>
<div>C</div>
Any other (the middle one slides out from between the two others):
<div class="col-lg-4">
<div>A</div>
<div>C</div>
</div>
<div class="col-lg-8">
<div>B</div>
</div>
I can manage this with code duplications and visible/hidden pairs, but is there a solution without these? Especially I don't want code duplications...
Thanks,
edit:
unluckily, I forgot to add there is another complication:
I need several 100% width elements under this whole ABC thing, and height of the B element changes...
This setup shows that the D and the B overlaps. I want to position the D under the B...:
<div class="container">
<div class="row parent-row">
<div class="col-lg-4 div-wrap">
<div class="a">A</div>
<div class="b">B<br>B<br>B<br>B<br>B</div>
<div class="c">C</div>
<div class="d">DDDDDDDDDDD DDDDDDDDD DDDDDDDDDDDDDDDDD DDDDD DDDDDDDDDDDDDDDDDD DDDDDDDDDDDDD DDDDDDDD DDDDDDDDDDDDDD</div>
</div>
</div>
</div>
#media (min-width: 1200px) {
.b{
position:absolute;
top: 0;
right:0;
width: 66.66666667%;
padding-right: 15px;
padding-left: 15px;
min-height:1px;
}
.d{
position:absolute;
right:0;
width:100%;
padding-right: 15px;
padding-left: 15px;
min-height:1px;
}
.div-wrap{
position:initial;
clear:both;
}
.parent-row{
position:relative;
clear:both;
}
}
See if this will do the trick for you:
http://codepen.io/panchroma/pen/xRqgJe
The important bit is that when the viewport is wider than the stacked mobile view, you use a media query to take div 'B' out of normal flow by applying 'position:absolute'. And at the same time you manually apply the Bootstrap CSS styling for a 'col-lg-8' div, and you also tweak the positioning of its parents (.div-wrap and .parent-row) so that .B floats to the correct position.
Good luck
HTML
<div class="container">
<div class="row parent-row">
<div class="col-lg-4 div-wrap">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
</div>
</div>
CSS
#media (min-width: 1200px) {
.b{
position:absolute;
top: 0;
right:0;
width: 66.66666667%;
padding-right: 15px;
padding-left: 15px;
min-height:1px;
}
.div-wrap{
position:initial;
}
.parent-row{
position:relative;
}
}
You don't need to use absolute position. Apply float: right; and clear: left; properties instead.
I've tested two situations:
block A is higher than B
block B is higher than A
Please check the result: http://codepen.io/glebkema/pen/dOezEz
/* Heart of the matter */
#media (min-width: 1200px ) {
.clear-lg-left {
clear: left;
}
.pull-lg-right {
float: right !important;
}
}
/* Tests */
.tests {
margin-top: 14px;
}
.tests > div {
font-size: 28px;
font-weight: bold;
color: #fff;
padding-top: 6px;
}
.tests > div:nth-of-type(1) { background: #9c6; min-height: 120px; }
.tests > div:nth-of-type(2) { background: #f93; min-height: 80px; }
.tests > div:nth-of-type(3) { background: #69c; min-height: 80px; }
.test-2 > div:nth-of-type(2) { background: #f93; min-height: 160px; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<div class="row tests">
<div class="col-lg-4">A</div>
<div class="col-lg-8 pull-lg-right">B</div>
<div class="col-lg-4 clear-lg-left">C</div>
</div>
<div class="row tests test-2">
<div class="col-lg-4">A</div>
<div class="col-lg-8 pull-lg-right">B</div>
<div class="col-lg-4 clear-lg-left">C</div>
</div>
</div>

I have a few problems with designing a responsive header

I am designing a header and have a few questions about the issues I have.
The demo is here and the code is below, any help would be much appreciated.
.menu {
position: relative;
width: 100%;
height: 66px;
max-height: 90px;
background: green;
}
.menu img {
max-height: 30px;
}
.menu ul {
left: 0;
margin: 0 auto;
width: 80%;
margin: -30px auto 0 auto;
font-size: 16px;
font-weight: bold;
max-width: 1200px;
}
.menu ul li:first-child {
border-left: 1px solid gray;
}
.menu ul li {
//
width: 140px;
width: 14%;
display: block;
float: left;
text-align: center;
border-right: 1px solid gray;
color: white;
height: 50px;
line-height: 70px;
vertical-align: bottom;
}
.menu ul li a {
color: white;
}
.menubtn {
width: 30px;
height: 30px; //
opacity: 0.5;
cursor: pointer;
}
.menubtn .fa {
font-size: 26px;
color: rgb(75, 0, 130)
}
#menubtn {
position: absolute;
top: 2px;
left: 4px;
}
#media only screen and (min-width: 501px) {
.topbar {
display: none;
}
.menu ul li a {
font-size: 14px;
}
#mybody {
margin-top: 8%;
}
}
#media only screen and (max-width: 1200px) {
.menu ul li a {
font-size: 12px;
}
}
#media only screen and (max-width: 888px) {
.menu ul li a {
font-size: 12px;
}
}
#media only screen and (max-width: 685px) {
.menu {
height: 40px;
}
.menu ul {
margin: 0;
}
.menu img {
display: none
}
.menu ul {
width: 100%;
}
.menu ul li {
line-height: 40px;
height: 40px;
font-size: 13px;
}
}
#media (max-height: 480px) and (min-width: 480px) and (max-width: 600px) {
.menu {
display: none;
}
}
#media only screen and (min-width: 320px) and (max-width: 480px) and (orientation: landscape) {
.menu {
display: none;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.2.1/bootstrap-social.css">
</head>
<body>
<header>
<div class="container-fluid">
<div class="row" style="background-color: lightblue;">
<div class="col-md-8 col-sm-8 col-xs-1">
<div id="banner" style="margin-left: 59%;">
<img height="25px" width="25px" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRROdI3yg-dOO1Wl56Ci6AHheWnzUA6j01oJDvxaUNViODWLpLX" />
<img height="40px;" width="253px;" src="http://staticx.ibncollege.com/wcsstore/ExtendedSitesCatalogAssetStore/907_90722_1_21939/images/FULLIMAGE_88753.jpg" />
</div>
</div>
<div class="col-md-2">
<div id="images" style="float: right;">
<a class="btn btn-social-icon btn-sm btn-facebook" style="text-align: center;" href="#"> <i class="fa fa-facebook"></i>
</a>
<a class="btn btn-social-icon btn-sm btn-twitter" href="#"> <i class="fa fa-twitter"></i>
</a>
<a class="btn btn-social-icon btn-sm btn-google-plus" href="#">
<i class="fa fa-google-plus"></i>
</a>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 search-container">
<form id="searchbox" role="form" action="#" method="GET">
<div class="col-md-4 col-sm-12 col-xs-12 searchbox">
<div class="ui-widget">
<input id="Name" name="name" class="form-control searchinput" type="text" placeholder="name" value="">
</div>
</div>
<div class="col-md-4 col-sm-12 col-xs-12">
<input id="family" name="family" class="form-control searchinput" type="text" placeholder="family" value="">
</div>
<div class="col-md-2 col-sm-2 col-xs-1">
<button style="background-color: blue; border-radius: 14px; border-style: solid;" class="btn-search" type="submit" title="Search">
<div style="background-color: blue;">
<span class="glyphicon glyphicon-search"></span>
</div>
</button>
</div>
</form>
<div style="float: right; text-align: right;" class="col-md">
Click1 Click2
</div>
</div>
</div>
</div>
<div class="hidden-xs">
<div class="menu">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTnYmtXUnZ6g5TwfPndnVQMcVdJO8qkSJqm-dPkNRJ_13IaeTP6Pw" style="width: 100%; max-height: 40px;">
<ul id="idmenu">
<li>Item1
</li>
<li>Item2
</li>
<li>Item3
</li>
<li>Item4
</li>
<li>Item5
</li>
<li>Item6
</li>
<li>Item7
</li>
<li>Item8
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
</body>
</html>
The way I want it to be is as following:
As you can see I have a logo at the right side of the search box, that is from top of the page to the bottom of the search box.
A banner in middle, three social media links and two links that are positioned in slightly right bottom side of the social media links.
I also have a white image on top of the menu that will be replaced with a proper image.
(I am not creating the menu using nav because of that image that should be on top of the menu;therefore, I have problem with mobile size screen as well, need to do that manually therefore, help to design that with nav would also be appreciated)
I was asked to narrow down the requirement,
I need to put the logo in the location that is shown in the screen shot, not where it is, (it is now at the left side of the banner - please click on 'demo is here' link to see).
Also need to create a hamburger style menu for mobile screens, as I am not using nav it is difficult to achieve. If you know how to solve the issue with nav I would appreciate it, as you can see the current menu is not based on nav.
I need it to be responsive, so if you make any changes I would be grateful if you could consider that.
To start with, for a hamburger style menu on mobile devices I highly recommend FlexNav.
Now, most of what you are trying to do can be accomplished by adding some extra divs, I will explain:
The whole idea of a responsive design is that items are stacked on top of each other, and when you get to a certain point (breakpoint) they float up to sit beside other elements.
The above example shows what would happen if all containers were made float: left; at the widescreen breakpoint.
All of the elements that you want to float next to other elements need be inside the same container. In your case that means one container should have your logo in it, the next container should have your banner, input fields and search box, and the last container should have your social links. Or if you want the social links near the top on mobile you could use float: right; instead of float: left; and put them in an earlier container.
To have your form elements next to each other, they will need width of 50% or less. Percentages work very well for responsive theming.
Finally, if you're planning to do a lot of responsive theming there are tools out there than can be a bit challenging to set up and learn, but make the whole process MUCH smoother such as:
SASS (requires Ruby or an application)
Singularity Grids
Susy (similar to Singularity)
Well, as I always said it’s faster, easier and, specially cleaner, to NOT use boostrap when you want to translate your design to web. Bootstrap is a tool to make fast responsive webs under Twitter own design. It’s good but NOT miraculous. IF you want your own designs on webs you NEED to know css, whatever to modified bootstrap or do it from scratch (and if you know css then you woudn’t use bootstrap too much).
I will start from scratch.
It’s easier when you start with your html layout without, yet, adding the main elements:
<header>
<div class="container-menu-top">
<div class="menu-top">
<div class="menu-top-center">
<div class="icons-left">
</div>
<div class="container-login">
<div class="logo">
</div>
<div class="login">
</div>
</div>
</div>
<div class="menu-top-right">
<div class="social">
</div>
<div class="links">
</div>
</div>
</div>
</div>
<div class="container-menu-bot">
<div class="menu-bot">
</div>
</div>
</header>
And then you add css’s to position the layout correctly (and better if you use colors to make it easier to check everything is ok):
body {margin:0; padding:0;}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container-menu-top {
width:100%;
background-color: aqua;
height:160px;
}
.container-menu-bot {
width:100%;
background-color: aqua;
height:60px;
margin-top:40px;
}
.menu-top, .menu-bot {
max-width:970px;
width:100%;
height:100%;
background-color: green;
margin:0 auto;
text-align:center;
position:relative;
}
.menu-top-center {
display:inline-block;
background-color: red;
width:50%;
height:100%;
}
.menu-top-right {
display:inline-block;
float:right;
height:100%;
background-color: violet;
width:150px;
}
.icons-left {
width:10%;
float:left;
background-color: blue;
height:100%;
}
.container-login {
width:90%;
float:left;
background-color: brown;
height:100%;
text-align:left;
}
.logo {
height:20%;
background-color: orange;
}
.login {
height:80%;
background-color: yellow;
}
#media only screen and (max-width: 600px) {
.menu-top-center {width: calc(100% - 150px);}
}
As you can see in this FIDDLE in progress, everything makes sense, and is responsive just adding a single line of media queries .The social panel won’t change it’s width so at 600px (you may set your desire break width) width, I have changed the menú-top-center to get all the parent width but the social container. Notice, please I also made de main container to be of a máximum width of 970px (as in your example)
Also, I have set some heights just to be able to check the layout, later on I will delete many properties as the content will set the right height.
Now it’s time to put the elements inside their html containers.
Icons to the left of your login adding the images at the html and as css. Right atm they are on a container responsive so the images inside will change their width as you resize window. If you want a fixed size then give to the container a width on px and to the container-logina width with, again width:calc(100% - yourwidthpx); :
.icons-left img {
width:100%;
display:block;
padding:5px;
}
Your “logo” image in the html with your desired size (removing now the height of his parent):
.logo img {
height:40px;
width:253px;
max-width:90%;
display:inline-block;
}
Your login inputsinside login div (removing now the height of his parent) and the mediaquery to make it resposnive:
.login input, .login button {
display:inline-block;
}
.login input {width:35%;}
#media only screen and (max-width: 600px) {
.login input {width:100%;}
}
Your social icons (I recomend you to insert them as a list in the html):
.social {}
.social ul {list-style:none;margin:0;}
.social li {
height:30px;
width:30px;
float:right;
background-color: blue;
margin-left:4px;
margin-top:4px;
background-repeat:no-repeat;
background-size:cover;
}
.social1 {background-image: url(http://the-route-to-your-image.com);}
.social2 {background-image: url(http://the-route-to-your-image.com);}
.social3 {background-image: url(http://the-route-to-your-image.com);}
Your Links:
.links {
clear:both;
text-align:left;
margin-top:4px;
}
.links a {
display:inline-block;
}
Then remove heights and background-colors and that’s it: FIDDLE
Of course there are still stuff to do to style your project, after all this is the layout, I will leave some work for You :)
If I have time later tonight I may complete your menu trying to explain how to make it resposive with a “burger” icon.
Trust me, All this is MUCH easier and faster tan overriding and modifying your bootstrap to make it look as you want.
Edited (“burger” menú):
Now let’s make the main menú (base on your image). The html is easy:
<div class="container-menu-bot">
<div class="menu-bot">
<ul id="">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
<li>Item5</li>
<li>Item6</li>
<li>Item7</li>
<li>Item8</li>
</ul>
<div class="burger"></div>
</div>
</div>
Where burger is the icon. We give position:absolute to this container and we hide it using display:none. Then with mediaqueries we show the icon while hidden our list. We also need to change the li’s from display:inline-block to display:block and finally set a min-height to the main container so while the list is hidden you still have the “green” menú nav:
.menu-bot {position:relative;}
.menu-bot a {color:#fff;}
.menu-bot ul {list-style:none; margin:0;}
.menu-bot li {
display:inline-block;
padding:10px 20px;
border-left:1px solid #fff;
}
.menu-bot li:last-child {
border-right:1px solid #fff;
}
.burger {
width:25px;
height:25px;
background-color: red;
position:absolute;
top:7px;
right:7px;
display:none;
}
#media only screen and (max-width: 720px) {
.burger {display:block;}
.menu-bot ul {display:none;}
.menu-bot li {display:block; border:0;}
}
We also add our last class:
.menu-bot .visible {display:block;}
visiblewill just change the display of your list once you click on the burger icon. For that you just need a very simple jquery code:
$(document).ready(function () {
$('.burger').click(function () {
$('.menu-bot ul').toggleClass("visible");
});
});
This could be made with just css and using hover insteed of click, but I find it much better the click event and you future users probably will have a better experience
And that’s it. Quite simple, easy to understand and just a few lines of css.
Final FIDDLE. Good luck with your project

css - div parent not ok , height remains 0px

ALL COMPONENTS ARE DISPLAYED OK. BUT WHEN I PRESS F12 AND HOVER OVER NAVBAR-LEFT, it's height is that of 0px. I think I need to solve this by placing a small div with class clear somewhere, but I don't know where exactly!
<div class="core-container">
<div class="core-content">
<div class="navbar">
<div class="navbar-left">
<div class="navbar-logo">
LOGO
</div>
<div class="navbar-suggestions">
SUGGESTIONS
</div>
<div class="navbar-notifications">
NOTIFICATIONS
</div>
<div class="clear">
</div>
</div>
<div class="navbar-right">
<ul>
<li>Profiles & Schedules</li>
<li>Settings</li>
<li>Log Out</li>
</ul>
</div>
<div class="clear">
</div>
</div>
</div>
</div>
css code:
/MASTER PAGE/
.core-container
{
margin-top: 100px;
border: 1px solid black;
}
.core-content
{
width: 1000px;
margin-left: auto;
margin-right: auto;
padding: 10px 20px 10px 20px;
}
.navbar
{
border: 1px solid red;
padding: 10px 5px 10px 5px;
}
.navbar-right div
{
float: right;
}
.navbar-left div
{
border-right: 1px solid red;
float: left;
padding-right: 10px;
margin-right: 10px;
}
.navbar-right ul li
{
list-style-type: none;
float: right;
padding-left: 10px;
margin-left: 10px;
border-left: 1px solid red;
}
.clear
{
clear: both;
}
Yes, everything in your navbar-left is floating, so its height remains 0. But is that a problem? It looks good on the screen!
Anyway, the quick answer is to append float:none to the style for the clear class. Make sure you make it specific enough to override the styles for .navbar-left div and navbar-right div though, like this:
.navbar-left .clear, .navbar-right .clear
{
clear: both;
float:none;
}
Reason is that your clear DIV also have float on it because you define class like this:
.navbar-right div
{
float: right;
}
write like this:
.navbar-right .clear
{
float: none;
}

CSS: How do you keep this Div to the right of a float?

In my code below, case #1 works correctly. The "advice-area" div stays to the right of the "rating-box".
However, case #2 does not work when the text extends beyond one line. This causes the "advice-area" div to move below the "rating-box"
What is the best way to fix this? Thanks.
<html>
<head>
<style type="text/css">
.wrapper {
width: 400px;
list-style: none;
}
.row {
border-bottom: 1px solid #E5E5E5;
padding: 15px 0;
font-size: 14px;
clear: both;
}
.rating-box {
float: left;
height: 70px;
position: relative;
width: 60px;
}
.thumbs {
float: right;
width: 20px;
}
.number {
position: absolute;
top: 16px;
left: 5px;
}
.advice-area {
display: inline-block;
margin-left: 35px;
}
.advice-content {
font-size: 16px;
margin: 0 0 10px 0;
}
.advice-action {
display: inline-block;
}
.add-box {
display: inline;
margin-left: 30px;
}
.add-box a {
display: inline-block;
}
.share-button {
display: inline;
margin-left: 30px;
cursor: pointer;
}
.flag {
display: inline;
margin-left: 30px;
cursor: pointer;
}
</style>
</head>
<body>
<ul class="wrapper">
<li class="row">
<div class="rating-box">
<div class="thumbs">
<div> Up </div>
<div> Down </div>
</div>
<div class="number">1</div>
</div>
<div class="advice-area">
<div class="advice-content">Case #1: This is correct</div>
<div class="advice-action">
<div class="add-box">Plan</div>
<div class="share-button"> Share </div>
<div class="flag"> Flag </div>
</div>
</div>
</li>
<li class="row">
<div class="rating-box">
<div class="thumbs">
<div> Up </div>
<div> Down </div>
</div>
<div class="number">2</div>
</div>
<div class="advice-area">
<div class="advice-content">Case #2: But this really long text does not want to stay right next to the "Up" and "Down" links</div>
<div class="advice-action">
<div class="add-box">Plan</div>
<div class="share-button"> Share </div>
<div class="flag"> Flag </div>
</div>
</div>
</li>
</ul>
</body>
I'd restrict the width for the .advice-content or .advice-area div (or whatever div is around the content you're floating).
When you enter text into a floated div the div will auto-size its width accordingly, and if it expands too wide it'll automatically wrap over to the next line. Think about how wrapping works for words in text.
So, all you need to do is to restrict the width of that particular div, and it'll never grow wide enough to wrap to the next line.
Unless if you're in IE: in which case it'll do whatever the hell it wants ;)
Floating elements, rather than inline blocks, are probably what you want in this situation. I managed to get what looks like a useful outcome by moving the number div above the up/down div in the code, and then floating both to the left. I then tweaked the margins until the spacing looked decent.
CSS changes:
.number {
float: left;
}
.thumbs {
float: left;
width: 20px;
margin-left: 20px;
}
.advice-area {
margin-left: 80px;
}
HTML changes:
<div class="rating-box">
<div class="number">1</div>
<div class="thumbs">
<div> Up </div>
<div> Down </div>
</div>
</div>
limit the width on .advice-content and it will show how you want it to.
.advice-content {
font-size: 16px;
margin: 0 0 10px 0;
width:300px;
}
worked for me in IE7 & 8 / Firefox / Opera / Chrome / Safari

Resources