Simple CSS Images Side By Side - css

I'm having a problem displaying images side by side inside of an overflow box.
They seem to be going to the end of the box then going to a new line for some reason.
Here's what I got:
<div style="overflow-x:auto; overflow-y:hidden; white-space:nowrap; width:500px; height:145px;">
<?php
for ($i=1; $i<=9; $i++) {
echo "<table><tr><td>";
echo "<img src=\"images/store/" . $i . ".jpg\" height=\"100px\" />";
echo "<br /><center><img src=\"images/store/buy.png\" width=\"75px\" /></center></td></tr></table>";
}
?>
</div>
Any help would be amazing!

I would recommend updating and formatting your code better, then addressing the issue you're having.
Don't echo out HTML tags using PHP.
Don't use inline-styles applied directly to the tags (use classes/ids)
Don't use tables, for non-tabular data.
With that said, here is a working example of what I believe you're trying to achieve:
http://jsfiddle.net/a8yDv/
PHP/HTML:
<div class="images">
<ul>
<?php for ($i=1; $i<=9; $i++) : ?>
<li>
<img src="images/store/<?php echo $i; ?>.jpg" class="top-image" alt="" />
<img src="images/store/buy.png" class="bottom-image" alt="" />
</li>
<?php endfor; ?>
</ul>
</div>
CSS:
.images {
border: 5px solid red;
height: 145px;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
width: 500px;
}
.images ul {
list-style-type: none;
margin: 0;
padding: 0;
white-space: nowrap;
}
.images li {
display: inline-block;
text-align: center;
}
.images img {
display: block;
margin: 0 auto;
}
.images img.top-image {
height: 100px;
margin-bottom: 5px;
}
.images img.bottom-image {
width: 75px;
}
/* Clearfix - http://css-tricks.com/snippets/css/clear-fix/ */
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-block; }
/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */

You could use the white-space:nowrap; property in your styles:
div {
overflow-x:auto;
overflow-y:hidden;
white-space:nowrap;
width:500px;
height:100px;
}
Demo.

I believe all I really had was a bug, and #Yamo seemed to point it out for me. Everything works fine now!
<div style="overflow-x:auto; overflow-y:hidden; white-space:nowrap; width:500px; height:145px;">
<table><tr>
<?php
for ($i=1; $i<=9; $i++) {
echo "<td><img src=\"images/store/" . $i . ".jpg\" height=\"100px\" />";
echo "<br /><center><img src=\"images/store/buy.png\" width=\"75px\" /></center></td>";
}
?>
</tr></table>
</div>

Related

Dealing with flexbox while changing an element

