I'm trying to display images horizontally using CSS - html

I have a series of images I would like to display horizontally on my website, using CSS and divs. I've looked at several posts about how to display images horizontally already and I wasn't able to get any of them to work.
Here's the code from the page I'm referring to:
<head>
<link rel=StyleSheet href="style.css" type="text/css" media=screen>
<style>
div.imageBox {
float: left;
margin-right: 10px;
}
div.imageBox p {
text-align: center;
}
</style>
</head>
<body>
<?php include 'header.php'; ?>
<div id="content">
<div id="container">
<div class="imageBox">
<img src="image" width="800" height ="600">
</div>
<div class="imageBox">
<img src="image" width="600" height ="450">
</div>
<div class="imageBox">
<img src="image" width="800" height ="450">
</div>
</div>
</div>
</body>
and here's the code for the style sheet:
body{
font-family: helvetica, arial, sans-serfif;
font-size: 14px;}
div#menu {
display: inline;
text-align: center;
width: auto;
top: 20px;
margin-left: 10%;
margin-right: 10%;
background: transparent;
height: 10px;
position: fixed;
}
div#menu ul {
margin: 0;
display: block;
}
div#menu ul li {
padding-right: 55px;
display: inline;
}
div#content {
padding-top: 40px;
text-align: center;
}
div#container{
float: left;
display: inline;
height: 800px;
width: 0px;
}
a:link {
text-decoration: none;
color: #000;
}
a:active {
text-decoration: none;
color: #000;
}
a:visited {
text-decoration: none;
color: #000;
}
a:hover {
text-decoration: underline;
color: #000;
}
Is there perhaps an easier way for me to do this?
Thanks for your help!

Try to change
div#container{
float: left;
display: inline;
height: 800px;
width: 0px;
}
into
div#container{
float: left;
display: inline;
height: 800px;
white-space: nowrap;
}

add:
div.imageBox {
float: left;
margin-right: 10px;
display:inline;
}
You're using divs which are block elements when you should be using something inline.

Images will align next to each other. If you need the divs, you can give them the style display: inline to make them behave in the same way. You can also use float: left, but that will make things harder in most cases.
You can apply styles like margins and borders to images too, so you may not need the divs. Although I'm not sure how you want it to look exactly.

Here is the example: http://jsfiddle.net/hobobne/d5sYM/
<html>
<head>
<style>
img {width: 100px; height: 100px;}
.imageBox {display: inline-block; border: 1px solid grey; background: silver; padding: 4px; text-align: center; font-size: 10px;}
</style>
</head>
<body>
<div class="imageBox">
<img src="http://screenshots.en.softonic.com/en/scrn/80000/80669/easter-icons-5.jpg"><br>
Image 1
</div>
<div class="imageBox">
<img src="http://l-userpic.livejournal.com/82523298/2181918"><br>
Image 2
</div>
<div class="imageBox">
<img src="http://www.jellymuffin.com/icons/emo/images/30.jpg"><br>
Image 3
</div>
</body>
</html>

Related

Centering Floated images in figure

