Expand svg tab as text expands without stretching the sides - css

I have tabs with svg background that stretches to the width of the text. Is there a way to edit my svg or css to fix the curvatures on the sides without splitting up the svg to separate elements or using pseudo after/before css? This way while the whole svg stretches the middle part, the sides would remain intact stretching only the middle rectangle element.
This would fix the "Other important specification" tab's stretched sides.
$(document).ready(function(){
$('.nav-tabs li').click(function() {
$(this).siblings('li').removeClass('active');
$(this).addClass('active');
});
});
.product-info .row,
.recipe-info .row {
text-align: left;
margin-left: 5px;
}
.product-info .nav-tabs,
.recipe-info .nav-tabs {
border-bottom: 1px solid #def0f8;
}
.product-info .nav-tabs > li,
.recipe-info .nav-tabs > li {
background-color: transparent;
margin-bottom: 0;
overflow: visible;
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
}
.product-info .nav-tabs > li > a:hover,
.recipe-info .nav-tabs > li > a:hover {
color: white;
text-decoration: none;
border: 0;
background-color: transparent;
}
.product-info .nav-tabs > li > a,
.recipe-info .nav-tabs > li > a {
border: none;
height: 35px;
background-color: transparent;
padding: 0;
text-align: center;
margin-top: 1px;
z-index: 2;
}
.product-info .nav-tabs > li > a .tabbed,
.recipe-info .nav-tabs > li > a .tabbed {
margin: 0;
height: 35px;
width: auto;
}
.product-info .nav-tabs > li > a .tabbed span,
.recipe-info .nav-tabs > li > a .tabbed span {
font-family: Roboto;
font-weight: 500;
font-size: 16px;
color: #616161;
line-height: 35px;
letter-spacing: 0.01em;
background-color: transparent;
padding: 0;
display: inline;
white-space: nowrap;
min-width: 95px;
}
.product-info .nav-tabs > li.active > a,
.recipe-info .nav-tabs > li.active > a {
color: #ffffff;
z-index: 10;
}
.product-info .nav-tabs > li.active > a .tabbed,
.recipe-info .nav-tabs > li.active > a .tabbed {
background-image: url("data:image/svg+xml,%3Csvg xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:cc='http://creativecommons.org/ns%23' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='0 0 134.5 35' preserveAspectRatio='none' data-name='Layer 1' id='Layer_1'%3E%3Cmetadata id='metadata15'%3E%3Crdf:RDF%3E%3Ccc:Work rdf:about=''%3E%3Cdc:format%3Eimage/svg+xml%3C/dc:format%3E%3Cdc:type rdf:resource='http://purl.org/dc/dcmitype/StillImage' /%3E%3Cdc:title%3Etab%3C/dc:title%3E%3C/cc:Work%3E%3C/rdf:RDF%3E%3C/metadata%3E%3Cdefs id='defs3'%3E%3Cstyle id='style5'%3E.cls-1%7Bfill:%2325437f;%7D%3C/style%3E%3C/defs%3E%3Ctitle id='title7'%3Etab%3C/title%3E%3Cpath style='fill:%2325437f;fill-opacity:1' id='path9' transform='translate%280 0%29' d='M0,35H30V0C6.39,0,11.8,35,0,35Z' class='cls-1' /%3E%3Cpath style='fill:%2325437f;fill-opacity:1' id='path11' transform='translate%280 0%29' d='M134.5,35h-30V0C128.11,0,122.7,35,134.5,35Z' class='cls-1' /%3E%3Crect y='-5.5511151e-17' x='29.5' height='35' width='56.5%25' id='rect4143' style='opacity:1;fill:%2325437f;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.5;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1' /%3E%3C/svg%3E");
background-repeat: no-repeat;
background-size: 100% 35px;
background-position: center;
}
.product-info .nav-tabs > li.active > a .tabbed span,
.recipe-info .nav-tabs > li.active > a .tabbed span {
color: #ffffff;
width: 100%;
margin: 0 35px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel='stylesheet'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="product-info tabbable">
<div class="row">
<ul class="nav nav-tabs">
<li class="active">
<a href="#" data-toggle="tab">
<div class="tabbed">
<span class="">Details</span>
</div>
</a>
</li>
<li>
<a href="#" data-toggle="tab">
<div class="tabbed">
<span class="">Other important specification</span>
</div>
</a>
</li>
</ul>
</div>
<div class="row">
<div class="tab-content">
lorem ipsum
</div>
</div>
</div>
Probably nested svg's could solve this, here's a notion of how I imagine achieving the rightly expanding svg:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" width="100%" height="35">
<defs>
<style>
</style>
</defs>
<title>expandable tab</title>
<!--
Whole tab as one path, if possible try to adjust the beizer curves so they
would keep the sides unstreched when image is streched on x axis.
-->
<!--
<path fill="#25437f" d="
m30 0
c-23.5,0 -18,35 -30,35
h30 40 30
c-12,0 -6.5,-35 -30,-35
z"
/>
-->
<!--
The sides should have fixed widths of 30, the middle uses up the available space in between.
-->
<g fill="#25437f">
<svg x="0" width="30" class="container-left">
<path d="m0 35h30v-35c-23.61 0-18.2 35-30 35z" class="path-left" vector-effect="non-scaling-stroke"/>
</svg>
<svg x="29" width="90%" style="overflow: hide;">
<!--
Should have width of 100% shrunken with 30 on the x axis.
Maybe apply a mask?
-->
<rect height="35" width="100%" y="-5.5511e-17"/>
</svg>
<svg x="100%" width="30" class="container-right" transform='translate(-30 0)'>
<!--
Its positioning should be counted from the right to left x="0" starting from right if direction could be set.
Hacking with x="100%" and transform="translate(-30 0)" should be doing the same, but they are not.
-->
<path d="m0 35h-30v-35c23.61 0 18.2 35 30 35z" class="path-right" vector-effect="non-scaling-stroke"/>
</svg>
</g>
</svg>
I'm looking for an implementation that uses pure html/svg/css techniques to adjust the tab size (no javascript adjustments). My goal with this is to replace an html hackery with left, middle and right blocks with one html element thus reducing the chance to mess the tab up, and renders the same way across browsers (from IE11>).
Sticking to my code structure with background-image, related css rules of course is not necessary, there could be even pure svg solutions with <text/> tags just to achieve the expanding tab as the text grows with non-stretching side paths.
Related interesting links:
https://www.sarasoueidan.com/blog/mimic-relative-positioning-in-svg/
https://codepen.io/gionkunz/pen/KDvLj
https://jsfiddle.net/boldewyn/taorj2q6/

Ok I tried changing this for you, and used pure CSS with 3 classes (left, middle, and right) - with different SVG base64 data for each. Still feels a bit hacky, but let me know if this is closer to what you are looking for.
$(document).ready(function(){
$('.nav-tabs li').click(function() {
$(this).siblings('li').removeClass('active');
$(this).addClass('active');
});
});
ul {
display:block;
width: 100%;
}
li {
list-style:none;
}
.tabbed {
display:inline-block;
}
.nav-tabs {
display: inline-flex;
width: 100%;
}
.tab-content {
margin-top:50px;
margin-left:70px;
}
.tabText {
position:relative;
color:white;
display:inline-block;
z-index:10;
padding:10px;
height:35px;
vertical-align:top;
}
.left {
display:inline-block;
margin:0;
padding:0;
height: 35px;
width: 35px;
background-image: url("data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns:cc='http://creativecommons.org/ns' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 30 35' enable-background='new 0 0 30 35' xml:space='preserve'%3E%3Cpath id='left' fill='%2325437F' d='M0,35h30V0C6.4,0,11.8,35,0,35z'/%3E%3C/svg%3E");
background-repeat:no-repeat;
background-size:cover;
}
.middle {
display:inline-block;
margin:0;
padding:0;
background-color: #25437F;
background-image: url("data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns:cc='http://creativecommons.org/ns' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 56.5 35' enable-background='new 0 0 56.5 35' xml:space='preserve'%3E%3Crect id='middle' fill='%2325437F' width='56.5' height='35'/%3E%3C/svg%3E%0A");
background-repeat:no-repeat;
background-size:cover;
width:auto;
height:35px;
margin-left:-6px;
}
.right {
display:inline-block;
margin:0;
padding:0;
height: 35px;
width: 35px;
margin-left:-6px;
background-image: url("data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns:cc='http://creativecommons.org/ns' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 30 35' enable-background='new 0 0 30 35' xml:space='preserve'%3E%3Cpath id='right' fill='%2325437F' d='M30,35H0V0C23.6,0,18.2,35,30,35z'/%3E%3C/svg%3E%0A");
background-repeat:no-repeat;
background-size:cover;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="product-info tabbable">
<div class="row">
<ul class="nav nav-tabs">
<li class="active">
<a href="#" data-toggle="tab">
<div class="tabbed">
<div class="left">
<div class="tabText"></div>
</div>
<div class="middle">
<div class="tabText">Details</div>
</div>
<div class="right">
<div class="tabText"></div>
</div>
</div>
</a>
</li>
<li>
<a href="#" data-toggle="tab">
<div class="tabbed">
<div class="left">
<div class="tabText"></div>
</div>
<div class="middle"><div class="tabText">Other important specification</div></div>
<div class="right">
<div class="tabText"></div>
</div>
</div>
</a>
</li>
</ul>
</div>
<div class="row">
<div class="tab-content">
lorem ipsum
</div>
</div>
</div>

Related

cant move ul.width to width:0px

I have the following code:
<div class="filter">
<ul>
<span class="filter-icon text-gray-lightest"> <!-- svg-inline--fa -->
<svg xmlns="http://www.w3.org/2000/svg" class="" viewBox="0 0 24 24" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><polyline points="15 6 9 12 15 18"></polyline></svg>
</span>
<li data-filter="f0">Alle</li>
<li data-filter="f1">Verw/Fin</li>
<li data-filter="f2">MaPa</li>
<li data-filter="f3">Presse</li>
<li data-filter="f4">Programme</li>
<li data-filter="f5">Inland</li>
<li data-filter="f6">Controlling</li>
</ul>
</div>
with this css:
.filter {
margin: 1px 0 1px 0;
width: 40%;
background-color:red;
overflow:hidden;
}
.filter ul {
padding-left:8px;
}
.filter-icon {
display: inline-block;
fill: currentColor;
stroke: currentColor;
vertical-align: middle;
transition: transform .5s;
height:16px; width:16px;
}
.filter-icon:hover {
fill: var(--orange);
stroke: #000;
transform:rotate(180deg);
}
.filter ul li {
display:inline-block;
padding:15px;
position:relative;
}
.filter:hover {
width:50px;
}
I would like to change the width of the div.filter with javascript to 0px.
for better test i made here a filter:hover to 50px.
Please see codepen
My Problem is, that the filter-box gets higher. But I would like that the content of the filter-box disapear (by overflow:hidden).
How to achieve this?
let filter = document.getElementsByClassName("filter")[0];
filter.addEventListener("mouseover", function(){filter.style.display = "none"});
filter.addEventListener("mouseout", function(){filter.style.display = "block"});

CSS Menu Layout - Make div take up remaining vertical space

Given the below fiddle:
Fiddle
What i'm looking to do is have the first column expand vertically in order to take up the remaining vertical space. Basically i want that right border to be equal across all the columns.
I'm a relative css/front-end newbie. Any ideas on how i can get this fixed up?
Full code below:
<html><head></head><body class="Body" onload="checkCookie()">
<div id="Container">
<div id="menu" class="clearfix">
<div class="menuItem" id="wallPopsMenuItem">
<a href="/wall-pops.aspx">
<div class="area">peel & stick</div>
<div class="category">Wall Decals</div>
</a>
<div class="subMenu" id="wallDecorSubMenu">
<div class="subMenuColumn">
<div class="inner">
<div>All Products</div>
<div>New</div>
<div>Popular</div>
<div>On Sale</div>
</div>
</div>
<div class="subMenuColumn">
<div class="inner">
<div class="title">Wallpops</div>
<div>
<ul>
<li>All Wallpops</li>
<li>Wall Art Kits</li>
<li>Wall Art for Kids</li>
<li>Wall Art for Nursery</li>
<li>Dot, Blox, Stripes</li>
<li>NuWallpaper</li>
<li>Room Dividers</li>
<li>Decorative Room Panels</li>
<li>Dry-Erase Decals</li>
<li>Chandeleiers</li>
<li>3-D Animal Heads</li>
<li>Hard Boards</li>
<li>Jewel Accented</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<style type="text/css">
body { color: #333; font-family: Gill Sans MT, Verdana, Arial, sans-serif; font-size: small; margin: 0 auto; text-align: left;position: relative;}
#Container { max-width: 960px;margin: 0 auto; }
.subMenu{padding: 5px;font-family: Arial;font-size: 9pt;text-transform: lowercase;background: white;display: none;position: absolute;z-index: 1;text-align: left;margin-left: 20px;box-shadow: 5px 5px 10px rgba(102, 102, 102, .7);}
#wallPopsMenuItem:hover #wallDecorSubMenu{ display: block;}
#dryEraseMenuItem:hover #dryEraseSubMenu{ display: block;}
.subMenu div, li{ padding: 2px 5px 0 0;}
.subMenu ul{ list-style: none;padding-left: 10px;margin: 0;}
.subMenu .subMenuColumn{float: left;height: 100%;}
.subMenu .inner{border-right: 1px solid #6a033d;height: 100%;padding: 0 10px 0 10px;}
.subMenu .shopBy{height: 100%;border-right: none;margin-left: 20px;min-width: 275px;}
.subMenu .title{ text-transform: uppercase;}
#menu{ position: relative;margin-top: 30px;}
#menu .menuItem{ float: left;width: calc(100% / 6);text-align: center;}
#menu .area{ color: #e86d1f;font-family: Arial;font-size: 10pt;text-transform: lowercase;}
#menu .category{color: #e86d1f;font-family: Arial;font-size: 11pt;font-weight: bold;text-transform:uppercase;}
.clearfix::after {
content: " ";
display: block;
height: 0;
clear: both;
}
</style></body></html>
Replace display: block with display: flex for #wallPopsMenuItem:hover #wallDecorSubMenu and remove float: left, height: 100% from .subMenu .subMenuColumn.
Updated JSFiddle

Twitter Bootstrap: Collapsing menu for higher resolution screen such as Large desktop

I am building my website using twitter bootstrap. I want to specifically target my website for smartphones and tablet device. The nav bar is perfectly getting collapse for smartphone and ipad(portrait mode) devices. I need the same collapsed navbar for higher resolution devices such as ipad landscape mode and large desktop.
In bootstrap-responsive.css file if I can max-width from 979px to higher resolution such as 1024px and 1200px it did work. Is this a correct approach?
Navbar snippet
<div class="navbar navbar-fixed-top navbar-absolute">
<div class="navbar-inner">
<div class="container" style="width: auto;">
<a class="btn btn-navbar custom-collapse-btn" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="http://www.test.com/" target="_blank"><img src="img/logo.png" border="0" /></a>
<div class="pull-right icon-custom-search"></div>
<div class="nav-collapse">
<ul class="nav">
<li>
<ul class="nav" id="nav-menu-left">
<li>LMenu1</li>
<li>LMenu2</li>
<li>LMenu3</li>
<li>LMenu4</li>
<li>LMenu5</li>
<li>LMenu6</li>
</ul>
</li>
<li>
<ul class="nav" id="nav-menu-right">
<li><img src="img/icon-newsletter.png" border="0" /> Rmenu1</li>
<li><img src="img/icon-register-login.png" border="0" /> Rmenu2</li>
<li><img src="img/icon-download-app.png" border="0" /> RMenu3</li>
</ul>
</li>
<div id="nav-copyright-text"><a href="#">This is test text/a></div>
</ul>
</div><!-- /.nav-collapse -->
</div>
</div><!
-- /navbar-inner -->
</div>
Navbar custom CSS
.navbar-inner {
background-color: #13417c !important;
background-image: none;
background-repeat: no-repeat;
filter: none;
padding:0 !important;
border: 1px solid #000000;
}
.navbar .btn-navbar {
padding:15px 10px;
margin-right:0;
}
.navbar .btn {
margin-top:0;
margin-left:0;
}
.navbar-inner .btn-navbar {
background: black;
}
.navbar .btn-navbar:hover {
background: black;
color:black;
}
.navbar .btn-navbar:focus, .navbar .btn-navbar:active {
background: black;
color:black;
}
#rotate {
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
-o-transform:rotate(90deg);
/* filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=1.5); */
-ms-transform:rotate(90deg);
}
.icon-custom-search {
color: #fffafe;
background: url('../img/search_bg.png') no-repeat;
height: 43px;
padding-left: 46px;
}
.custom-collapse-btn {
border-radius: 0 !important;
-webkit-border-radius:0 !important;
-moz-border-radius:0 !important;
}
.nav-collapse.collapse {
background-color: #000000;
}
.navbar .nav > li {
line-height: 16px;
}
.nav-collapse .nav > li > a:hover {
background-color:#000000;
}
.nav-collapse .nav > li > a {
text-shadow:none;
}
#nav-menu-left {
width:49%;
float:left;
border-right: 1px solid #808080;
margin-top: 20px;
}
#nav-menu-right {
width:50%;
float:left;
margin-top: 20px;
}
#nav-menu-left > li > a {
color: #ffffff;
}
#nav-menu-right > li > a {
color:#85b3e5;
font-weight: normal;
}
#nav-menu-right > li > a > img {
padding-right:10px;
}
#nav-copyright-text {
clear:both;
}
#nav-copyright-text a {
color: #666666;
font-weight: bold;
padding: 10px;
}
#nav-copyright-text {
text-align: center;
}
#nav-copyright-text a:hover{
text-align: center;
text-decoration: none;
}
editing core files is an bad idea. insisted make use of media queries and get your tasks done.
<link rel='stylesheet' media='screen and (min-width: 979px) and (max-width: 1024px)' href='css/medium.css' />
and get your task done more efficiently.