I have a problem with styling my bar, which works on flexbox.
bar
As you can see, there is three divs inside: one sticked to the left border and another sticked to right border; there is also a small div in the middle showing the amount of comments (80px) and I want it to go left and stick to the div on left. Is it a chance to manage this with flexbox, without changing for display: inline-block?
The bar has a class .article__metas.
The div in the middle is .social_item.
<div class="article__metas">
<div class="item date">
//showing date
</div>
<div class="seperator"></div>
<?php
/**
$clist = get_the_category_list(', ');
if (!empty($clist)) {
?>
<div class="item categories">
<?php
echo $clist;
?>
</div>
<div class="seperator separator-categories"></div>
<?php } */
?>
<?php
$share = $app->getPostStats();
if ($share->comment_count > 0 || $share->share_count > 0):?>
<div class="item social_item">
<?php
if ($share->comment_count > 0) {
echo '<span>';
echo '<img src="' . _img_url('comment.svg') . '"/>';
echo '<span class="amount">' . $share->comment_count . '</span>';
echo '</span>';
}
if ($share->share_count > 0) {
echo '<span>';
echo '<img src="' . _img_url('share.svg') . '"/>';
echo '<span class="amount">' . $share->share_count . '</span>';
echo '</span>';
}
?>
</div>
<?php endif; ?>
<?php get_template_part('inc/article/share'); ?>
</div>
And Sass:
.article__metas {
color: #888888;
font-size: 12px;
display: flex;
border-bottom: 1px solid #e5e5e5;
justify-content: space-between;
#include link-color('a', '#888');
a:hover {
text-decoration: underline;
}
.item {
padding: 20px;
&:first-child {
padding-left: $cards_left;
}
}
.seperator {
display: block;
align-self: stretch;
width: 1px;
background-color: #e5e5e5;
}
.social_item {
display: flex;
align-items: center;
justify-content: space-between;
span + span {
margin-left: 20px;
}
& > span {
display: block;
white-space: nowrap;
img {
width: 16px;
display: inline-block;
}
}
img {
margin-top: 2px;
margin-right: 9px;
}
}
}
Thank you in advance!
Please check if this is what you need. SCSS doesn't work here, so you need to copy to your own environment.
.ariticle__metas is now aligned left and .social_item has a margin-left:auto
Fiddle here
.article__metas {
color: #888888;
font-size: 12px;
display: flex;
border-bottom: 1px solid #e5e5e5;
justify-content: left;
#include link-color('a', '#888');
a:hover {
text-decoration: underline;
}
.item {
padding: 20px;
&:first-child {
padding-left: 10px;
}
}
.seperator {
display: block;
align-self: stretch;
width: 1px;
background-color: #e5e5e5;
}
.social_item {
display: flex;
align-items: center;
justify-content: space-between;
margin-left: auto;
span + span {
margin-left: 20px;
}
& > span {
display: block;
white-space: nowrap;
margin-right: 10px;
img {
width: 16px;
display: inline-block;
}
}
img {
margin-top: 2px;
margin-right: 9px;
}
}
}
<div class="article__metas">
<div class="item">Dodano 18.04.2016</div>
<div class="seperator"></div>
<div class="item">1</div>
<div class="seperator"></div>
<div class="social_item">
<span>Spodobal Ci</span>
<img src="http://placehold.it/15" />
<img src="http://placehold.it/15" />
<img src="http://placehold.it/15" />
<img src="http://placehold.it/15" />
</div>
</div>

Multiple divs in absolute

I reached to a problem in my website.
My website is showing all the records in she same page, that each record calls the main div called "work" and inside of that one is calling another one called "worktitle".
I want the worktitle div stays like the image:
Image
But the problem is on the second row. The divs that belongs to the seconda row are in the same place as the first row.
Like you can see here:
Website
HTML Code
<div id="box1">
<?php do { ?>
<div id="work">
<a href="<?php echo $row_works['url']; ?>" target="new">
<img src="images/<?php echo $row_works['image']; ?>" />
<div class="worktitle">
<span class="infotec"><?php echo $row_works['infotec']; ?><br/>
<?php if ((isset($_GET['lang'])) && ($_GET['lang']=="en")) {
echo $row_works['descriptionen']; }
else {
echo $row_works['descriptionpt'];
} ?>
</span>
<span class="title"><?php echo $row_works['title']; ?></span>
</div>
</a>
</div>
<?php } while ($row_works = mysql_fetch_assoc($works)); ?>
</div>
CSS Code
#work {
float: left;
margin: 0px;
padding: 0px;
width : 200px;
border: solid 1px #787879;
}
#work a{
color: #FFF;
text-decoration:none;
}
#work a:hover {
opacity: 0.5;
}
#work img {
margin: 0px;
width: 200px;
z-index: 9;
}
a img{
border: 0;
}
.worktitle {
position: absolute;
top: 200px;
background-color: #787879;
opacity: 0.6;
font-weight: bold;
font-size: 14px;
z-index: 10;
}
.infotec {
font-weight: normal;
font-size:9px;
}
.title {
text-align: right;
}
What am i doing wrong? Please help me out.
First of all id's must be unique in your html so change #work to .work then try giving it a relative position and aligning your description to the bottom.
.work{
position: relative;
}
.worktitle {
position: absolute;
bottom: 0;
}

CSS fixed position on X axis but absolute on Y axis?

