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.
Related
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 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
The problem should be able to be seen live at this link (on every page, as the main content of the page is contained by my "content" div): http://tucsonbagley.com/index.html
The "content" class (a container div) has a much larger margin on the left than on the right and, after going over my CSS ad nauseum, I just cannot figure out why. I've broken something for sure (it was working not long ago!), but I just can't figure out what.
If I remove my id Navbar or id Header divs, the Content div will default back to the left... yeah, at this point I'm lost.
The CSS in question:
.content{
display:inline-block;
margin:0 auto;
width: 68%;
overflow:hidden;
text-align: center;
padding: 10px;
background-color: #FFFFFF;
font-size: 12px;
border-radius: 10px 10px 10px 10px;
}
Example HTML:
<body>
<div class="header">
<p>Tucson Bagley</p>
</div>
<div id="socialmedia">
<img src="images/Twitter_logo_blue.png"/>
<img src="images/linkedin.png"/>
<img src="images/facebook.png"/>
</div>
<div id="header">
<small>BagelHero#gmail.com</small>
</div>
<div id="navbar">
<ul>
<li><span>Gallery</span></li>
<li><span>Resume/CV</span></li>
<li><span>Contact me</span></li>
</ul>
</div>
<div class="content">
<div class="thumbleft"><h2>This is some content.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius metus. Pellentesque eu nunc tortor. Aliquam id lectus orci. Sed id consectetur eros. Curabitur semper nisl nibh, rhoncus lacinia nibh volutpat at. Pellentesque sollicitudin vitae ipsum ut dictum. Proin ac risus ac nisi interdum hendrerit. Pellentesque sodales mauris ac eleifend vehicula. Nulla convallis aliquet urna varius auctor. Donec eget ipsum ut mauris consequat auctor eget sit amet odio. Nullam sed lorem erat. Praesent consequat porttitor magna, sit amet feugiat odio tincidunt ut. Fusce congue eros vel quam condimentum, vel consectetur quam imperdiet. </p>
</div>
</br>
<div id="copyright">
<p>Copyright 2012-2014 | Tucson Bagley</p>
</div>
</body>
Some help would be appreciated. Thanks in advance!
Add a <div style="clear:both"></div> before .content div and apply display:block to .content instead of display:inline-block and that's it
change the css of your .content to look like this
.content{
position: absolute;
left:0px;
right:0px;
display:inline-block;
margin:10px auto;
width: 68%;
overflow:hidden;
text-align: center;
padding: 10px;
background-color: #FFFFFF;
font-size: 12px;
border-radius: 10px 10px 10px 10px;
}
the magic is the left:0px combined with right:0px and margin:10px auto which will only work in absolute mode.
Edit - updated css as per comments.
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>