Prevent div from wrapping around in bootstrap [closed] - html

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 6 years ago.
Improve this question
I am using bootstrap to help structure a webpage. Within a row, I have three divs side-by-side, with widths: 2 columns, 6 columns, and 4 columns in that order in a 12 column layout.
The middle div also has a minimum width set, so when the outermost div shrinks beyond a certain width, there is not enough room for the right most div (the 4 column one), so it wraps around and hangs out below the other divs.
I would like to prevent this div from wrapping around, forcing it to be cut off by the window when the screen shrinks too small. How would I accomplish this?
I can provide any further details/code/pictures if necessary.
Thanks!
Before wrapping
After wrapping

To prevent wrapping: add this to your row.
.row{
width:100%;
margin:0;
padding:0;
display:flex;
}
width:100%;margin:0;padding:0; are optional in this.
This may cause your content to stretch to full height, so don't put content in bootstrap columns(e.g. `col-md-6 and so on) directly. put a div in them and put the content inside that div.
like this :
<div class="col-xs-2">
<div class="contentDiv">
<!--Put your content here-->
</div>
</div>
Here's an example:
#firstDiv,#secondDiv,#thirdDiv{
height:100px;
background-color:red;
min-width:100px;
}
#firstDiv{
background-color:green;
}
#secondDiv{
background-color:blue;
min-width:500px;
}
.row{
width:100%;
margin:0;
padding:0;
display:flex;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-2" id="firstDiv">
</div>
<div class="col-xs-6" id="secondDiv">
</div>
<div class="col-xs-4" id="thirdDiv">
</div>
</div>
</div>

Related

Inserting an element (div) before a centered element (div)

I have a fixed width div with centered text
--------Centered Text--------
I would like to append another div that has right aligned text right before the centered div.
This is Centered Text------
EDIT:
I updated the jsfiddle code so it isn't left in such a disoriented state.
I was trying many different approaches and ended up posting a messy example. The code below shows what I am trying to do.
<div class="text-entry" style="
display:flex;
justify-content: center;
background-color:grey;
">
<div style="display:inline-block; width:100px; text-align:right; background-color:red;">My-</div>
<div style="background-color:white; ">Text</div>
<div style="display:inline-block; width:100px;"></div>
</div>
<!--- ------------------- -->
<div class="text-entry" style="background-color:grey;text-align:center;">
<div style="display:inline-block; background-color:white; ">
Text
</div>
</div>
My question is what is the proper way to implement this instead of using two inline-blocks of fixed width?
*Excuse my lack of skills. I am doing this as a hobby and not professionally. Thank you for the help. I have googled before coming here.

HTML put two div side by side [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I put two div side by side with CSS like shown on the image down here?
Eventually I'd like the div on the left to be scrollable, but it's not necessary.
The most important thing I need is to put them side by side.
Side by side divs:
display: inline-block;
//add this to both divs
http://www.w3schools.com/cssref/pr_class_display.asp
Scrollable div:
overflow: scroll;
//add this to the left div
http://www.w3schools.com/cssref/pr_pos_overflow.asp
example:
https://jsfiddle.net/90h5c20x/
Put your divs into common parent, and then you have to use css. For the left div, add style="float: left". For the second one write style="float: right".
You can wrap both divs inside another div and apply the flexbox to the wrapper
html:
<div class="wrapper">
<div class="div1">
<!-- div code here -->
</div>
<div class="div2">
<!-- div code here -->
</div>
</div>
CSS:
.wapper{
display: flex;
flex-flow: row wrap;
}
This works smoother than inline-block and floats and is mobile responsive. It will also allow the scrolling for the first div.
Flexbox is cool and very elegant, but it simply does not work in a production environment (IE9 and lower) without any fixes/hacks. Therefore I am providing this working cross-browser answer.
Here is your HTML:
<h1>Title</h1>
<div class="wrapper">
<div class="div1">
<!-- div code here -->
</div>
<div class="div2">
<!-- div code here -->
</div>
</div>
With the following CSS:
.wrapper {display: table;}
.div1, .div2 {display: table-cell;}
And here is the working code: http://codepen.io/anon/pen/xVMprO
Here is the code with overflow: http://codepen.io/anon/pen/NNoXBJ

Positioning div's in html and CSS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have 5 div's as follows:
<div class="centered" style="background-color:red;">top</div>
<div style="background-color:orange;">left</div>
<div style="background-color:yellow;">center</div>
<div style="background-color:green;">right</div>
<div class="centered" style="background-color:blue;">bottom</div>
I want to place the first one (with centered class) on the top-center, and the second (with "left" text), third (with "center" text) and the fourth (with "right" text) in one row in the center right below the top. Lastly, the fifth (with centered class) in the bottom center below the line of 3 div's.
I tried but it was just a waste of time. Can you help me with css?
Like this?
div {
height: 200px;
display: border-box;
}
.centered {
margin: 0 auto;
width: 33.33%;
}
.row {
}
.row div {
width: 33.33%;
float: left;
}
.row:after {
display: table;
content: ' ';
clear: both;
}
<div class="centered" style="background-color:red;">top</div>
<div class="row">
<div style="background-color:orange;">left</div>
<div style="background-color:yellow;">center</div>
<div style="background-color:green;">right</div>
</div>
<div class="centered" style="background-color:blue;">bottom</div>
you may want to use a framework with a grid such as Twitter Bootstrap: http://getbootstrap.com/ or Zurb Foundation: http://foundation.zurb.com/. These frameworks provide a 12 column grid to make div positioning easier to handle.
The following example is using twitter bootstraps grid to position div's in the manner you are speaking of:
<div class="container">
<div id="top" class="row">
<div class="col-md-2 col-md-offset-5">
<p>...content</p>
</div>
</div>
<div id="middle" class="row">
<div class="col-md-4">
<p>...content</p>
</div>
<div class="col-md-4">
<p>...content</p>
</div>
<div class="col-md-4">
<p>...content</p>
</div>
</div>
<div id="bottom" class="row">
<div class="col-md-2 col-md-offset-5">
<p>...content</p>
</div>
</div>
</div>
The "row" class will create a new row where the elements will be positioned sort of like hitting enter for a new line in a word document. the "col-md-2" is the bootstrap syntax for how many columns the element will take up out of the 12 column grid. Offsetting this column by 5 on both ends will subtract 10 from the number of columns and so the remaining two in the middle will be reserved for the element. This will position your div in the center. You mentioned that you wanted the second row divs to all be positioned together in the center. The code written above will give each div equal width to take up the whole length of the row across the screen. The container that is wrapped around the code will provide a padding around all of the content inside of it so it will not touch the edges of the window. I hope this helps.

Bootstrap fixed size column [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to do fixed width right column column in bootstrap, but left column will be responsive.
I use bootstrap 2.3.2
(source: toile-libre.org)
Right column will not be resized at all screen size.
My basic solution below (see it in action here). I've padded out the CSS to demonstrate the blocks with colours, but all you really need to do is as follows:
Fixed element
Set it to float:right
Apply a fixed width to it
Fluid row element
Apply padding/margin-right equal to the width of the fixed element
Apply box-sizing:border-box, so that the 100% width against the .row-fluid element persists, but the margin/padding added doesn't push it out further. The markup below shows the minimum you'll need.
CSS
#fixed-width {
width:100px;
float:right;
}
#fluid.row-fluid {
margin-right:100px;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
HTML
<div class="clearfix">
<div id="fixed-width">Content...</div>
<div id="fluid" class="row-fluid">
<div class="span4">a</div>
<div class="span4">b</div>
<div class="span4">c</div>
</div>
</div>
this kind of design it's not provided by bootstrap, but there are simple solutions.
Here is one, see the accepted answer to this previous SO question Bootstrap: Fixed gutter width in fluid layout?
and in particular, this css tricks
.fluid-fixed {
margin-right: 240px;
margin-left:auto !important;
}
as shown in this fiddle http://jsfiddle.net/6vPqA/808/

How to create a div grid with equal spacing in a flexible layout?

I am trying to creat a layout like this:
My question is specifically centered around the five boxes. I struggle with the CSS to get it to work. Have you guys got a simple setup for such a layout?
I see that you have fixed width, so here is an example. Widths are not exact for your width, but you can esily set values you need. Main thing here is float:left in small_bottom class which makes div to be shown in one row. overflow:hidden in bottom class makes that div wrap around floating divs (without that it will be shown like there is nothing inside). If you want this depend on browser window width - try using percents in width for small_bottom.
HTML:
<div class="main">
<div class="top"></div>
<div class="bottom">
<div class="small_bottom"></div>
<div class="small_bottom"></div>
<div class="small_bottom"></div>
<div class="small_bottom"></div>
<div class="small_bottom"></div>
</div>
</div>​
CSS:
div{border:solid 1px;}
.main{width:350px; border:solid 1px;}
.top{ height:40px;margin:5px;}
.small_bottom{
float:left;
height:50px;
width:50px;
margin:5px;
}
.bottom{margin:5px; overflow:hidden;}
​
Here is an example how it looks