My container, #topmenu is in fixed position. I just added a phone number (image) that I want to move with this bar, but it doesn't move with the fixed bar.
I've absolutely positioned it within a relatively positioned element, but it just doesn't stick.
If I just make the phone number position:fixed then it moves around with the viewport width. What's the best way to accomplish what I'm doing?
CSS fragment:
.topsocial a { margin-left: 15px; }
#topmenu {position:fixed; z-index:220; }
#topmenu .ktwrap {padding-top: 3px; padding-bottom: 3px; color: #fff;}
#topmenu ul li { display:inline; list-style-type: none; padding: 0px 10px 0 0; font-size: 13px; }
#topmenu .widget-container { margin-top: 5px;}
.topsocial .widget-containter {margin-top: 0px!important;}
#menu-menu li a span {
display:block;
line-height:14px;
margin-right: 4px;
text-transform: lowercase!important;
}
.menu-menu ul li a span {
line-height:14px;
margin-right: 4px;
text-transform: lowercase!important;
}
.topsocial {margin-top: 5px; color: #fff;}
.ktlogo {float: left; width: auto; margin-top:-35px; margin-left: 137px; font-family: 'HoneyScriptLight'; font-size: 60px; padding-top: 22px; }
.ktlogo img:hover {background: none;}
#navigationtop { font-size: 12px; color: #fff;}
#navigationtop ul li strong { display: block; padding-bottom: 7px; font-size: 14px; }
#navigationtop .ktwrap { padding-top: 60px; padding-bottom: 5px; height:71px; }
#floatnumber {
position: absolute;
top: -3px;
right: 150px;
z-index : 270;
}
PHP fragment:
<?php get_template_part( 'includes/template-parts/topbar' ); ?>
<?php } ?>
<?php
$disable_sidebar = of_get_option('disable_footer', '' );
if( $disable_sidebar['navbar']==0 ) { ?>
<div class="ktfullwidth" id="navigationtop">
<div class="ktwrap"> <div id="floatnumber"><img src="http://combined-effort.com/wp-content/uploads/telephone-18005174660.png" alt="Phone Number 1-800-517-4660"></div>
<div class="ktlogo">
<?php
$disable_sidebar = of_get_option('disable_parts', '' );
if( $disable_sidebar['logo']==0 ) { ?>
<?php if ( of_get_option('logo') ) { ?>
<img src="<?php echo of_get_option('logo'); ?>" />
<?php } else { ?>
<a href="<?php echo home_url() ?>">
<?php if ( of_get_option('logotext') ) { ?>
<?php echo of_get_option('logotext', ''); ?></a>
<?php } else { ?>
Combined Effort</a>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
You can change
<ul id="menu-main" class="sf-menu sf-js-enabled sf-shadow">...</ul>
<div class="topsocial right">...</div>
into
<ul id="menu-main" class="sf-menu sf-js-enabled sf-shadow">...</ul>
<div class="right">
<img src="http://combined-effort.com/wp-content/uploads/telephone-18005174660.png" alt="Phone Number 1-800-517-4660">
<div class="topsocial right">...</div>
</div>
And then delete the othe image.
Without having read or tested your code in detail: If I got you right and you want to move the number with the bar then you have to put it within this fixed header. In the orignal code you can see that there are two overlapping headers and the number is NOT in the one with position fixed. Which there is
<div id="topmenu" class="ktfullwidth">
but in (and in your code seemingly as well)
<div class="ktfullwidth" id="navigationtop">
Put the number inside the #topmenu-div.
You might also be able to use position fied on the number itself, but i would recommend ot put it in the div.
Edit: I got confused by the names of the navigation-divs. I hope I got it right now.

DIV float right not working. What is wrong?

I am trying to float the timer right top across from the logo. but it's not working.
If I use the regular style="float:right" it works perfect...
<div id="whole_page" />
<div id="header" />
<?php echo "$logo" ?>
<div id="timer" style="float:right" /><?php
echo "$today";
?></div>
</div>
<div id="nav" />
Home |
About |
Help
</div>
<div id="content" />
<?php
echo "Hello, my name is, $first_name \"$nick_name\" $last_name<br />";
echo "I am from $city, $country<br />";
?>
</div>
</div>
This is the css:
#whole_page {
width: 65em;
margin: auto;
padding: 0;
text-align: left;
border-width: 0 1px 1px;
border-color: #000;
border-styler: solid;
}
#header {
color: white;
background: #ebebeb;
font-size: 24pt;
margin-bottom: 0;
font-weight: bold;
}
#timer {
float: right;
margin-bottom: 0;
}
#nav {
color: #000;
font-size: 12pt;
font-weight: none;
background: #ebebeb;
padding: 0.5em;
border: none;
Usually, for a float to work, you need to set a width on the element.
(Otherwise, the browser renders the element at 100% and there is nothing to float.)
So make this
#timer{
width:200px; //OR WHATEVER SIZE
float:right;
margin-bottom:0;
}
What happens when you use F12 debug? Do you see any style applied to the element? Also view the source code of of rendered page and see the actual CSS in the page. Then please post the necessary css from there to debug it.
Try to add to div header:
float:left;
If you want that a div to be in the next line just place:
clear: both;

