Cannot push dd over to the left - html

Still a CSS newbie, not quite sure what to do
I am having difficulty getting my dd elements to line up directly next to their respective dt elements. They seem to align far to the right and I'd like to be able to control their width span from position with 0 px
Here is an image of the resulting HTML:
If you look the blue boxes are lined up far to the right
Here is my HTML:
<div id="reviews">
<table cellpadding="0" cellspacing="0">
<tr class="reviewuserinfo">
<td width="1%"><img class="avatar" src="/avatar/35274"/></td>
<td>Traveler<br/>posted on 15 May, 2008</td>
<td align="right" style="padding-right:15px">Joined 2 years ago<br/>12 reviews and 49 comments posted</td>
</tr>
<tr class="reviewuserdata">
<td style="width:100%" colspan="3">
<table cellpadding="0" cellspacing="0" class="reviewchart">
<tr><td><h2>Overall Rating <img class="stars" src="/stars/3.9/large" /> <span class="rating">4.5</span></h2></td></tr>
<tr>
<td>
<dl>
<dt><span>QUALITY OF THE DANCERS</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>PRIVATE DANCES, VALUE FOR MONEY</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>OVERALL HOSPITALITY</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>GUEST TO DANCER RATIO</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>VARIETY OF DANCERS</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>VALUE FOR MONEY, COVER CHARGE</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>VALUE FOR MONEY, DRINKS</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>VALUE FOR MONEY, FOOD</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>OVERALL ATMOSPHERE</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
<dt><span>SOUND SYSTEM AND DJ</span></dt>
<dd><div class="bar"><div style="width:100%"></div></div></dd>
</dl>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
And here is my CSS:
#CHARSET "UTF-8";
.page {
position: relative;
background-color: #ffffff;
width: 1200px;
margin: 0px auto;
box-sizing: border-box;
border-left: 1px solid #d0d0d0;
border-right: 1px solid #d0d0d0;
}
table {
border:0px;
width:100%
}
table.reviewsouter .reviewleft{
width:800px
}
table.reviewsouter .reviewright{
width:400px
}
#reviewspotlight {
position: relative;
background-color:#000000;
height:111px;
z-index:19997;
font-family: DinWebCond, Sans-serif;
color:#ffffff;
}
#reviews {
position: relative;
background-color:#ffffff;
color:#000000;
border-right:1px solid #d0d0d0;
}
#reviews table tr.reviewuserinfo {
background-color:#f0f0f0;
height:60px;
border-left:1px solid #d0d0d0;
}
#reviews table tr.reviewuserinfo img.avatar{
position:relative;
width:40px;
height:40px;
margin:10px;
display: inline-block;
vertical-align: middle;
}
#reviews table tr.reviewuserinfo div {
display:block
}
#reviews table tr.reviewuserdata {
background-color:#ffffff;
height: 315px;
border-left:1px solid #ffffff;
vertical-align: top;
}
#reviews table td h2 {
position:relative;
display:inline-block;
white-space:nowrap;
font:24px/24px DinWebCond,Sans-serif;
margin:0px;
text-transform:uppercase;
/**padding:20px 0px 9px 15px;*/
/**padding-top:20px;*/
/**padding-left:20px;*/
}
#reviews table td h2 img.stars {
position:absolute;
margin-left:10px;
display:inline-block;
}
#reviews table td h2 span.rating{
position:absolute;
margin-left:145px;
display:inline-block;
color:#e85a06;
font-weight:bold;
}
table.reviewchart {
position:relative;
display:inline-block;
white-space:nowrap;
border-collapse: collapse;
font:14px/14px DinWebCond,Sans-serif;
margin:0px;
text-transform:uppercase;
/**padding:20px 0px 9px 15px;*/
padding-top:20px;
padding-left:20px;
}
table.reviewchart td.reviewlabel{
/**padding-top:15px;*/
padding-bottom:15px;
}
#reviews.dl {
position:relative;
margin: 15px 15px 15px 15px;
}
#reviews dt {
position:relative;
display:inline-block;
float:left;
width:300px;
/**text-align:right;*/
pointer-events:none;
margin:0px;
padding:3px 0px 2px 0px;
z-index:2;
}
#reviews dd {
position:relative;
display:block;
margin:0px;
padding:3px 0px 2px 0px;
z-index:1
}
#reviews dd .bar {
position:relative;
display:inline-block;
width:150px;
height:15px;
margin:1px 20px -1px 20px;
}
#reviews dd .bar div {
position:absolute;
left:0px;
top:0px;
height:100%;
background-color:#1f73b3;
border-top-right-radius:3px;
border-bottom-right-radius:3px;
}

