I have the following Html and CSS Fiddle Example:
<div>
<i class="fa fa-yelp"></i>
<h2>Help</h2>
<p>This is some text which I want to be on the right side of span</p>
</div>
div {width: 200px;}
i {
font-size: 48px!important;
float: left;
}
h2 {float: left;}
p {float: left;}
I need that h2 and p to be on a same column on the right of the i tag.
I am using floats but no luck. How can I do this without tables?
Have you tired giving margin to the paragraph?
p {float: left;
margin-left:20px;
margin-top:0px}
** UPDATE **
Fiddle: http://jsfiddle.net/847ndaap/13/
In this example I am floating the left div only, and letting the right div fall into place, but giving it a padding that matches the size of your left floated div (48px). Works like a charm. I am also using min/max-width to allow the responsive bits to work.
New CSS:
.main{
max-width: 200px;
overflow: hidden;
}
.left{
float: left;
width: 48px;
}
.left i{
font-size: 48px!important;
}
.right{
padding-left: 48px;
max-width: 152px;
}
-
-
OLD:
So what you need to do is give yourself a container to hold your inner floated content. Then use 2 divs inside, a left and right. The left will contain your icon and the right will contain your content. Floats nest if you don't contain them - you will also need to specify width of each side so don't forget that. You will need to use a clearfix on your main container - in this example I am using a basic overflow hidden fix.
Fiddle: http://jsfiddle.net/847ndaap/10/
New HTML:
<div class="main">
<div class="left">
<i class="fa fa-yelp"></i>
</div>
<div class="right">
<h2>Help</h2>
<p>This is some text which I want to be on the right side of span</p>
</div>
</div>
New CSS:
.main{
width: 200px;
overflow: hidden;
}
.left{
float: left;
width: 48px;
}
.left i{
font-size: 48px!important;
}
.right{
width: 152px;
float: left;
}
Related
Im trying to use margin: auto; at the same time as i'm using the display: inline-block; css. Before i'm putting in the inline-block code it worked fine and the div was centered using margin auto. But now its not working anymore.
I want the Divs logo and contact_info to be inline and the div .inner to be centered.
.inner {
width: 80%;
display: inline-block;
margin: auto;
padding-top: 40px;
padding-bottom: 40px;
}
.logo {
float: left;
}
.contact_info {
float: right;
}
HTML CODE
<div class="inner"> <!-- Top header -->
<div class="logo">
Logga här
</div>
<div class="contact_info">
<h4> Vikbo Bil & Motor AB </h4>
<p> Ekkällavägen 6 </p>
<p> 610 24 Vikbolandet </p>
<p> 0125 500 71 </p>
</div>
</div>
Remove inline-block from .inner class.
display: inline-block;
makes an element well..inline. meaning it only takes as much space as it's width, and allows other inline elements to take the remaining space in the page if they can fit in.
what you want, is to create the .inner div a block element, which, even though there might be extra space after the div has taken the space for it's own width, won't let any other element take up that space. meaning, it'll be the only element in that row.
so you can use margin: auto to make it center.
I see you've used float placement on logo and contact_info meaning they'll not be fitting in the div.inner. you should use display: inline-block on these divs, so they inline and inside the div.inner.
see if this fiddle satisfies all your needs?
Just remove the inline-block property on your "inner" div :
.inner {
width: 80%;
margin: auto;
padding-top: 0;
padding-bottom: 40px;
background: blue;
}
.logo {
float: left;
background: red;
}
.contact_info {
float: right;
background: green;
}
<div class="container">
<div class="logo">logo</div>
<div class="contact_info">contact_info</div>
<div class="inner">inner</div>
</div>
You can do problem solve using this code
.inner{
width:100%
margin:0 auto;
display: block;
height: 100px;
}
.logo{
display:inline-block;
width:auto;
}
.contact_info{
display:inline-block;
width:auto;
}
I have in div two divs with floats (left and right). In right div there are paragraphs. All that two divs have inline-block display. If paragraphs in right div too long, then right div jump over the left, and set to display block.
I'm want to paraghraps do new line if it too long.
Code:
.left {
margin: 30px;
float: left;
display: inline-block;
}
.right {
float: left;
margin-top: 30px;
}
.right p {
margin: 10px;
font-weight: 900;
}
<div class="box_container">
<div class="left">
<img src="{url}">
</div>
<div class="right">
<p>p1</p>
<p>p2</p>
<p>p3</p>
<p>p4</p>
<p>p5</p>
</div>
</div>
When text in paragraph too long:
.left {
margin: 30px;
float: left;
display: inline-block;
}
.right {
float: left;
margin-top: 30px;
}
.right p {
margin: 10px;
font-weight: 900;
}
.left img {
border: 5px solid white;
}
<div class="box_container">
<div class="left">
<img src="http://monitorgame.com/m/games/001.jpg">
</div>
<div class="right">
<p>p1</p>
<p>p2</p>
<p>p3</p>
<p>p4</p>
<p>p5 text text text text text text lalalalalalalalalalalallalalallalalalala</p>
</div>
</div>
You should allocate space for them. I like using floats in these instances, so for example you could add float:left width: 50% to each one, something like that.
.left {
margin: 30px;
float: left;
width: 50%;
}
.right {
float: left;
width: 50%
margin-top: 30px;
}
You already had the float, you just needed to specify the width. They could be static too not % if you want, but if the static sizes don't fit in the screen they will break like your example.
see working here : https://jsfiddle.net/3LtLuxbc/3/
Just a note on the fiddle - I changed your img size to with 100% and removed the border so it would scale , you can change that to suit your design.
Add a width to the right div. This will force the text to wrap. Without a specified width, div will increase in size until reaching max size of wrapper div or page
I haven't used CSS quite often. I always get stuck even when it get's to the simplest layout questions. Even though I am reading a book I cannot figure out how the following works:
I want to design a website which has a header on top, then menu bar and then content. Menu bar and content are working quite good. But I want to have a header with some header text on the left and a logo on the right.
So I have taken this approach:
<div id="headline">
<div id="headertext">Some title<br/>some more title text</div>
<div id="logo"><img src="somelogo.png" /></div>
</div>
And for the CSS:
#headline { overflow: hidden;
height: 224px;
text-align: left;
padding: 0px 80px 0px 80px;
}
#headertext { font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 20pt;
color: #000000;
float: left;
font-weight: bold;
}
#logo {
float: right;
}
So I made the text on the left float: left and the logo on the right float: right. So far so good. Now I want to align both elements to the vertical middle of the parent <div> that has a certain height.
This is what I want it to look like (the blue rectangle is the logo):
I have tried using vertical-align: middle but this does not work out. I have also stumbled across display:table-cell and display: inline but I must have used it in a wrong way or it also does not work. Do I have to use another "wrapper" <div> inside the headline element?
Edit: thanks for the hint about fiddle; I tried to edit one: http://jsfiddle.net/f5vpakdv/
Thank you for your help!
You can achieve this using display: table and display: table-cell, together with vertical-align: middle.
I've removed some irrelevant bits from your original CSS to make it easier to see what's different.
To make it work perfectly after you add padding or margin, check this link: Box Sizing | CSS-Tricks.
<div id="headline">
<div id="headertext">
Some title<br/>some more title text
</div>
<div id="logo">
<div id="fakeImg"></div>
</div>
</div>
...
#headline {
width: 100%;
height: 224px;
background: yellow;
display: table;
}
#headertext {
text-align: left;
}
#headertext,
#logo {
display: table-cell;
width: 50%;
vertical-align: middle;
}
#fakeImg {
width: 100px;
height: 100px;
background: blue;
float: right;
}
Demo
You can use some CSS to accomplish this. Also check for vendor-specific transforms.
.vertical-center {
position: relative;
top: 50%;
transform: translateY(-50%);
}
Here is a fiddle, and I added another div wrapper.
http://jsfiddle.net/5o3xmfxn/
Updated version of your fiddle:
http://jsfiddle.net/f5vpakdv/1/
I have updated your fiddle here. I simply added display:table; to your wrapping div and gave both inner divs a style of:
display:table-cell;
vertical-align:middle;
I also made a version using flexbox here
I just added the following styles to your wrapping div:
display:flex;
align-items:center;
justify-content:space-between;
I would go for something easier like this. Just put wrapper around the content that you want to center and use a margin-top: http://jsfiddle.net/f5vpakdv/2/
<div id="headline">
<div id="wrapper">
<div id="headertext">Some title some
<br/>more title text</div>
<div id="logo"><img src="somelogo.png" width="198px" height="120px" />
</div>
</div>
</div>
CSS
#wrapper {
margin-top: 60px;
}
I am trying to centre the middle circle but I am unable even when set to margin: 0 auto; and display: inline-block; or display table. Any suggestions?
JSFiddle
HTML
<div id="intro">
<p class="body">As part of Science World’s Cycle Safe Initiative we have installed sensors at each of our gates. In the past year we have had over <b>300,000</b> people ride along. Some information we gathered for June included;</p>
<span class="blue circle">
<h3>2 - 3PM</h3>
<p>is the busiest hour</p>
</span>
<span class="green circle">
<h3>117,295</h3>
<p>riders this month</p>
</span>
<span class="navy circle">
<h3>10%</h3>
<p>of Vancouverites*</p>
</span>
</div>
CSS
#intro {
max-width: 1080px;
margin: 0 auto;
}
#intro .circle {
min-width: 230px;
min-height: 230px;
display: inline-block;
text-align: center;
border-radius: 1000px;
color: white;
margin: 60px 0;
}
#intro .circle h3 {
margin-top: 80px;
margin-bottom: 0;
font-size: 2.2em;
}
#intro .circle p {
margin-top: 0;
}
#intro .circle.blue {
background: #0079c8;
}
#intro .circle.green {
background: #2ecc71;
}
#intro .circle.navy {
background: #34495e;
float: right;
}
Add text-align:center to the #intro (as your inner content acts like inline) and add float:left to your #intro .circle.blue.
Example
Only block-level elements can be centered with margin:0 auto.
You can probably achieve the effect you want in other ways, though.
See this updated version of your jsfiddle for a solution via adding the following CSS to your middle circle:
position:absolute;
left:50%;
margin:-115px;
(Note that the negative margin-left must be equal to half the element's width to make it appear centered using this solution.)
I have updated your code: http://jsfiddle.net/h9HGG/6/
The trick is to put each circle centered inside a div which is set to "display:table-cell". Then wrap all the circle inside a container which is set to "display:table".
example:
<div class="wrapper"> <!--display: table, width: 100%, table-layout: fixed -->
<div class="circle-container"> <!--display: table-cell, text-align: center -->
<!--circle 1-->
</div>
<div class="circle-container"> <!--display: table-cell, text-align: center -->
<!--circle 2-->
</div>
<div class="circle-container"> <!--display: table-cell, text-align: center -->
<!--circle 3-->
</div>
</div>
I'm not sure this is going to work for you - FIDDLE
I put the circles in divs, floated them left, align: center, and gave each one a width of 33%.
They are flexible, and even overlap when the screen is moved horizontally (not sure if that works for you).
CSS
.centerme {
float: left;
width: 33%;
text-align: center;
}
I want to create two divs beside each other, however I want the one on the left side to be 300px, and the right one to take up the remaining amount on the screen. How would that be possible? Thanks!
The most straight-forward (and I would say correct) way is to use display: table:
#wrapper {
display: table;
width: 100%;
}
#left, #right {
display: table-cell;
color: white;
}
#left {
background: blue;
width: 300px;
}
#right {
background: red;
}
<section id="wrapper">
<aside id="left">Left 300px</aside>
<div id="right">Right the rest</div>
</section>
http://jsfiddle.net/YbLZE/1/
Try resizing the bottom right frame.
Updated with HTML5 elements section and aside, which you should use if you have an HTML5 doctype. I have to remember to use those...
This is the working example:
http://jsfiddle.net/tnm62/
Explenation:
1. Place both elements in one container.
2. Position your left element absolute, set its width to 300px.
3. Set left margin to your right element to 300px.
One solution is to float: left; the left div that's 300px wide, and then apply overflow: hidden; to your right div. Here's the basic outline:
HTML:
<div class = "left">
Glee is awesome!
</div>
<div class = "right">
Glee is awesome!
</div>
CSS:
.left {
width: 300px;
float: left;
}
.right {
overflow: hidden;
}
And a little demo: little link.
Here's something for newer browsers (not IE):
CSS:
#container {
display: box;
}
#left {
width: 400px;
}
#right {
box-flex: 1;
}
HTML:
<div id="container">
<div id="left">Left</div>
<div id="right">Right</div>
</div>
Demo: http://jsfiddle.net/N5zhH/1/
This should be sufficient:
<div style="overflow: hidden;">
<div style="width: 300px; float: left;"></div>
<div style="margin-left: 300px;"></div>
</div>
overflow: hidden will stretch the container div to accommodate the tallest child element
float: left floats the element left (doh!)
width: 300px and margin-left: 300px together assures that if the right column is taller than left it will not flow below the left floated div; it will maintain a 300x gap from the left edge of container div
Tip: change to margin-left: 320px to add a 20px gutter
Here is a nice little DEMO