Centering the absolute positioned navigation bar of NivoSlider? (or using the margin: 0 auto trick)?

I added Nivo Slider to my Wordpress theme.
In the demo provided with the file the nivo-ControlNav has position absolute, and it is moved to the right.
I would like to know if there is a way of centering the nivo-ControlNav (and it should even be centered in Internet Explorer)?
front-page.php:
<div id="feature">
<div class="container">
<div id="slider-wrapper">
<div id="slider">
<?php // Retrive custom post type with a custom taxonomy assigned to it
$posts = new WP_Query('post_type=page_content&page_sections=Slider (Front Page)&order=ASC') ?>
<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
<div class="shadow-slider">
<!-- Shadow at the bottom of the slider -->
</div>
</div>
</div><!-- .container -->
</div><!-- #featured -->
stlye.css:
#feature {
background: #333;
padding: 30px 0;
height: 400px;
}
#slider-wrapper {
float: left;
height: 500px;
}
#slider {
float: left;
border: 1px solid #DDD;
}
#slider {
position:relative;
background:url(images/loading.gif) no-repeat 50% 50%;
}
#slider img {
position:absolute;
top: 0px;
left: 0px;
display: none;
}
#slider a {
border: 0;
display: block;
}
.nivo-controlNav {
position: absolute;
left: 260px;
bottom: -42px;
width: 50%;
left: 0;
right: 0;
margin: 0 auto;
}
.nivo-controlNav a {
display: block;
width: 22px;
height: 22px;
background: url(images/bullets.png) no-repeat;
text-indent: -9999px;
border: 0;
margin-right: 3px;
float: left;
}
.nivo-controlNav a.active {
background-position: 0 -22px;
}
.nivo-directionNav a {
display: block;
width: 30px;
height: 30px;
background: url(images/arrows.png) no-repeat;
text-indent: -9999px;
border: 0;
}
a.nivo-nextNav {
background-position: -30px 0;
right: 15px;
}
a.nivo-prevNav {
left: 15px;
}
.nivo-caption {
text-shadow:none;
font-family: Helvetica, Arial, sans-serif;
}
Or should I just use the float: left; margin: 0 auto; trick?
EDIT:
I decided to do this:
.nivo-controlNav {
margin: 0 auto;
overflow: hidden;
width: 200px;
}
.nivo-controlNav {
margin: 0 auto;
overflow: hidden;
width: 200px;
}
but the links inside the nivo-controlNav div are not centered.
Any suggestions?
.nivo-controlNav {
text-align:center;
left:0;
right:0;
}
.nivo-controlNav a {
display:inline-block; /* so float:none */
}
It will work on all browsers understanding inline-block property.
I found the solution, and it's relevant for any number of images, the only inconvenient is that you'll have to use jQuery, but I guess that won't be a problem cause Nivo already works with jQuery ^^' ... anyways ...
Based on the earlier posted css codes :
.nivo-controlNav {
position: absolute;
left: 50%;
}
I could come up with this javascript code, I'll explain it later :
$(document).ready(function() {
$('#slider').nivoSlider();
var numberImages = $('#slider img').length;
var bulletWidth = 22;
var margin = - ( (numberImages * bulletWidth) / 2 );
$('.nivo-controlNav').css('margin-left', margin+'px');
});
What this basically means is that, instead of giving each slider's controlNav a random margin-left based on the number of images, we'll calculate that, and the way to do that is very simple :
We MOVE the left edge of our controlNav to 50% (CSS)
Next we have to know the width of the WHOLE controlNav, which contains bullets of course :
`numberImages * bulletWidth`
Divide all this by 2, and then remove it from the margin-left, this simply means : move the controlNav by half of its width to the left.
Hope it works for you :)

Resources