Float images into overflow without wrapper div - css

I got some images into a div.
<div>
<img />
<img />
<img />
<img />
</div>
All images are set to the same height of 50px. The width is set to auto.
The question is, how do i get the images to float left into a horizontal line that reached into the parent div's overflow area. The parent div need a width of 100%.
I want to set the div to overflow-x: scroll. When the images are simply float: left they break into another line if they extend the divs width. But how can I get them into the overflow, so i have to scroll to see the others?
The main problem is that i can't use js or a wrapper div. The problem has to be solved with css.

Use white-space: nowrap; on the container div and display:inline on the img elements.
FIDDLE
<div>
<img src="http://placehold.it/350x50"/>
<img src="http://placehold.it/350x50"/>
<img src="http://placehold.it/350x50"/>
<img src="http://placehold.it/350x50"/>
</div>
div
{
white-space:nowrap;
overflow-x: auto;
}
img
{
display: inline;
margin-right: 10px;
}

TRY this.. i hope this one can help you.,
Cascsading Syle..
.float_l { float: left }
.float_r { float: right }
.col_w200 {
overflow: scroll;
height: 300px;
width: 200px;
}
.lp_frontpage { margin: 0; padding: 0; list-style: none }
.lp_frontpage li {
margin: 0;
padding: 0;
display: inline
}
.lp_frontpage li a {
float: left;
display: table;
width: 200px;
height: 100px;
margin: 0 10px 10px 0
}
.lp_frontpage li a img { width: 190px; height: 90px; border: 1px solid #3c4445; padding: 4px; }
HTML CODE..
<div class="col_w200 float_r">
<h2>Web Design Gallery</h2>
<ul class="lp_frontpage">
<li><img width="200" height="100" src="images/_01.jpg" alt="Image 01" /></li>
<li><img width="200" height="100" src="images/_image_02.jpg" alt="Image 02" /></li>
<li><img width="200" height="100" src="images/_03.jpg" alt="image 03" /></li>
<li><img width="200" height="100" src="images/_04.jpg" alt="image 04" /></li>
</ul>
</div>

Related

I am struggling to align three images in my header

I am trying to align three images in a header div. I need one image on the left - once centered - and an image on the right. I have the image on the left and the centered image in place. However, I cannot get the image I need on the right to display on the right of the centered image. If I float:left the centered image it messes up my centered image in various browsers. The image I want on the right displays on the left of the centered image. How do I get it on the right side of the centered image? Thank you very much.
Here is my code:
HTML:
<div class="header">
<div class="headerLeft">
<img src="salogo_lg.jpg"
width="105"
height="115"
alt="Salvation Army Logo" />
</div> <!-- closing tag of headerLeft-->
<div class="headerCenter">
<img src="logo85.jpg"
width="485"
height="93"
alt="Salvation Army" />
</div> <!-- closing tag of headerCenter -->
<div class="headerRight">
<img src="salogo_lg.jpg"
width="105"
height="115"
alt="Salvation Army Logo" />
</div> <!-- closing tag of headerRight -->
</div> <!-- closing tag of header -->
CSS:
.header{
width: 100%;
height: 115px;
background-color: #0B0B3B;
margin-bottom: -15px;
}
.headerLeft{
float: left;
width: 105px;
height: 115px;
}
.headerCenter{
display: inline-block;
margin-left: auto;
margin-right: auto;
width: 485px;
height: 93px;
}
.headerRight{
float: left;
text-align: right;
margin-left: 15px;
width: 105px;
height: 115px;
}
Quick answer :
*
{
box-sizing: border-box;
}
header
{
background: grey;
color: white;
padding: 1em;
position: relative;
height: 5em;
width: 100;
}
img
{
display: block;
height: 3em;
margin: auto;
}
img.right
{
position: absolute;
right: 1em;
top: 1em;
}
img.left
{
left: 1em;
position: absolute;
top: 1em;
}
<header>
<img src="http://25.media.tumblr.com/tumblr_m9gus8QYjY1rw0ggfo3_r5_400.gif" alt="" class="left" />
<img src="http://t1.gstatic.com/images?q=tbn:ANd9GcRBzTbPH8FRYR0HRqTmXnwSO4GgLbFO6rpALpwynKRr4SM_nTCywQQO6qvDcg" alt="" class="center" />
<img src="https://c2.staticflickr.com/4/3016/3071708735_ddaf5d361b.jpg" alt="" class="right" />
</header>
To avoid using position: absolute;, I'd recommend using calc to help out, and wrapping the .headerCenter in .headerCenterWrapper as I have below.
CSS:
.headerLeft {
width: 105px;
height: 115px;
display: inline-block;
}
.headerCenterWrapper {
width: calc(100% - 220px); /* Using a number slightly more than the sum of the side images' widths (210 px) to be safe */
height: 115px;
display: inline-block;
text-align: center;
}
.headerCenter {
width: 50px;
height: 115px;
display: inline-block;
}
.headerRight {
width: 105px;
height: 115px;
display: inline-block;
}
And the HTML:
<header class="header">
<img src="" alt="" class="headerLeft"/>
<div class="headerCenterWrapper">
<img src="" alt="" class="headerCenter" />
</div>
<img src="" alt="" class="headerRight" />
</header>
css
.headerLeft{
float: left;
width: 33.33%;
height: 115px;
}
.headerCenter{
margin-left: auto;
margin-right: auto;
width: 33.33%;
height: 115px;
float:left;
text-align:center;
}
.headerRight{
float: right;
width: 33.33%;
height: 115px;
text-align:right;
}
html
<div class="header">
<div class="headerLeft">
<img src="manish.png"
width="105"
height="115"
alt="Salvation Army Logo" />
</div> <!-- closing tag of headerLeft-->
<div class="headerCenter">
<img src="manish.png"
width="105"
height="115"
alt="Salvation Army" />
</div> <!-- closing tag of headerCenter -->
<div class="headerRight">
<img src="manish.png"
width="105"
height="115"
alt="Salvation Army Logo" />
</div> <!-- closing tag of headerRight -->
</div>

How do I align images in a row all vertically aligned in the middle no matter what height and with a fluid width?

I'm trying to create some fluid images that are aligned side by side but should also be vertically aligned in the middle no matter what there height dimensions are, I've set the images to have a max-width: 100% so they stay within their parents max-width so I can reduce these in size at smaller screen widths. My problem however is that I'm not sure of the best way to vertically align these images, can anyone advise?
CSS
.img-ctn {
display: inline-block;
margin-right: 3%;
max-width: 120px;
background: #cecece;
}
.img-ctn > img {
display: block;
height: auto;
max-width: 100%;
min-width: 100%;
vertical-align: middle;
}
Fiddle: http://jsfiddle.net/xmJ3R/
I think this is what you're asking for.
.container > div {
display: inline;
}
.container img {
max-width: 100%;
vertical-align: middle;
}
<div class="container">
<div>
<img src="http://lorempixel.com/100/75/" />
</div>
<div>
<img src="http://lorempixel.com/100/175/" />
</div>
<div>
<img src="http://lorempixel.com/100/25/" />
</div>
<div>
<img src="http://lorempixel.com/150/125/" />
</div>
</div>
And with your code.
* {
padding: 0;
margin: 0;
}
body {
padding: 20px;
}
.ctn {
width: 100%;
text-align: center;
}
.img-ctn {
display: inline;
margin-right: 3%;
max-width: 120px;
background: #cecece;
font-size: 0;
}
.img-ctn > img {
max-width: 100%;
vertical-align: middle;
}
<div class="ctn">
<p class="img-ctn">
<img src="http://dummyimage.com/80x65/000/fff" alt="" />
</p>
<p class="img-ctn">
<img src="http://dummyimage.com/100x30/000/fff" alt="" />
</p>
<p class="img-ctn">
<img src="http://dummyimage.com/70x10/000/fff" alt="" />
</p>
<p class="img-ctn">
<img src="http://dummyimage.com/30x40/000/fff" alt="" />
</p>
<p class="img-ctn">
<img src="http://dummyimage.com/50x65/000/fff" alt="" />
</p>
</div>
Try applying display:table-cell; to the image wrappers, then set padding:3%; instead of margin:
Demo:
http://jsfiddle.net/xmJ3R/
.img-ctn {
display: table-cell;
max-width: 120px;
background: #cecece;
vertical-align:middle;
padding:3%;
}
or set the margin on the images inside.

How can I style a list item to contain images without any gaps between them?

I'm trying to style a set of images contained within an unordered list so that:
The <ul> occupies the full width of the containing element
Each <li> occupies 25% of the width of the <ul>
The images contained in the <li>scale proportionately as the screen is resized
The 8 total images arrange in two stacked rows of 4 images each
There are no gaps, either vertically or horizontally, between the images
I can accomplish the first four objectives in the list above, but can't seem to lose the gap between the first and second row of images.
Here's the markup:
<div class="container">
<ul>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
<li><img src="http://davidangerer.com/i/sample.jpg" alt="Image Description" /></li>
</ul>
</div>
And the (post-reset) CSS:
.container {
width: 90%
max-width: 960px;
margin: 6em auto;
}
.container ul {
float: left;
display: block;
width: 25%;
height: auto;
}
.container img {
max-width: 100%;
height: auto;
width: auto\9; /* fixes a bug in ie8 */
}
Thanks in advance for any help you can provide.
Cheers,
David
You will have to set display:block; on the images and the lis to avoid that ugly inline margin between them. Check out this working jsFiddle
.container img {
display:block;
max-width: 100%;
height: auto;
width: auto\9; /* fixes a bug in ie8 */
}
.container ul li{ display:block; }
image are inline-boxes and stands on baseline (defaut value : vertical-align:baseline;). This explains the gap underneath. you can either fix it like:
.container img {
max-width: 100%;
height: auto;
width: auto\9; /* fixes a bug in ie8 */
vertical-align:top;
}
or
.container img {
max-width: 100%;
height: auto;
width: auto\9; /* fixes a bug in ie8 */
vertical-align:bottom;
}
or make your inline-boxe into a block-boxe
.container img {
max-width: 100%;
height: auto;
width: auto\9; /* fixes a bug in ie8 */
display:block;;
}

css alignment list inside div

I'm having lots of problem aligning an image on CSS.
Here is the thing, I have a div called "toggle" inside this div I have a list ul - li on each li I have text and then 3 images, but I want to have the Images aligned some how the alignment of the images are relative to the text not to the left padding.
http://aluna.webdcg.com/visistat/
Maybe this is what you need. See code in action at: http://jsfiddle.net/67VWe/
CSS:
* { font-family: Tahoma; }
ul { width: 200px; margin: 20px; border: 1px solid #777; }
li { padding: 2px; border-bottom: 1px dotted #777; }
li label { width: 120px; float: left; }
​
HTML:
<div id="toggle">
<ul>
<li><label>Text 1</label> <img src="http://admin.visistat.com/sales/img/icon-pulse-dot-red.png" width="22" height="22" /></li>
<li><label>Text 1234</label> <img src="http://admin.visistat.com/sales/img/icon-pulse-dot-red.png" width="22" height="22" /></li>
<li><label>Text 1234567</label> <img src="http://admin.visistat.com/sales/img/icon-pulse-dot-red.png" width="22" height="22" /></li>
</ul>
</div>
--
The label tag, width, and float values did the trick.

scrollbar inside fixed div

I have a fixed div and need the content to be able to be scrolled when its width exceeds the window size. I need this div with position: fixed because it's next to a column with display: none, and if I float it or position it in any other way it will take up the space of that hidden column. So the problem is I can't make the scroll work within this div. It's a pretty big CSS so I'll post what I think is relevant.
CSS
#main {
background-color: yellow;
height: 100%;
overflow: auto;
position: fixed;
top: 10px;
left: 380px;
}
#container {
background-color: red;
height: auto;
margin-left: 20px;
width: 700px/*655px*/;
overflow: auto;
}
#tabs {
background-color: blue;
float: left;
height: 100%;
margin-top: -187px;
margin-left: 20px;
width: 500px/*50%*/;
}
ul#slider {
height: 350px;
list-style: none;
margin: 0px;
padding: 0px;
width: 700px;
overflow: hidden;
position: relative;
}
ul#thumb {
background-color: #000;
list-style: none;
margin: 0 0 0 500px;
width: 200px;
position: relative;
overflow: auto;
/*overflow: hidden;*/
}
ul#thumb a {
border: 1px solid #bfbfbf;
display: block;
float: left;
height: 40px;
margin: 10px 0 10px 24px;
width: 40px;
opacity: 0.75;
overflow: hidden;
}
And the HTML:
<div id="main">
<div id="container">
<ul id="slider">
<li id="1"><img src="img/img01.jpg" alt="img01" width="700" height="350" /></li>
<li id="2"><img src="img/img02.jpg" alt="img02" width="700" height="350" /></li>
<li id="3"><img src="img/img03.jpg" alt="img03" width="700" height="350" /></li>
<li id="4"><img src="img/img04.jpg" alt="img04" width="700" height="350" /></li>
</ul>
<ul id="thumb">
<li><img src="img/img01.jpg" alt="img01" width="50" height="50" /></li>
<li><img src="img/img02.jpg" alt="img02" width="50" height="50" /></li>
<li><img src="img/img03.jpg" alt="img03" width="50" height="50" /></li>
<li><img src="img/img04.jpg" alt="img04" width="50" height="50" /></li>
</ul>
<img id="title" src="img/title.jpg" width="119" height="61" alt="" />
<div id="tabs">
<div class="verticalslider" id="text">
<ul class="verticalslider_tabs">
<li>Tab 01</li>
<li>Tab 02</li>
<li>Tab 03</li>
<li>Tab 04</li>
</ul>
<ul class="verticalslider_contents">
<li>
<table>
<tr><td>Description tab 01</td></tr>
</table>
</li>
<li>
<table>
<tr><td>Description tab 02</td></tr>
</table>
</li>
<li>
<table>
<tr><td>Description tab 03</td></tr>
</table>
</li>
<li>
<table>
<tr><td>Description tab 04</td></tr>
</table>
</li>
</ul>
</div>
</div>
</div>
The "container" div is the one that needs to be scrolled when resizing the browser window (I'm working with Opera and FF) but so far the content on the right just disappears and there's no way to see it. The vertical scrollbar doesn't show either but if I use the mouse wheel I can scroll down.
It's a big code and I've tried many combinations already but I'm starting to go in circles. It's probably an easy answer but It this point I can't figure it out so an outsider perspective will help.
I need this div with position: fixed
because it's next to a column with
display: none, and if I float it or
position it in any other way it will
take up the space of that hidden
column.
Hiding an element while preserving its size can be accomplished with a visibility: hidden style.

Resources