in advance i appreciate all help i can get since im new to HTML and CSS, i want to center the 3 images, but i cant center them, im sure its something silly but i cant figure it out. i added an image so you can see what the layout is.
body {
font-family: Arial, Verdana, sans-serif;
color: #000;
font-weight: bold;
margin: 0;
}
#wrapper {
width: 100%;
}
#logo {
float: left;
}
#navigation {
clear: both;
background-color: #14171a;
width: 100%;
height: 70px;
box-shadow: 0px 5px 3px #000;
}
#navigation ul li {
display: inline;
margin-left: 50px;
}
#navigation ul li a {
text-decoration: none;
color: #fff;
font-size: 20px;
}
#navigation ul {
width: 570px;
padding-top: 20px;
margin: 0px auto 0px auto;
}
#midcontent {
}
h1 {
margin: 0px auto 0px auto;
margin-top: 50px;
padding: 10px 0px 10px 10px;
color: #fff;
background-color: #6ac045;
font-size: 170%;
border-radius: 8px;
width: 400px;
}
#midcontent article {
}
figure {
float: left;
width: 300px;
}
figure img {
display: inline-block;
width: 300px;
height: 244px;
}
figcaption {
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<title>Electronix CR</title>
<link rel="stylesheet" type="text/css" href="CSS/Electronix.css">
</head>
<body>
<div id="wrapper">
<header id="logo">
<img src="images/Electronix.png">
</header>
<nav id="navigation">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
<h1>What can we fix for you today</h1>
<section id="midcontent">
<article class="content">
<figure><img src="images/Diagnostic.jpg" alt="Helianthus" />
<figcaption>Siagnostic</figcaption>
</figure>
<figure><img src="images/LCD.jpg" alt="Passiflora" />
<figcaption>LCD Replacement</figcaption>
</figure>
<figure><img src="images/Battery.jpg" alt="Nyctocalos" />
<figcaption>Battery Replacement</figcaption>
</figure>
</article>
</section>
</div>
</body>
</html>
have you attempted to remedy the issue using the BootStrap framework? Using the grid you will be able to place the images in columns and rows based on the size you desire. BootStrap works in a grid of 12. So you would require something along the lines of
<div class = row>
<div class = col-md-4>
<insert image here or content here>
</div>
</div>
You may also need to add this to your images:
.center-block {
display: block;
margin-right: auto;
margin-left: auto;
}
essentially you would repeat the process as needed. each image with "col-md-4" as 4*3=12. It may require additional adjustments, but bootstrap will do almost all the heavy lifting. Below is a link to BootStrap and it's documentation. Good luck friend.
http://getbootstrap.com/

Navigation and Logo Same Line

Weebly Menus and logos
So I have been reading everywhere that I can think of online to fix an issue with logo and navigation being on the same line. And yes I have attempted the other articles on Stackoverflow.
I have changed lines of code, added lines of code and it moves things around but refuses to put them on the same lines.
The code is this:
/* LOGO & MENU */
#header{
width: 100%;
height: auto;
padding: 0;
margin: 0;
}
.navContainer{
width: 500px;
height: auto;
background: url('navbg.jpg') repeat;
text-align: right;
display: inline;
overflow: hidden;
}
.logo {
width: 200px;
min-height: 20px;
height: auto;
margin: none;
float: left;
display: inline;
}
span.wsite-logo {line-height: 1;}
#logo, #logo a, #wsite-title {
color: #2a2a2a !important;
text-decoration: none !important;
font-family: "Open Sans", sans-serif;
font-size: 44px;
font-weight: lighter;
font-weight: 300;
line-height: 1;
}
/* Navigation Menu */
#navigation{
float: right;
border-bottom: 1px solid #eee;
border-top: 1px solid #eee;
height: 100px;
display:inline;
overflow: hidden;
}
#navigation a, #icontent #navigation li:last-child a{
display:inline-block;
text-decoration:none;
line-height: 1;
padding: 20px 16px;
border-right: 1px solid #eee;
}
#navigation li:last-child a, #icontent #navigation span:last-child li a{border-right: none;}
#navigation ul{margin: 0; list-style: none;}
#navigation li{display:inline;}
#weebly-menus .weebly-menu-wrap { z-index: 5000; margin: 0; }
#weebly-menus .weebly-menu { padding: 0; margin: 0; list-style: none; }
#weebly-menus .weebly-menu li { width: 162px; text-align: left; margin-top: 2px;}
#weebly-menus .weebly-menu li a {
border: none;
display: block;
background-color: #ffffff;
text-decoration: none;
font-size: 12px;
font-weight: normal;
line-height:1;
padding: 5px 0px;
color: #000;
font-family: Helvetica, sans-serif;
width: 160px;
height: auto;
border: 1px solid #eee;
}
#weebly-menus .weebly-menu-wrap, #wsite-menus .wsite-menu-wrap {
z-index: 5000;
margin: 0;
postiion: relative !important;
}
Please help. I am wanting to learn more but do you ever get to the point where your brain is just fried from trying different what you hope are solutions, and it turns out not to work. THAT IS WHERE I AM RIGHT NOW!!!!
The link to the site is this :Site preview
Also I am having trouble putting simple text to the right of the navigation.
The HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=1024">
<!-- Fonts -->
<link href='http://fonts.googleapis.com/css?family=Crimson+Text:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
<!-- JS -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body class='tall-header wsite-theme-light'>
<div class="note" style="text-align: center;"><p>This gap is here to allow you to see the text tool bar for the header bar below. When site is published, the gap will disappear</p></div>
<div id="wrapper">
<div id="bar">
<div class="frame clearfix">
<div class="bar-text"><p>{call:text}</p></div>
<div id="search-button"><i class="af-search"></i></div>
<div class="social-frame">{social}</div>
<div class="search-bar">{search}</div>
</div>
</div>
<header id="header">
<div class="navContainer clearfix">
<div class="logo med-padding">{logo}</div>
<nav><div id="navigation">{menu}</div></nav>
</div>
<div class="sliderContainer">
<div id="tall-header-image" class="wsite-header"></div>
</div>
</header>
<div id="main" role="main">
<div class="frame">
<div class="content large-padding">{content}</div>
</div>
</div>
<footer>
<div id="footer" class="large-padding clearfix">
<div class="frame">
<div class="note" style="text-align: center;"><p>Drag & drop footer content here</p></div>
<div id="footer-content" class="med-padding">{bottom:content} </div>
<div id="footer-content" class="med-padding" style="display:none;">{footer}</div>
</div>
</div>
<div id="footer-bottom" class="feature small-padding">
<div class="frame">
<div class="copyright"><p>{copyright:text}</p></div>
</div>
</div>
</footer>
</div>
<script type="text/javascript" src="/files/theme/basic-header.js"></script>
</body>
</html>
Place the span.wsite-logo class directly under the nav tag, after that change the span class in a div class and add a float: left to the class .wsite-logo.
remove logo div class logo med-padding.
Some advice that worked!!
Line 120 of css, in the #navigation, change text align right to center to move it horizontally, or add margin-top: 3%; to move it vertically, or both, or various other combinations.
navigation {
text-align: center;
border-bottom: 1px solid #eee;
border-top: 1px solid #eee;
float: none;
margin-top: 3%;

CSS vertical alignment and floating issue

I'm creating a website which enables reservation of hour-long blocks. I'm trying to get the style right.
This is what it should look like:
And here is the code I've written so far:
<html>
<head>
<title></title>
<link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400" rel="stylesheet" type="text/css" />
<style type="text/css">
body
{
font-family: 'Source Sans Pro';
font-weight: 300;
margin-left: 25px;
margin-right: 25px;
margin-top: 10px;
margin-bottom: 10px;
}
#header
{
height: 50px;
width: 100%;
}
.block
{
background-color: #e5e5e5;
display: inline-block;
width: 275px;
height: 35px;
}
.block-sideline
{
background-color: #999999;
display: inline-block;
margin-right: 5px;
width: 5px;
height: 35px;
}
.block-span
{
margin-left: 5px;
margin-right: 5px;
}
.block-hours
{
color: #000000;
}
.block-status
{
}
.block-notavailable .block-sideline
{
}
</style>
</head>
<body>
<div id="header">
<img id="header-logo" src="header-logo.svg" height="50px" width="125px" />
</div>
<div id="content">
<h2>Sunday, December 1, 2013</h2>
<div class="block">
<div class="block-sideline">
</div>
<span class="block-hours">6:00 AM – 7:00 AM</span>
<span class="block-status">Not available</span>
</div>
</div>
</body>
Right now, this is what it looks like in IE:
So, now, when I float the hours and the sideline left with float: left; and the status right with float: right;, it looks like this:
Right now the margins and colors are not important, but how can I center the text inside the div and allow it to float at the same time? Also, in the screenshot above, the margins are not showing on the right side. Why is this?
Here is the CSS
.block-sideline
{
background-color: #999999;
display: inline-block;
margin-right: 5px;
width: 5px;
height: 35px;
float:left;
}
.block-hours
{
float:left;
line-height:225%;
color: #000000;
}
.block-status
{
float:right;
line-height:225%;
}
Basically add floats and line-height.

Margin: 0 auto is not centering my image

I'm very new to all of this and am trying to build this website, but the main image on the page is not centering. I've tried all sorts of centering things but they don't work. Also, the width percentage is ignored too.
I've readjusted margin/padding to 0. don't know what it could be.
css for the picture:
#pictures img{
width:"70%";
margin: 0 auto;
padding-bottom: 80px;
padding-top: 20px;
}
and the html div that has to do with it:
<div id="pictures">
<img src="img/homepage.png" alt="HomePage"></div>
FULL HTML
<!DOCTTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Jacobs Bookeeping</title>
<link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/style-no-grid.css" type="text/css" media="screen">
</head>
<body>
<div class="container clearfix">
<div id="main">
<div id="header">
<img src="img/logo.png" alt="Jacobs Bookkeeping Logo" width="248">
</div>
<div id="twitter">
<img src="img/twitter.jpg" alt="Twitter">
</div>
<div id="facebook">
<img src="img/facebook.jpg" alt="Facebook">
</div>
<ul class="nav">
<li>About Us</li>
<li>Services</li>
<li>Contact Us</li>
<li class="last">Resources</li>
</ul>
<div id="pictures">
<img src="img/homepage.png" alt="HomePage">
</div>
</div>
</div>
<div id="copyright">
<p>K. RONI JACOBS, <em>KEEPER OF THE BOOKS</em> — EMAIL JACOBS BOOKKEEPING — CALL 206.861.5664 — © 2013 JACOBS BOOKEEPING &nbsp &nbsp</p>
</div>
</body>
</html>
FULL CSS
html {
margin: 0px;
padding: 0px;
}
body {
font-family:'Futura', sans-serif;
color: #FFFFFF;
font-size: 13;
margin: 0px;
padding: 0px;
}
#main {
border-top: 10px solid #EAE1C9;
border-right: 10px solid #EAE1C9;
border-left: 10px solid #EAE1C9;
padding-bottom: 20px;
background: url('../img/bg-jacobs.jpg') repeat;
background-color:#96B9BF;
}
a {
color: #FFFFFF;
text-decoration: none;
}
#facebook img{
float: right;
padding: 45px 5px 10px 10px;
position: static;
}
#twitter img{
float: right;
padding: 45px 50px 20px 0px;
position: static;
}
#header img {
padding: 40px 0px 0px 40px;
float: left;
position: static;
}
ul.nav {
margin-top: 45px;
list-style: none;
text-transform: uppercase;
float: right;
position: relative;
}
ul.nav li {
margin: 0px 50px 0px 60px;
display: inline;
}
ul.nav li a {
color: #FFFFFF;
}
#pictures img{
width:"80%";
margin: 0 auto;
padding-bottom: 80px;
padding-top: 20px;
display: block;
text-align: center;
}
#copyright {
text-align: right;
background: #867131;
border-top: 10px solid #EAE1C9;
position: fixed;
bottom: 0;
width: 100%;
height: 30px;
font-size: 10px;
letter-spacing: 2px;
color: white;
}
.container{
width: auto;
margin: 0 auto;
}
.clear{clear:both;display:block;overflow:hidden;visibility:hidden;width:0;height:0}.clearfix:after{clear:both;content:' ';display:block;font-size:0;line-height:0;visibility:hidden;width:0;height:0}* html .clearfix,*:first-child+html .clearfix{zoom:1}
Put display: block; on it. By default, images are inline.
To center inline —default for image— or inline-block elements, just center it as text. This means, you will need to use text-algin on the parent element:
div#pictures {
text-align: center;
}
The other solution is the one from #One Trick Pony, and display the image as a block element and just then apply the automatic margin.
#pictures img{
display:block;
}
Add this code then i will be centered
i know this is an old post, but wanted to share how i solved the same problem.
My image was inheriting a float:left from a parent class. By setting float:none I was able to make margin:0 auto and display: block work properly. Hope it may help someone in the future.
You have two options:
Remove img from #pictures and then put the image inside that div.
Add the #pictures to the image Tag in html (inline style).
You might remove the display tag in #pictures.
Good luck with that.