css text-align/positioning question

The situation: I have several lists; in each of these lists, the text inside the first li is positioned slightly to the right of center, instead of exactly in the center like the following li elements. In the following example, the second row text ("Site Map") is not centered. Any ideas?
The html:
<body>
<!-- <div class="header">Module Settings</div> -->
<div class="left_content">
<div id="header_nav" class="moduleTypeContent" style="top:-50px" name="header_nav">
<div class="moduleTypeHeader">
<div class="text-center">header_nav</div>
</div>
<ol class="connectedSortable sortable used nonest">
<li id="list_39">
<div class="listItemContents">
<div class="moduleTypeItem left">
<img src="common/images/icons/shadowed/cross-circle.png" alt="Delete Site Map" width="16" height="16" border="0" class="icon rightspace" />
</div>
<div class="moduleTypeItem center text-center">
Site Map
</div>
<div class="moduleTypeItem right text-center">
all
</div>
</div>
</li>
<li id="list_38">
<div class="listItemContents">
<div class="moduleTypeItem left">
<img src="common/images/icons/shadowed/cross-circle.png" alt="Delete Contact Us" width="16" height="16" border="0" class="icon rightspace" />
</div>
<div class="moduleTypeItem center text-center">
Contact Us
</div>
<div class="moduleTypeItem right text-center">
all
</div>
</div>
</li>
<li id="list_6">
<div class="listItemContents">
<div class="moduleTypeItem left">
<img src="common/images/icons/shadowed/cross-circle.png" alt="Delete Help" width="16" height="16" border="0" class="icon rightspace" />
</div>
<div class="moduleTypeItem center text-center">
Help
</div>
<div class="moduleTypeItem right text-center">
all
</div>
</div>
</li>
</ol>
</div>
</div>
and the relevant css:
html, body {
height:100%
}
body {
margin: 0px;
font-size: 12px;
font-family: Arial;
font-family: Arial, Verdana, Univers;
background-color: #f0eff0;
}
ol {
border: 0 solid #aeaeae;
border-width: 0;
margin: 0;
padding: 0;
padding-left: 30px;
}
ol.sortable, ol.sortable ol {
margin: 0 0 0 25px;
padding: 0;
list-style-type: none;
}
ol.sortable {
margin: 4em 0;
}
.sortable li {
margin: 0 0 0 0;
padding: 0;
}
.sortable li div {
border: 0 solid #aeaeae;
border-width: 1px;
padding: 0px;
margin: 0;
cursor: move;
}
div.moduleTypeDiv {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 12px;
width:100%;
}
div.moduleTypeHeader {
border:1px solid #6d6d6d;
padding: 6px;
}
div.moduleTypeHeader {
background: #336699 url(../images/table_header_highlight.png) repeat-x bottom;
font-weight:bold;
color: #ffffff;
}
div.moduleTypeHeader a {
color: #ffffff;
}
.left_content{
width:48%;
float: left;
}
.moduleTypeContent{
position:relative;
top: -50px;
}
.moduleTypeHeader{
position: relative;
bottom: -48px;
}
.legendItem.left, .moduleTypeItem.left{
float: left;
width: 18px;
padding: 5px;
border:0px ;
border-right: 1px solid #aeaeae;
}
.legendItem.center, .moduleTypeItem.center {
padding:6px;
border:0px ;
}
.legendItem.right, .moduleTypeItem.right {
position: relative;
top: -25px;
float: right;
width: 100px;
padding:6px;
width:50px;
border:0px ;
border-left: 1px solid #aeaeae;
}
.listItemContents {
position:relative;
}
.text-center { text-align:center; }
Thanks!
p.s. I created a fiddle: http://jsfiddle.net/earachefl/c2bcc/
You are doing some really weird positioning on the right "column" elements by floating the right, but not actually leaving them any space for them on the line they belong, so they are pushed down a row and then using relative positioning is "hack" them back where you want them. And thus there is no item in the first line that would push the text left so that it would appear centered.
Simple solution: Use a table. Your code is a prime example of bad "CSS hacking" because of misunderstanding the rule "Don't use tables for layout". Please, use a table. Please.
EDIT:
Since you can't use a table, here's what you have to do:
Move the "right" column to the first position in the list item
Give the center column a right margin wide enough for the right column to fit it. (63px = 50px width + 2 * 6px padding + 1px left-border)
http://jsfiddle.net/Se87U/1/