If you want the blue bars to be positioned right beside the text, like this:
Then one option is to float the dt and dd elements, like this:
#reviews dt {
float: left;
clear: both;
}
#reviews dd {
float: left;
}
If you then want to control the spacing, like this:
Add a fixed width to your dt elements:
#reviews dt {
width: 260px;
}
If you don't want the text labels to wrap onto two lines and it isn't possible for you to know how wide the longest label will be, then I suggest converting your dl into a table and placing the labels and blue bars in separate table cells.

You have a width of 300px set for #reviews dt. If you remove that, they are no longer to the right.

Related

Html Table moving when displaying a glyphicon when hovered on Div

I'm trying to display a glyphicon in a table row when a div is hovered. I'm able to implement it but the whole table is moving somewhat left when hovered.
This is happening only because of the styling I used.
The working code: https://jsfiddle.net/nvarun123/DTcHh/22806/
html code:
<div id="container">
<div class="heading">
Section Heading
</div>
<table align="center" >
<tr>
<td id="label" align="right">Name:</td>
<td id="field" align="left"><a >Miachel Jackson<span style="padding-left:8px;padding-right:8px;" class="glyphicon glyphicon-pencil" id="test"></span></a><td>
</tr>
<tr>
<td id="label" align="right">Net Worth:</td>
<td id="field" align="left">$500 Million</td>
</tr>
<tr>
<td id="label" align="right">Place:</td>
<td id="field" align="left">Los Angels</td>
</tr>
</table>
</div>
CSS code:
#container{
border: 1px solid #E3E3E3;
border-radius:3px;
background-color:#E3E3E3;
padding:10px;
min-width:70%;
}
.heading{
font-family:sans-serif;
font-size:18px;
color:#33434e;
padding:15px;
}
table{
border: 1px solid white;
}
tr{
border:2px solid #E3E3E3;
}
td{
padding:12px;
padding-left:8px;
padding-right:8px;
padding-top:5px;
padding-bottom:5px;
}
#label{
font-family:sans-serif;
font-size:15px;
color:#546A79;
font-weight: bold;
text-align:right;
}
#field{
font-family:sans-serif;
font-size:15px;
color:#546A79;
font-weight: normal;
height:30px;
padding-left:12px;
cursor:pointer;
}
#container:hover #field{
background-color: #E4EBF1;
}
#container:hover #field:hover{
background-color:#7F96A3;
}
#container #test{
display:none;
}
#container:hover #test{
display:inline;
}
#field:hover #test{
color:white;
}
#field:hover{
color:#FFF;
}
a{
color:#546A79;
text-decoration:none;
}
#field:hover a{
color:#FFF;
text-decoration:none;
}
Please tell me where I'm going wrong.
To achieved expected result, use below
#container #test{
visibility:hidden;
}
#container:hover #test{
visibility:visible;
}
https://jsfiddle.net/Nagasai_Aytha/DTcHh/22810/
display:none, doesn't occupy space , so when display:inline is available on hover, creates extra space which shifts table.
visibility :hidden ,hides the glyphicon and occupies element space

Place a DIV side by side with a SPAN, inside another DIV