HTML/CSS float left issue

I have been recently designing some content which needs to be side by side and have the height automatically resize, but the height doesn't resize. The div doesn't expand to the size of the items inside of it. Is there a way to allow the div to expand to the size of the elements inside of it?
CSS
* {
padding: 0px;
margin: 0px;
}
body {
font-family: 'Metrophobic', sans-serif;
background-color: #c5c5c5;
background-image: url('../images/noise.png');
}
#container {
width:900px;
background-color: #dbdbdb;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
margin-bottom: 20px;
box-shadow: 0px 0px 5px black;
}
.center_align {
display: inline-block;
margin-left: auto;
margin-right: auto;
}
#header {
height:80px;
font-size: 60px;
padding: 10px;
text-align: center;
}
#menu {
width:900px;
height:50px;
margin-top: 10px;
margin-bottom: 10px;
background-color: #cacaca;
}
.menu_link {
width:224px;
height:50px;
text-align: center;
font-size: 35px;
float: left;
opacity: 0.3;
background-color: #cacaca;
}
.menu_divider {
width: 1px;
height: 50px;
background-color: #dbdbdb;
float:left;
}
#content {
width: 900px;
height: auto;
padding: 10px;
font-size: 20px;
height: auto;
}
.line_container {
margin-top:5px;
margin-bottom:5px;
}
#footer {
width:900px;
height:22px;
padding-top:2px;
text-align: center;
font-size: 14px;
color:black;
}
a:link {
color:black;
text-decoration: none;
}
a:visited {
color:black;
text-decoration: none;
}
a:hover {
color:black;
text-decoration: none;
}
a:active {
color:black;
text-decoration: none;
}
a.link:link {
color:#21525e;
}
a.link:visited {
color:#21525e;
}
a.link:hover {
color:#307f91;
text-decoration: underline;
}
a.link:active {
color:#307f91;
text-decoration: underline;
}
HTML
<html>
<head>
<title>Home</title>
<link rel="shortcut icon" href="../images/favicon.ico" />
<link href="http://fonts.googleapis.com/css?family=Metrophobic" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.icon {
width:100px;
height:100px;
border: 3px solid white;
border-radius:25px;
margin-left:10px;
margin-right:10px;
background-position: center center;
background-size: 100px 100px;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<div class="center_align">
<img src="../images/header_icon.png" alt="header_icon" width="80" height="80" style="margin-right:20px;float:left;" />
<div style="height:80px;float:left;">Title</div>
</div>
</div>
<div id="menu">
Home
<div class="menu_divider"></div>
Tutorials
<div class="menu_divider"></div>
About
<div class="menu_divider"></div>
Contact
</div>
<div id="content">
<div style="width:900px;">
<div class="icon" style="background-image:url('image.jpg');float:left;"></div><div style="float:left;margin-top:20px;">I'm a freelance Web, Iphone, and Game developer.</div>
</div>
</div>
<div id="footer">
© Cameron
</div>
</div>
</body>
</html>
Looks like the problem is that the #footer element isn't properly cleared. Add clear: both; to #footer. This pushes the cleared element below the floated elements, and should functionally result in the same visual fix.
The "container div" basically "forgets" that it is the container for them, so simply add an overflow:auto; to make it remember.
I also tend to add zoom:1 for IE.
The problem is that you are floating elements, and that causes problems with wrapping divs per default (pretty much...).
Here is a working solution, where overflow:hidden is added to the wrapping div: http://jsfiddle.net/s2dxw/2/
The float issue is pretty confusing, and has had a couple of solutions in the past. Here's a good read regarding floats in HTML: http://css-tricks.com/all-about-floats/
Alternatively, you can put some element with the rule clear: both; inside and at the end of the wrapping div.