Why no effect of text-align:center and margin:0 auto on positioned element? see live example

CSS
* {margin:0;padding:0}
/* General styles */
#gallery {
padding: 2em 0;
margin: 0 auto;
width: 840px;
font: small Verdana, sans-serif;
}
#gallery #photo-grid {
width: 100%;
margin: 0;
padding: 1em 0;
list-style: none;
}
#gallery #photo-grid li {
float: left;
margin: 0 10px 10px 0;
background: #def;
color: #333;
padding: 0.5em 1em;
}
#gallery #photo-grid li span.photo-title { bottom:-28px;
font-style:italic;
position:absolute;
width:200px
}
/* Positioning and initial formatting */
#gallery #photo-grid {
padding-left: 20px;
}
#gallery #photo-grid li a {text-decoration:none; width: 200px;
height:200px;display:block;background:red}
#gallery #photo-grid li a img {border:0; display: block;}
HTML
<ul id="photo-grid">
<li class="photo">
<a href="#" class="photo-link">
<img src="http://placehold.it/200x150" class="photo-img" width="200" height="150" >
<span class="photo-title">${photo-title}</span>
</a>
</li>
<li class="photo">
<a href="#" class="photo-link">
<img src="http://placehold.it/150x200" class="photo-img" width="150" height="200">
<span class="photo-title">${photo-title}</span>
</a>
</li>
</ul>
Live example http://jsbin.com/onavo
if i use positioning to keep image and bottom than margin:0 auto or text-align center doesn't work
My question is , I want to keep align vertically bottom and horizontally centered, in red box.
is this what you're trying to achieved?
CSS
#gallery{overflow:hidden; padding:10px;}
#gallery #photo-grid{list-style: none;}
#gallery #photo-grid .photo{position:relative; display:inline;}
#gallery #photo-grid .photo-img{border:none;}
#gallery #photo-grid .photo-title{position:absolute; bottom:4px; left:0; right:4px; background-color:#FF0000; padding:10px 2px 10px 2px; text-align:center;}
HTML
<div id="gallery">
<ul id="photo-grid">
<li class="photo">
<a href="#" class="photo-link">
<img src="http://placehold.it/200x150" class="photo-img" width="200" height="150" >
<span class="photo-title">${photo-title}</span>
</a>
</li>
<li class="photo">
<a href="#" class="photo-link">
<img src="http://placehold.it/150x200" class="photo-img" width="150" height="200">
<span class="photo-title">${photo-title}</span>
</a>
</li>
</ul>
</div>

Resources