I need to place the promo div in the right side of the alert div, just like this:
Please, can some CSS expert help me with this code: https://jsfiddle.net/08rnpxbt/4/
body {
width:640px;
float:left;
margin:0 6px 0 6px;
padding:18px;
font-family:Arial, Helvetica, sans-serif;
}
p {
padding:0;
margin:8px 0 0 0;
}
div.alert {
padding:8px 12px 8px 12px;
margin:20px auto 20px auto;
text-align:justify;
border:2px solid #389CF2;
border-radius:8px;
background-color:#F5F5F5;
background-image:url(http://i61.tinypic.com/1oxi50.png);
background-repeat:no-repeat;
background-position:8px 11px;
}
div.alert span {
display:block;
//float:left;
padding-bottom:2px;
margin-left:40px;
font-size:15px;
line-height:1.3em;
color:#5C5C5C;
}
div#promo {
display:block;
width:80px;
height:32px;
padding:4px 2px 2px 2px;
text-align:center;
line-height:15px;
font-size:14px;
color:#FF0000;
border:2px dotted #585858;
border-radius:16px;
background-color: #FFFFD5;
}
<body>
<div class="alert" style="width:530px; margin:0 auto 10px auto;">
<span>
<b>Windows 7 Home Premium - 02 License(s)</b><br>
Price: U$ 225.00 up to 10X or R$ 210.00 in cash
</span>
<div id="promo">15,00% de desconto !</div>
</div>
</body>
Just add this CSS rule to your #promo element:
#promo{
float: right;
}
and change this in your CSS:
div.alert span{
display: inline-block;
}
If you don' set inline-block the #promo will break in new line like you had it before.
Try it here
You can use flexbox attribute for this
just add display:flex and justify-content:space-between
div.alert {
display:flex;
justify-content:space-between;
padding:8px 12px 8px 12px;
margin:20px auto 20px auto;
text-align:justify;
border:2px solid #389CF2;
border-radius:8px;
background-color:#F5F5F5;
background-image:url(http://i61.tinypic.com/1oxi50.png);
background-repeat:no-repeat;
background-position:8px 11px;
}

Display two divs inline

I need to display two divs one next to another on the same line, but I can't understand why the second one is slightly lower than the first one.
<div class="cont-title">
<div class="triang-header"></div>
<div class="h2-stripe">
<h2 itemprop="name">
Title
</h2>
</div>
</div>
This is the css:
.cont-title{
margin-right: -7px;
min-width: 90%;
max-width: 100%;
height:51px;
float:right;
text-align:right;
white-space: nowrap;
}
.triang-header{
position:relative;
width:39px;
height:38px;
display:inline-block;
background:url('../images/titlebar.png') no-repeat top left;
}
.h2-stripe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
What am I doing wrong?
I think you did not count the line-height,
should be like this the style for .h2-stripe:
.h2-stripe{
position:relative;
line-height: 23px; // <----
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
box-shadow: 2px 3px 5px 0 #555;
}
here it is an example with line-height:23px for .h2-stripe: http://jsfiddle.net/6a0ga3uq/
you misspelled your class
.h2-strispe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
should be
.h2-stripe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
The margin of your h2 element causes the second div to shift down. Also, you should vertical-align inline-block elements. See this updated snippet (also with corrected class name in CSS).
.cont-title{
margin-right: -7px;
min-width: 90%;
max-width: 100%;
height:51px;
float:right;
text-align:right;
white-space: nowrap;
}
.cont-title > * {
vertical-align: middle;
}
.triang-header{
position:relative;
width:39px;
height:38px;
display:inline-block;
background:url('http://placehold.it/39x38') no-repeat top left;
margin: 0;
}
.h2-stripe{
position:relative;
z-index:10;
display:inline-block;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
h2 {
margin:0;
}
<div class="cont-title">
<div class="triang-header"></div><div class="h2-stripe"><h2 itemprop="name">
Title
</h2>
</div>
</div>
In the second div, you have line height and lot of other stuff. So other elements can extend your div. If you want your div to be the same size regardless to its other elements you should change display attribute like this
.h2-strispe{
position:relative;
z-index:10;
display:inline-block;
box-sizing:border-box;
text-align:left;
background-color: #2A58AE;
margin:0;
height:38px;
min-width:80%;
line-height:38px;
box-shadow: 2px 3px 5px 0 #555;
}
You can see i added box-sizing to border-box and that will save the position of your div no matter what you do to inner elements

how to center the button inside a table cell

I'm trying to center a button inside the table by : text-align: center
However, it seems doesn't work for me.
Note: I used Display: table-cell combine with Vertical-align: middle to center the text of the button. As you can see the text of the first button "AAAAAAA" is in the middle.
Can someone help me to center the button without affecting the text of the button.
Thank you in advance.
Here's the example code:
http://codepen.io/anon/pen/pAcBx
I usually do
margin:auto;
display:block;
I guess #rhino answer works as well. Remember to remove
display:table-cell;
EDIT:
Keep in mind that doing this will get the a element content vertically centered, but if you also give the a element an arbitrary height, the surrounding background will not be centered.
Example 1: the text is vertically centered. But you set the button height to 32px and that surrounding container isn't:
table, tr, td{
border: solid;
}
.my_table {
width: 312px;
margin: 0 auto;
}
.dashed {
border-bottom:1px dashed #99F;
width:100%;
display:block;
position:absolute;
font-size:0;
top:43px;
}
/*BUTTON TABLE left CELL*/
.left_button_cell{
margin: 0 auto;
text-align: center; /*<---- NOT WORKING */
height: 50px;
padding-top: 10px;
line-height: 22px;
}
/*BUTTON TABLE right CELL*/
.right_button_cell{
text-align: center;
height: 50px;
padding-top: 10px;
line-height: 22px;
}
.inner_button {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background-color:#fbfbfb;
-webkit-border-top-left-radius:8px;
-moz-border-radius-topleft:8px;
border-top-left-radius:8px;
-webkit-border-top-right-radius:8px;
-moz-border-radius-topright:8px;
border-top-right-radius:8px;
-webkit-border-bottom-right-radius:8px;
-moz-border-radius-bottomright:8px;
border-bottom-right-radius:8px;
-webkit-border-bottom-left-radius:8px;
-moz-border-radius-bottomleft:8px;
border-bottom-left-radius:8px;
text-indent:0;
border:2px solid #dcdcdc;
display:block;
margin:auto;
color:#939393;
font-family:arial;
font-size:15px;
font-weight:normal;
font-style:normal;
height:32px;
line-height:16px;
width:104px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ffffff;
word-wrap:break-word;
vertical-align:middle;
}
.inner_button:hover {
background-color:#EBEBEB;
}
.inner_button:active {
position:relative;
top:1px;
}
<div class="dashed"></div>
<table class="my_table">
<tbody>
<tr>
<td class="left_button_cell">
<a class="inner_button" href="#">AAAAAAAA</a>
</td>
<td class="right_button_cell">
<a class="inner_button" href="#">BBBBBBBB BBBBBBBB</a>
</td>
</tr>
</tbody>
</table>
You could set the line-height to be also 32px, which would work for the first button, but the second one would break. Also, you could set a button padding of 6px to achieve the same result without declaring an explicit height (as css frameworks like bootstrap or materialize do) but the line break on the second button would result in uneven button sizes.
So, here's my suggested trick: set the a element line height to be 32px, then wrap its inner text in a span element where you reset the line-height to 16px:
table, tr, td{
border: solid;
}
.my_table {
width: 312px;
margin: 0 auto;
}
/*BUTTON TABLE left CELL*/
.left_button_cell{
margin: 0 auto;
text-align: center; /*<---- NOT WORKING */
height: 50px;
padding-top: 10px;
line-height: 22px;
}
/*BUTTON TABLE right CELL*/
.right_button_cell{
text-align: center;
height: 50px;
padding-top: 10px;
line-height: 22px;
}
.inner_button {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background-color:#fbfbfb;
-webkit-border-top-left-radius:8px;
-moz-border-radius-topleft:8px;
border-top-left-radius:8px;
-webkit-border-top-right-radius:8px;
-moz-border-radius-topright:8px;
border-top-right-radius:8px;
-webkit-border-bottom-right-radius:8px;
-moz-border-radius-bottomright:8px;
border-bottom-right-radius:8px;
-webkit-border-bottom-left-radius:8px;
-moz-border-radius-bottomleft:8px;
border-bottom-left-radius:8px;
text-indent:0;
border:2px solid #dcdcdc;
display:block;
margin: 0 auto;
color:#939393;
font-family:arial;
font-size:15px;
font-weight:normal;
font-style:normal;
height:32px;
line-height:32px;
width:104px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ffffff;
word-wrap:break-word;
vertical-align:middle;
}
.inner_button span {
line-height:16px;
display:inline-block;
}
.inner_button:hover {
background-color:#EBEBEB;
}
.inner_button:active {
position:relative;
top:1px;
}
<table class="my_table">
<tbody>
<tr>
<td class="left_button_cell">
<a class="inner_button" href="#">
<span>AAAAAAAA
</span>
</a>
</td>
<td class="right_button_cell">
<a class="inner_button" href="#">
<span>BBBBBBBB BBBBBBBB</span>
</a>
</td>
</tr>
</tbody>
</table>
EDIT 2019
You can achieve the same using flexbox. However, this means the border-spacing property does no longer apply so you need to do some fine tuning to the cell margins.
Basically, you set flex properties as:
.my_table tr {
display:flex;
}
.my_table td {
margin: 2px;
height: 60px;
display:flex;
flex-grow:1;
/* centering the button */
align-items:center;
justify-content:center;
}
.inner_button {
display:flex;
/* centering the text inside the button */
align-items:center;
justify-content:center;
/* plus the other properties */
}
With this you no longer need playing with spans, and the alignment of children is controlled explicitly.
table, td{
border: solid;
}
.my_table {
width: 312px;
margin: 0 auto;
}
.my_table tr {
display:flex;
}
.my_table td {
margin: 2px;
height: 60px;
display:flex;
flex-grow:1;
align-items:center;
justify-content:center;
}
.inner_button {
align-items:center;
justify-content:center;
display:flex;
width:104px;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background-color:#fbfbfb;
text-align:center;
border-radius:8px;
border:2px solid #dcdcdc;
color:#939393;
font-family:arial;
font-size:15px;
height:45px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
word-wrap:break-word;
}
.inner_button:hover {
background-color:#EBEBEB;
}
.inner_button:active {
position:relative;
top:1px;
}
<table class="my_table">
<tbody>
<tr>
<td class="left_button_cell">
<a class="inner_button" href="#">
AAAAAAAA
</a>
</td>
<td class="right_button_cell">
<a class="inner_button" href="#">
BBBBBBBB BBBBBBBB
</a>
</td>
</tr>
</tbody>
</table>
Anyway, once you switch to this layout there's no reason to stick to tables, and you might as well convert your layout to divs.
Change display: table-cell to display: inline-block:
.inner_button {
/* ... */
display: inline-block;
/* ... */
}
I added this to the TableCell and it centered my ImageButton. I think we were running into the same issue.
<asp:TableCell HorizontalAlign="Center" style="padding: 0px;">
<asp:ImageButton/>
</asp:TableCell>
Found my answer here: http://forums.asp.net/t/1418752.aspx?image+button+inside+table+cell
You can use the table-cell display property of the container div and set the vertical-align property to middle:
HTML
<div id="table">
<div class="row">
<div class="cell">
I'm your button
</div>
</div>
</div>
CSS
#table {
width: 300px;
display: table;
background: red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
height: 200px;
background: yellow;
vertical-align: middle;
text-align: center;
}
You can find the fiddle here.
this works
td{
align:center;
}
simple and easy... hope it helps

Positioning text in different CSS shapes

Unfortunately I’m going slightly mad trying to align the “date” numbers over the CSS shapes. The problem I have is I would prefer a “universal” CSS number format for simplicity (the date is a displayed variable with a class applied to the td). I then change the CSS class for the underlying cell shape depending on its state to give it a background. All the PHP works to output the thing but some of the numbers align central to the cell, others are too low in the cell (mid height bottom) and two of them are off the page on at the top.
This is where I am up to (very simplified but illustrates the alignment problem in a table) – JSFiddle http://jsfiddle.net/xLWCH/
.daynumber {font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000000; font-weight: bold; position:absolute; display: table-cell; width:20px; vertical-align:middle; top:-9px; text-align: center; vertical-align: middle;}
.halfdaystart {position:relative; border-top: 20px solid green; border-right:20px solid red; font-size:0; line-height:0; width:0;}
.halfdayend {position:relative; border-top: 20px solid red; border-right:20px solid green; font-size:0; line-height:0; width:0;}
.booked {width:20px; height:20px; background:red;}
.Prohalfdaystart {position:relative; border-top:20px solid green; border-right:20px solid yellow; font-size:0; line-height:0; width:0;}
.Prohalfdayend {position:relative; border-top: 20px solid yellow; border-right:20px solid green;font-size:0; line-height:0; width:0;}
.Profree {width:20px; height:20px; background:yellow;}
.SBhalfdaystart {position:relative; border-top:20px solid red; border-right:20px solid green; width:0; height:0;}
.SBhalfdaystart:before {content: ''; display:block; position:relative; background:lightblue; height:5px; width:20px; top:-20px;}
.SBhalfdayend {position:relative; border-top:20px solid green; border-right:20px solid red; width:0; height:0;}
.SBhalfdayend:before { content: ''; display:block; position:relative; background:lightblue; height:5px; width:20px; top:-20px;}
.free {position:relative; width:20px; height:20px; background:green;}
.SBfree {position:relative; border-top:20px solid green; border-right:20px solid green; width:0; height:0;}
.SBfree:before { content: ''; display:block; position:absolute; background:lightblue; height:5px; width:20px; top:-20px;}
<table width="20" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Halfdaystart
<div class='halfdaystart'> <!-- or other corresponding class above -->
<table width="100%" cellpadding=0 cellspacing=0 border=0>
<tr>
<td align=center class="daynumber">1</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
What is the best way to do this? Can it be done with a one size fits all CSS or will I have to create a separate class for the text (applied to the td) as well depending on what I want to display as the div class that controls the shape? Basically is there a quick and easy way to do this?