I have the followin g HTML:
<div class="wrapper">
<div class="left-block">
<p>
some text
</p>
</div>
<div class="right-block">
<p>
some text
</p>
<div class="some-block">654</div>
<div class="some-block">132</div>
<div class="some-block">987</div>
<div class="clear"></div>
<div class="regular-block">10002</div>
</div>
</div>
blocks with class left-block and some-block have property float:left
This looks like http://jsfiddle.net/5k5v67jj/
block with class clear has clear:left;
How can I make block regular-block to like on this screenshot:
You have to contain the float and the clear in a block formatting context. To set up such a context, a common practice is to use overflow:auto or overflow:hidden. You'd add this to the styling of the div with the "right-block" class.
See http://jsfiddle.net/5k5v67jj/1/
I would change .some-block from float:left; to display:inline;. That way, a standard div like .regular-block will automatically show underneath and you don't need a clear between them.
Then you can put the clear div at the bottom to fix the block heights:
.wrapper{
border: 1px solid brown;
}
.left-block{
float:left;
width:100px;
padding:5px;
border: 1px solid red;
}
.right-block{
margin-left: 112px;
border: 1px solid green;
padding:5px;
padding-bottom:0;
}
.some-block{
display:inline;
border: 1px solid yellow;
}
.regular-block{
margin-top:10px;
border: 1px solid violet;
}
.clear{
clear:left;
}
<div class="wrapper">
<div class="left-block">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tristique, lorem dapibus tristique rhoncus, justo erat volutpat erat, in malesuada enim libero quis metus. Nunc tristique maximus efficitur. Sed nec dolor ut quam consequat molestie id quis justo.
</p>
</div>
<div class="right-block">
<p>
Nunc a lectus enim. Quisque sit amet iaculis turpis, a auctor tortor. Mauris aliquet sapien non odio tempor, auctor gravida nunc commodo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elementum eu tellus vel volutpat. Cras sed neque egestas, ullamcorper purus id, viverra odio. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Fusce et malesuada est, et bibendum lectus.
</p>
<div class="some-block">654</div>
<div class="some-block">132</div>
<div class="some-block">987</div>
<div class="regular-block">10002</div>
<div class="clear"></div>
</div>
</div
Related
I have an ordered list that can contain any number of elements. Each element can be different in size, but regardless of size I want the number of the ordered list to align with the first row of the content. So what I want to achieve is this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit...
Box 1
See my jsfiddle for the problem I have.
https://jsfiddle.net/txo5bsua/2/
This is the HTML and CSS I have
.boxes {
display: table;
width: 100%;
height: 100%;
}
.box {
display: table-cell;
}
.box1 {
background: orange;
width: 75%;
}
.box2 {
background: yellow;
}
<ol>
<li>
<div class="boxes">
<div class="box box1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quis condimentum massa. Quisque purus nisl, finibus id placerat id, ultricies non magna. Sed justo dui, tristique et metus at, fringilla viverra ipsum. Duis malesuada est eget lectus fermentum,
vitae pretium eros tempor. Integer eu mi metus. Cras dui ipsum, iaculis ut libero dictum, dapibus consequat orci. Sed semper vitae lorem eu sollicitudin. Curabitur dapibus fringilla facilisis. Nullam facilisis ante in velit maximus gravida.
</div>
<div class="box box2">
<input type="radio">Yes
<input type="radio">No
</div>
</div>
</li>
<li>
<div class="boxes">
<div class="box box1">Box 1</div>
<div class="box box2">Box 2</div>
</div>
</li>
</ol>
Can you help me with this?
Does this work for you?
.boxes {
display:table;
width: 100%;
height: 100%;
float: right;
}
li {
clear: both;
}
.box {
display: table-cell;
}
.box1 {
background: orange;
width:75%;
}
.box2 {
background: yellow;
}
<ol>
<li>
<div class="boxes">
<div class="box box1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quis condimentum massa. Quisque purus nisl, finibus id placerat id, ultricies non magna. Sed justo dui, tristique et metus at, fringilla viverra ipsum. Duis malesuada est eget lectus fermentum, vitae pretium eros tempor. Integer eu mi metus. Cras dui ipsum, iaculis ut libero dictum, dapibus consequat orci. Sed semper vitae lorem eu sollicitudin. Curabitur dapibus fringilla facilisis. Nullam facilisis ante in velit maximus gravida.
</div>
<div class="box box2">
<input type="radio">Yes
<input type="radio">No
</div>
</div>
</li>
<li>
<div class="boxes">
<div class="box box1">Box 1</div>
<div class="box box2">Box 2</div>
</div>
</li>
</ol>
use display: inline-flex; instead of display: table; for your class .boxes.
If you want to keep the space below the boxes you can add margin-bottom: 20px;:
.boxes {
display:inline-flex;
width: 100%;
height: 100%;
margin-bottom: 20px;
}
.box {
display: table-cell;
}
.box1 {
background: orange;
width:75%;
}
.box2 {
background: yellow;
width: 25%;
}
li {
clear: both;
}
<ol>
<li>
<div class="boxes">
<div class="box box1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quis condimentum massa. Quisque purus nisl, finibus id placerat id, ultricies non magna. Sed justo dui, tristique et metus at, fringilla viverra ipsum. Duis malesuada est eget lectus fermentum, vitae pretium eros tempor. Integer eu mi metus. Cras dui ipsum, iaculis ut libero dictum, dapibus consequat orci. Sed semper vitae lorem eu sollicitudin. Curabitur dapibus fringilla facilisis. Nullam facilisis ante in velit maximus gravida.
</div>
<div class="box box2">
<input type="radio">Yes
<input type="radio">No
</div>
</div>
</li>
<li>
<div class="boxes">
<div class="box box1">Box 1</div>
<div class="box box2">Box 2</div>
</div>
</li>
</ol>
updated answer. it will work on IE also
use display:inline-table
demo: jsfiddle
.boxes {
display:inline-table;
width: 100%;
height: 100%;
}
.box {
display: table-cell;
}
.box1 {
background: orange;
width:75%;
}
.box2 {
background: yellow;
width:25%;
}
<ol>
<li>
<div class="boxes">
<div class="box box1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quis condimentum massa. Quisque purus nisl, finibus id placerat id, ultricies non magna. Sed justo dui, tristique et metus at, fringilla viverra ipsum. Duis malesuada est eget lectus fermentum, vitae pretium eros tempor. Integer eu mi metus. Cras dui ipsum, iaculis ut libero dictum, dapibus consequat orci. Sed semper vitae lorem eu sollicitudin. Curabitur dapibus fringilla facilisis. Nullam facilisis ante in velit maximus gravida.
</div>
<div class="box box2">
<input type="radio">Yes
<input type="radio">No
</div>
</div>
</li>
<li>
<div class="boxes">
<div class="box box1">Box 1</div>
<div class="box box2">Box 2</div>
</div>
</li>
</ol>
I need the three div in the section to be centered in the middle of the section; they are off too the left too far right now.
<section class="support-feat clearfix">
<div class="container-fluid">
<div class="row box">
<div class="block about-feature-1 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".3s">
<h2>
text, Lorem ipsum dolor
</h2>
<p>
sit amet, quam donec libero suspendisse vel, neque nunc vel, donec massa turpis rutrum mauris, quam enim in dui sit penatibus ipsum, ut lacus lobortis. Vestibulum phasellus metus pellentesque<br>sit amet, quam donec libero suspendisse vel, neque nunc vel, donec massa turpis rutrum mauris, quam enim in dui sit penatibus ipsum, ut lacus lobortis. Vestibulum phasellus metus pellentesque
</p>
</div>
<div class="block about-feature-2 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".5s">
<h2 class="item_title">
text, Lorem ipsum dolor
</h2>
<p>
sit amet, quam donec libero suspendisse vel, neque nunc vel,
donec massa turpis rutrum mauris, quam enim in dui sit
penatibus ipsum, ut lacus lobortis. Vestibulum phasellus metus pellentesque<br>sit amet, quam donec libero suspendisse vel, neque nunc vel, donec massa turpis rutrum mauris, quam enim in dui sit
penatibus ipsum, ut lacus lobortis. Vestibulum phasellus metus pellentesque<br>
penatibus ipsum, ut lacus lobortis. Vestibulum phasellus metus pellentesque
</p>
</div>
<div class="block about-feature-3 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".7s">
<h2 class="item_title">
text, Lorem ipsum dolor
</h2>
<p>
sit amet, quam donec libero suspendisse vel, neque nunc vel, donec massa turpis rutrum mauris, quam enim in dui sit penatibus ipsum, ut lacus lobortis. Vestibulum phasellus metus pellentesque<br>
sit amet, quam donec libero suspendisse vel, neque nunc vel, donec massa turpis rutrum mauris, quam enim in dui sit penatibus ipsum, ut lacus lobortis. Vestibulum phasellus metus pellentesque
</p>
</div>
</div>
</div>
</section>
.support-feat {
text-align: center;
margin: 2%
}
.support-feat .block {
color: #1c1c1c;
flex: 2;
min-width: 340px;
max-width: 400px;
box-sizing: border-box;
}
.support-feat .block p {
font-weight: 300;
font-size: 140%
}
.support-feat h2 {
font-size: 200%
}
.support-feat .about-feature-1 {
padding: 20px;
background: #fff;
border: solid;
border-color: #17b6ea;
margin: 2%
}
.support-feat .about-feature-2 {
padding: 20px;
background: #fff;
border: solid;
border-color: #17b6ea;
margin: 2%
}
.support-feat .about-feature-3 {
padding: 20px;
background: #fff;
border: solid;
border-color: #17b6ea;
margin: 2%
}
Here's an image to explain what's going on and what I'm trying to do;
basically I'm trying to do what this does: https://www.tvlift.com/support/technical-support/
You can utilize bootstraps 12-column grid system to accomplish this... check out my jsfiddle below https://jsfiddle.net/gumctejp/
Basically you will format your page component to fit within the context of bootstraps grid system.
A really simple example would look like:
<div class="row text-center">
<div class="col-sm-3">
</div>
<div class="col-sm-2 box">
one box
</div>
<div class="col-sm-2 box">
two box
</div>
<div class="col-sm-2 box">
three box
</div>
<div class="col-sm-3">
</div>
</div>
See http://getbootstrap.com/css/ for the official documentation on boostraps grid system
As far as I understood, you wish to have centered floating items. This can be realized with some basic css:
HTML:
<div class="row">
<div class="col-xs-12 text-center">
<div class="floating-center">
Whatever content in here
</div>
</div>
</div>
Be sure to have all required elements in place when working with the bootstrap grid system (in your code, the column element was missing, leading to glitches sometimes).
CSS for the floating elements:
.text-center {
text-align: center;
}
.floating-center {
position: relative;
width: 500px;
height: auto;
margin: 5px; /*Whatever margin each element should have*/
display: inline-block; /*This is mainly doing the magic */
}
EDIT:
Added a plunker to show the effect: https://plnkr.co/edit/vGKHW8Pa1tw2RLlmj4BI?p=preview
Note: This is how to center the divs. Device dependant widths can be realized with css #media attribute.
Hi all been searching hard but found various answers that doesn't seem to resolve my issue.
I have one div box that needs to be vertically align centered to the div box next to it matching its height which is not defined as the content will change
But i need the content in the left box to be centered no matter what the height of the div box next to it.
any help would be appreciated.
Thanks
<div class="container">
<div class="leftCol">
Content or image in here needs to be vertical center based on div next to it height <
/div>
<div class="rightCol">
Content here
</div>
</div>
Here is an example using CSS tables.
.table-panel {
display: table;
}
.table-panel div {
display: table-cell;
vertical-align: middle;
border: 1px dotted gray;
}
<div class="table-panel">
<div>Left panel</div>
<div>Right panel: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu pulvinar risus. Vestibulum imperdiet velit nisi, eget ullamcorper urna rutrum vel. Aliquam tristique elit augue, nec lobortis eros pretium quis. Proin ac quam pretium,
fringilla est et, sodales erat. Cras quis odio est. Integer ornare, neque in efficitur ultricies, justo magna ornare enim, quis dictum enim ipsum vel urna. Cras consectetur orci id quam cursus feugiat. Proin laoreet ullamcorper est vitae sagittis.
Aliquam faucibus elit sed sodales varius. Phasellus maximus turpis non nisl lobortis, sit amet efficitur lacus suscipit. Nunc a ligula a est feugiat mollis in a lacus.</div>
</div>
If I understand your question right what you are looking for is a wrapper around the two left- and right-boxes. Then inside the wrapper you want the two boxes to be inline-blocks and with vertical-align:middle perhaps?
See this Fiddle:
<div id="wrap">
<div class="left-box"></div>
<div class="right-box"></div>
</div>
#wrap{
width:250px;
height:auto;
background:#efefef;
}
.left-box{
display:inline-block;
width:100px;
height:150px;
background:#00ff00;
vertical-align:middle;
}
.right-box{
display:inline-block;
width:100px;
height:180px;
background:#ff0000;
vertical-align:middle;
}
http://jsfiddle.net/0kpdskf2/
Is this what you want?
I have a website where I am trying to have a series of blocks next to each other and below each other. Currently the blocks are inline, I'd like to stop that and have stacking blocks both next to each other and on top of each other.
The website and page in question: http://cityofguilds.com/profile.php
My CSS:
.profile_containers {
display: inline-block;
vertical-align: top;
margin-right: 5px;
margin-bottom: 5px;
width: 48%;
padding: 5px;
border: 1px solid #222;
}
And the HTML:
<div class="profile_containers">
<h2>User Info</h2>
Text Here
</div>
<div class="profile_containers">
<h2>About Me</h2>
Text Here
</div>
<div class="profile_containers">
<h2>Badges</h2>
Text Here
</div>
<div class="clear"></div>
Thanks guys
I would recommend having two eight columns next to each other..
HTML
<div class="container">
<div class="eight columns">
<div class="profile_containers">
<h2>User Info</h2>
<strong>Name:</strong> Ben<br>
<strong>Level:</strong> 1<br>
<strong>Gender:</strong> Male<br>
<strong>Country:</strong> United Kingdom<br>
<strong>Started Playing:</strong> 21st July 2013<br>
<strong>Interests:</strong> Programming, Magic: The Gathering and gaming.<br>
<strong>Guild:</strong> Shinkaku
</div>
<div class="profile_containers">
<h2>Badges</h2>
Lorem ipsum dolor sit amet and stuff... Lorem ipsum dolor sit amet and stuff... Lorem ipsum dolor sit amet and stuff...
</div>
</div>
<div class="eight columns">
<div class="profile_containers">
<h2>About Me</h2>
Maecenas tincidunt fermentum nisi, sed convallis sapien aliquet a. Proin venenatis pharetra nisi, sit amet ultricies nibh hendrerit in. Donec et metus augue. Praesent fringilla justo non eros accumsan, venenatis posuere justo aliquet. Nullam et tortor fermentum, sollicitudin augue eget, ornare augue. Sed interdum imperdiet ullamcorper. Proin nec mattis velit. Donec sed augue nec mauris commodo lacinia sit amet ac purus. Maecenas faucibus bibendum nisi sit amet fringilla. Donec vel urna nec massa molestie tincidunt. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut at euismod neque. In venenatis, augue lobortis bibendum pretium, velit est ornare nunc, a blandit lectus velit eu tortor. Quisque consequat odio at arcu accumsan, vel dapibus ipsum aliquam.
</div>
</div>
</div>
CSS
.profile_containers {
margin-right: 5px;
margin-bottom: 5px;
padding: 5px;
border: 1px solid #222;
}
getting them to fit and stack on one another snug is a little tricky to just do with CSS since your blocks are different sizes.
If you can set a height for your blocks thats fixed, then you can float them in css and they will automagically grid out for you.
so your css would look like this :
.profile_containers{
float:left;
margin: 0 5px 5px 0;
width:48%;
padding: 5px;
border: 1px solid #222;
/* consider adding box sizing to keep the integrity of your width because the padding will mess that up*/
box-sizing : border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
}
if this method will work but will break if the heights of your divs are different. The easiest way to get them snug as I have found is either to break them into separate columns and put your divs in columns ex
<div class="profile_container_column">
<div class="profile_container"></div>
<div class="profile_container"></div>
</div>
<div class="profile_container_column">
<div class="profile_container"></div>
<div class="profile_container"></div>
</div>
and use the css float:left on the columns.
Or use a javascript library like masonry to manage the positioning for you.
Im wanting the container (purple border) to grow in size alongside the main content so i can place a border around it so it looks like the sidebar (blue border) is full height.
<div id="container">
<section id="mainContent">
<h1>title here</h1>
<img src="images/jayzmchg.jpg"></img>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec eget sapien ut eros auctor consectetur. Praesent pretium ante et orci pharetra venenatis.
Proin fringilla fermentum sollicitudin. In ornare lectus ipsum, et egestas arcu consectetur
a. Nulla facilisi. Praesent id convallis arcu. Vestibulum leo tellus, hendrerit eu metus et,
cursus ultricies sapien. Aenean eu rutrum sem. Curabitur at quam nec augue viverra tempor ac
ut lorem. Sed vel accumsan sapien. Phasellus luctus diam ac luctus tincidunt. Integer quis
venenatis mauris. Nam malesuada augue id nibh porta commodo. Nam ullamcorper dui sit amet
ligula scelerisque hendrerit.</p>
</section>
<div id="sidebar">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
<footer id="footer">
<p></p>
</footer>
Above is the html, the following is the css
#container { /* purple border */
height: 250px;
margin: 0 auto;
max-width: 1000px;
border: 1px solid #FF00FF;
}
#mainContent { /*red border */
float: left;
width: 700px;
border: 1px solid #FF0000
}
#sidebar {/*blue border */
width: 294px;
float: right;
border: 1px solid #0000FF;
}
ive set the height at 250px for the container so you can see it, ive tried setting it as 100% but just doesnt show anything im guessing this is cause theres no content in it but how could i make it so it acts like if what is inside the mainContent is its height.
adding overflow:hidden to container causes this
Put a float:left; on #container.
OR
Put overflow:hidden; on #container to clear the internal floats.
Example fiddle: http://jsfiddle.net/3jNTv/
Chris Coyier has written a great post about it here:
http://css-tricks.com/all-about-floats/
Try set the height to heigh: 100%;?
Try this one, see live example:
link
height: auto !important;
I have added a class floClear and add a div. it will work fine.
CSS
#container { /* purple border */
margin: 0 auto;
max-width: 1000px;
border: 1px solid #FF00FF;
}
#mainContent { /*red border */
float: left;
width: 700px;
border: 1px solid #FF0000
}
#sidebar {/*blue border */
width: 294px;
float: right;
border: 1px solid #0000FF;
}
.floClear
{
clear:both;
}
HTML
<div id="container">
<section id="mainContent">
<h1>title here</h1>
<img src="images/jayzmchg.jpg"></img>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec eget sapien ut eros auctor consectetur. Praesent pretium ante et orci pharetra venenatis.
Proin fringilla fermentum sollicitudin. In ornare lectus ipsum, et egestas arcu consectetur
a. Nulla facilisi. Praesent id convallis arcu. Vestibulum leo tellus, hendrerit eu metus et,
cursus ultricies sapien. Aenean eu rutrum sem. Curabitur at quam nec augue viverra tempor ac
ut lorem. Sed vel accumsan sapien. Phasellus luctus diam ac luctus tincidunt. Integer quis
venenatis mauris. Nam malesuada augue id nibh porta commodo. Nam ullamcorper dui sit amet
ligula scelerisque hendrerit.</p>
</section>
<div id="sidebar">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="floClear"></div>
</div>
<footer id="footer">
<p>Test</p>
</footer>