Here is my code:
<style type="text/css">
div.page {
text-align:center;
border: 1px solid rgb(0,0,0);
width:20px;
height:20px;
}
span.page {
text-align:center;
border: 1px solid rgb(0,0,0);
width:20px;
height:20px;
}
</style>
<div class="page">1</div>
<div class="page">2</div>
<div class="page">3</div>
<span class="page">1</span>
<span class="page">2</span>
<span class="page">3</span>
Div's look fine but they places vertically. Is there any way to place them horizontally in one line?
Span's place in the one line, but the span can not have the width as any inline element.
If there is no way to use DIV's and SPAN's for my task I will use a table, but I am looking for the no-table solution.
xandy is correct, but this is better:
<div class='pageHolder'>
<div class='page'>1</div>
<div class='page'>2</div>
<div class='page'>3</div>
</div>
with CSS:
.page {
text-align:center;
border: 1px solid rgb(0,0,0);
width:20px;
height:20px;
float: left;
}
.pageHolder{
overflow: auto;
width: 100%;
}
Elements to clear floats is markup. It's like using <br> but for floats. Mixing markup and content is considered bad practice in semantic web.
Read this article for more information.
Use
display:inline-block
in the div's style
Lorenzo's answer is correct, but I would add something to the markup:
<div class='pageHolder'>
<div class='page'>1</div>
<div class='page'>2</div>
<div class='page'>3</div>
<div class='pageHolder-footer'></div>
</div>
in CSS, add:
div.pageHolder-footer{
clear: left;
height: 0;
}
So that the rest of your stuff will flow correctly.
==Alternative method (From Jan, and SitePoint) ==
No need to have the div.pageHolder-footer (but keep pageHolder). And then:
div.pageHolder { overflow: auto; } /* Jans' method */
/* or */
div.pageHolder { overflow: hidden; } /* From SitePoint */
They both may have drawbacks, but it depends on what you need.
use display:inline; and your div's will be in one line.
other solution : float:left;
Use this
div.page {
text-align:center;
border: 1px solid rgb(0,0,0);
width:20px;
height:20px;
float: left;
}
Use display: table-cell; It will solve your issue of div alignment in horizontal order.
<div class="content">
<div> Page1</div>
<div>Page 2</div>
<div>Page 3</div>
</div>
CSS
.content > div{
display: table-cell;
}
You can try out with the combination of ul/li with list-style ( css property ) as none.
some thing like
<ul> <li> <div ....</li> <li><div...></li></ul>
or
you can try within table / tds inside divs.
Related
Hi im trying to set some divs inline and i dont know what else to do.
.menuboton{
display:inline;
padding:0.7em;
border-radius: 4px;
background-color: #093;
}
.menu{
display:inline;
margin-right:4em;
}
There are two classes, first are 4 divs and the another is one div with an <img> inside. Those divs are inside another div:
#elmenu{
margin:auto;
margin-bottom:10px;
width:100%;
border-top:1px solid black;
border-bottom:1px solid black;
}
This is my problem: the 4 divs always are slightly below the one with the <img> inside and cross over the container div (elmenu). For fix that I tried setting it display:inline-block and fix the problem of exceds the container limit but still below the one with <img> inside.
Here the html code:
<div id="elmenu">
<div class="menu" id="logo"><img id="imglogo" src="psds/logo.png" /></div>
<div class="menuboton">Inicio</div>
<div class="menuboton">Posts</div>
<div class="menuboton">Login</div>
<div class="menuboton">Usuario</div>
</div>
Pics:
Using display:inline;
Using display:inline-block;
I want all divs stay at the same level!
Some guess?
Place the Knowit image in left and the menu in right and edit widths accordingly.
HTML:
<div class='container'>
<div class='left'></div>
<div class='right'></div>
</div>
CSS:
.container { overflow: hidden; margin:0; padding:0; }
.left{ float: left; width: 150px; }
.right { float: right; width: 150px; text-align:left; }
Edit on OP request:
To center object within div class use:
text-align:center;
to center align the div container use:
margin: 0 auto;
All this information can be found at http://w3schools.com/
You should try to use span instead of div. Also use float:left
vertical-align: middle on #elmenu should do the trick along with display: inline-block; on the logo and menu items.
first you should build your menu from a list or a nav tag.
Inline-block is a good idea, you can easily size and align your elements.
To build your menu you need:
inline-boxes
text-align:center.
line-height
float (just once)
First element (holding logo for instance) can float left.
set a line-height to size (min-)height of the nav bar.
here we come to this : http://jsfiddle.net/GCyrillus/CaR7a/
.menuboton {
display:inline-block;
padding:0.7em;
border-radius: 4px;
background-color: #093;
line-height:1.2em;
}
.menu {
float: left;/* logo */
}
#elmenu {
padding:0;
margin:0;
list-style-type:none;
line-height:48px;/* logo's height */
text-align:center;
border-top:1px solid black;
border-bottom:1px solid black;
}
a {
color:white;
text-decoration:none;
}
<ul id="elmenu">
<li class="menu" id="logo"><img id="imglogo" src="http://placehold.it/1&1" /></li>
<li class="menuboton">Inicio</li>
<li class="menuboton">Posts</li>
<li class="menuboton">Login</li>
<li class="menuboton">Usuario</li>
</ul>
I hope it is useful
Like my comment, the Css should like this
.menuboton{
float: left;
padding:0.7em;
border-radius: 4px;
background-color: #093;
}
.menu{
float: left;
margin-right:4em;
}
UPDATE:
HTML:
<div id="elmenu">
<div class="menu" id="logo"><img id="imglogo" src="http://www.winphoneviet.com/forum/data/avatars/l/35/35914.jpg?1370081753" /></div>
<div class="menuboton">Inicio</div>
<div class="menuboton">Posts</div>
<div class="menuboton">Login</div>
<div class="menuboton">Usuario</div>
<div style="clear: both;"></div>
</div>
This's Fiddle
I have a strange situation, where my middle div is slightly downward.
Here's a screenshot:
HTML :
<div id="footer">
<div class="content">
<div id="info1">
<img src="img/temp.png" alt="About me" />
<h4>About Me</h4>
<p>this is about me section</br>and this is the other line</br>and this is a third line</p>
</div>
<div id="info2">
<h4>Random Photos</h4>
<div id="randomPhotos"></div>
</div>
<div id="info3">
<h3>Follow Me</h3>
<div>
<img src="img/temp.png" alt="facebook" />Facebook
</div>
<div>
<img src="img/temp.png" alt="twitter" />Twitter
</div>
<div>
<img src="img/temp.png" alt="email" />E-mail
</div>
</div>
</div>
</div>
CSS:
#info1, #info2, #info3
{
padding: 10px;
display:inline-block;
}
#info1
{
width:20%;
}
#info1 img
{
margin-right:3px;
width:20px;
height:20px;
background-image:url('../img/glyphicons-halflings.png');
background-repeat:no-repeat;
background-position:-162px 1px;
}
#info1 img, #info1 h4
{
display:inline-block;
}
#info2
{
width:55%;
border-left:1px solid gray;
border-right : 1px solid gray;
}
#info3
{
width:15%;
}
#info3 img
{
width:20px;
height:20px;
margin-right:5px;
}
#info3 img[alt="facebook"]
{
background : url('../img/result.png') no-repeat 0px -30px;
}
#info3 img[alt="twitter"]
{
background : url('../img/result.png') no-repeat 0px -60px;
}
#info3 img[alt="email"]
{
background : url('../img/result.png') no-repeat 0px 0px;
}
#info2 div
{
padding:3px;
}
#randomPhotos
{
height : 100px;
}
I'm really not that good at CSS, so it maybe a small problem. I just can't find it out.
Most browsers, for elements using display:inline-block will automatically use vertical-align:baseline on that element unless you use a CSS reset (that will probably also define the defacto standard as vertical-align:baseline.)
This is the reason for what you are seeing, each one of your info divs is aligning to the baseline. As the central div is smaller height wise you get the gap you are seeing at the top.
To fix it:
#info1, #info2, #info3
{
padding: 10px;
display:inline-block;
vertical-align:top;
}
The second problem you will probably encounter is that now it is aligned top, you have a 'gap' at the bottom with no left or right borders. Either have the borders managed by the full height divs or make all the divs the same height.
I suggest you to add float: left to each of your divs. This solve your problem.
example
You could also try to
position:absolute;
the divs inside the container and then specify
top:0px;
left: (left div with)px;
I am always working with absolute, hope it helps.
#info2
{
vertical-align: top
}
should do the trick.
I appear to have a peculiar problem.
I've got the following code snippet and as you can see i've just added the footer div at the end:
<body>
<div id="conainer">
<div id="wrapper">
<p>this is the wrapper</p>
<div id="centerDoc">
<p>this is the centerDoc</p>
</div> <!--centerDoc !-->
</div> <!-- wrapper !-->
</div> <!--container !-->
<div id="footer">
<p>footer</p>
</div>
</body>
I get the follwing output [I added borders to see whats going on]:
I hope you can see that the centerDoc div is inside the footer div and i don't understand why.
CSS for divs:
#container {
margin:auto;
width: 100%;
}
#wrapper{
width:80%;
border:1px dashed black;
}
#centerDoc {
margin-top:2.8%;
margin-left:10px;
float:left;
width: 100%;
border:1px dashed black;
}
#footer{
text-align:center;
color:#333333;
border:1px dashed black;
}
Any pointers to sort this out is appreciated!
That is normal behavior. Your #centerDoc division is floated left, so it's position is correct. However, because it's floated, it's removed from the flow of the document, so it's not included in the height of the wrapper division and the footer division fills in behind it, then the text moves down so that it's not behind other content.
#animuson is right. you may use "clear: both;" to fix it. see below
<pre>
#footer{
text-align: center;
color: #333333;
border: 1px dashed black;
clear: both;
}
</pre>
Is it possible to make a nested structure of divs
<div>Content1
<div>Content2
<div>Content3</div>
</div>
</div>
to look like divs with fixed width that float left?
<style>
div {
float: left;
width: 200px;
}
</style>
<div>Content1</div>
<div>Content2</div>
<div>Content3</div>
I guess you can't do it with CSS. It's a language for defining the style of elements, not for modifying their structure. You could think about jQuery or XSLT for your case.
you can use margin-top property to get this effect
<div style="width:100px;height:100px;border:1px solid black">
<div style="width:100px;height:100px;border:1px solid green;margin-top:100px">
</div?
</div?
Actually you don't need to do anything really, this is the default behavior for block level elements.
Try to create a blank html page and insert the lines
<div>Content1
<div>Content2
<div>Content3</div>
</div>
</div>
Without any form of styling the output will be:
Content1
Content2
Content3
Which is what you are asking for
I guess I figured how to do that with a bit of additional html and absolute positioning:
<div id="parent">
<div class="nest">
<div class="content">One</div>
<div class="nest">
<div class="content">Two</div>
<div class="nest">
<div class="content">Three</div>
</div>
</div>
</div>
</div>
//css:
#parent {
position: relative;
}
div.nest {
position:absolute;
width: 200px;
top: 0;
left: 200px; /*should be same as width */
/* the next is the tricky part */
margin: 0px;
padding: 0px;
border: 0px;
}
/* apply custom border, padding and margin here */
div.content {
border: 1px solid #ccc;
padding: 8px;
margin: 4px;
}
Color me noobish, but couldn't you achieve something similar with an unordered list, since you're looking to nest elements? (http://jsfiddle.net/xDJAY/) Not sure if this is the structure you're looking for though.
I'm working on a album viewer. At the top I want a horizontal container of all the image thumbnails. Right now all the thumbnails are wrapped in a div with float:left. I'm trying to figure out how to keep these thumbnails from wrapping to the next line when there are too many, but rather stay all in one horizontal row and use the scrollbar.
Here's my code:
(I don't want to use tables)
<style type="text/css">
div {
overflow:hidden;
}
#frame {
width:600px;
padding:8px;
border:1px solid black;
}
#thumbnails_container {
height:75px;
border:1px solid black;
padding:4px;
overflow-x:scroll;
}
.thumbnail {
border:1px solid black;
margin-right:4px;
width:100px; height:75px;
float:left;
}
.thumbnail img {
width:100px; height:75px;
}
#current_image_container img {
width:600px;
}
</style>
<div id="frame">
<div id="thumbnails_container">
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/glry-pixie-bob-kittens.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-KitJan08-1.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-KitJan08-3.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-Jan08.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/gallery3.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/gallery4.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/Gallery-Pics/kitten3.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/Gallery-Pics/kitten1.jpg" alt="foo" /></div>
</div>
<div id="current_image_container">
<img src="http://www.whitetailrun.com/Pixiebobs/PBkittenpics/shani-kits/Cats0031a.jpg" alt="foo" />
</div>
</div>
How about using display: inline-block this way you can use borders on the block elements and get the horizontal scroll bar.
#thumbnails_container {
height:75px;
border:1px solid black;
padding:4px;
overflow-x:scroll;
white-space: nowrap
}
.thumbnail {
border:1px solid black;
margin-right:4px;
width:100px; height:75px;
display: inline-block;
}
Did you try
white-space: nowrap;
in your #thumbnails_container?
Instead of floating, try this:
#thumbnails_container {
height:75px;
border:1px solid black;
padding:4px;
overflow-x:scroll;
overflow-y: hidden;
}
.thumbnail {
border:1px solid black;
margin-right:4px;
width:100px; height:75px;
display: inline;
}
Remove the div { overflow:hidden; }, the rest stays the same.
It's a bit simpler and they'll span across and scroll like you want.
It is a common mistake thinking that setting the white-space property to "nowrap" also works on floated elements.
It only works on inline elements or inline-block elements.
I guess you need the floated elements to be a block, so you could turn them into inline blocks.
It is possible to gain it on all the browsers with some trick:
display: -moz-inline-stack;
display: inline-block;
zoom: 1;
*display: inline;
This solution opens a lot of new web-design sceneries to be explored, so I gratefully give the proper credits to the author:
http://foohack.com/2007/11/cross-browser-support-for-inline-block-styling/
Here you can read a document which speaks of the white-space property and the floated elements:
http://reference.sitepoint.com/css/white-space
Cheers!
This is driving me nuts, can't figure it out.
This kinda works:
.thumbnail {
padding-right:4px;
width:100px; height:75px;
display: table-cell;
}
.thumbnail img {
border:1px solid black;
display: block;
width:100px; height:75px;
}
But I have no idea about browser support for display: table-cell;
Personally i would either make the thumbs vertical or use javascript (the browser scrollbar is ugly anyways)
I had the same problem a few months ago. I tried all solutions presented here. They don't work.
This is my solution:
Give the wrapper div the needed width fix (body will expand, too). Then put the content in the extra large wrapper container (float or inline). Now you can use the horizontal scrollbar of the window as scrollbar. Now everything else on the page (header, footer etc.) is scrolling with. You can give these containers position:fixed. Now they stay on there position, while you are scrolling the extra wide wrapper/body.
I would still prefer to be able to use block elements for the thumbnails tho so I can add borders and what not.
You can use "borders and whatnot" with display: inline-block elements. You can also use fixed with/height inline-block elements, so that your design is consistent.
Basically, make .thumbnail not-floated and display: inline-block, apply width/height, borders etc., and on #thumbnails_container use white-space: nowrap.
Add another container for the thumbnails and set it's width to the total width of all thumbnails (along with their margins, borders and padding). Look below at div named "thumbnails_scrollcontainer":
<style type="text/css">
div {
overflow:hidden;
}
#frame {
width:600px;
padding:8px;
border:1px solid black;
}
#thumbnails_container {
height:75px;
border:1px solid black;
padding:4px;
overflow-x:scroll;
}
.thumbnail {
border:1px solid black;
margin-right:4px;
width:100px; height:75px;
float:left;
}
.thumbnail img {
width:100px; height:75px;
}
#current_image_container img {
width:600px;
}
</style>
<div id="frame">
<div id="thumbnails_container">
<div id="thumbnails_scrollcontainer" style="width : 848px;">
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/glry-pixie-bob-kittens.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-KitJan08-1.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-KitJan08-3.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-Jan08.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/gallery3.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/images/gallery4.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/Gallery-Pics/kitten3.jpg" alt="foo" /></div>
<div class="thumbnail"><img src="http://www.blueridgexotics.com/Gallery-Pics/kitten1.jpg" alt="foo" /></div>
</div>
</div>
<div id="current_image_container">
<img src="http://www.whitetailrun.com/Pixiebobs/PBkittenpics/shani-kits/Cats0031a.jpg" alt="foo" />
</div>
</div>
I know this is an old question now but this came up in a google search. I was trying to change a floated layout into a horizontal scrolled layout on mobile. None of the above worked for me. Instead I used the below which worked in my case:
main
{
display: flex;
max-width: 100%;
overflow-x: auto;
}
main .thumbnail
{
width: 400px;
flex-shrink: 0;
}
This way worked for me
main #thumbnailBox {
height: 154px;
width: auto;
overflow-x: scroll;
white-space: nowrap;}
main .thumbnail {
display: inline-block;}