Trying to get numbers right aligned with right padding in a cell - css

I am trying to get the following effect where numerical entries in cells are right aligned but with 25px of right padding.
For some reason, I can't seem to override a setting of padding: 1 in my template.
The numbers end up without the padding-right. (what you see in the sample above was the result of tweaking the CSS in Inspect as described below)
The view code is
<div class="field">
<td><%= :number_of_rolls_fill %></td>
<span class="number_right"> <td><%= #bedsheet_line.number_of_rolls_fill %></td></span>
</div>
</tr>
The css in application.css (which rails uses for custom css in addition to the template)
.number_right {
/* used to right align numbers in table cells */
margin: 0 !important;
padding: 0 !important;
text-align: right !important;
padding-right: 25px !important;
}
I've tried a number of variations on this.
If I do an inspect I found that if I uncheck the padding: 1px in BOTH areas indicated I will get the effect I want.
My style sheet has
.art-article th, .art-article td
{
padding: 1px !important;
vertical-align: top;
text-align: left;
}
.art-article th
{
text-align: center;
vertical-align: middle;
padding: 1px !important;
}
pre
{
overflow: auto;
padding: 0.1em;
}
.preview-cms-logo
{
border: 0;
margin: 1em 1em 0 0;
float: left;
I could probably get the effect I want by changing my style sheet but I that would cause issues in other areas of the app.

Here is a working sample that is close to your current code. It uses your css and modifies the view only.
/* css */
td.number_right {
/* used to right align numbers in table cells */
margin: 0 !important;
padding: 0 !important;
text-align: right !important;
padding-right: 25px !important;
}
# view
<tr>
<td><%= :number_of_rolls_fill %></td>
<td class="number_right"><%= #bedsheet_line.number_of_rolls_fill %></td>
</tr>
Here is a jsfiddle showing the result.
You can get rid of the <div class="field"> and the <span class="number_right"> and apply the number_right class directly to your table cell. The syntax wasn't pretty before so this will clean that up. Also, if you moved the span inside the table cell you'd have to set width or display: block; to get it to align properly.
example with span inside the td:
/* css */
td span.number_right {
/* used to right align numbers in table cells */
margin: 0 !important;
padding: 0 !important;
text-align: right !important;
padding-right: 25px !important;
display: block;
}
# view
<td><span class="number_right">$80</span></td>

You need to target that element specifically:
.art-article td .number_right {
/* used to right align numbers in table cells */
margin: 0 !important;
padding: 0 !important;
text-align: right !important;
padding-right: 25px !important;
}
Also, the span should be inside the <td> element:
<td><span class="number_right"> <%= #bedsheet_line.number_of_rolls_fill %></span></td>

Related

<td style="width"> attribute works inline but not in external stylesheet

I'm trying to use external css to format a 3-column table with 100% width and column widths of 10%, 80%, and 10% respectively. All my td attributes work from the external stylesheet except width.
<td style="width:10%">
works in inline css, but not as an internal style or from the external stylesheet.
It will read td widths from the external css if I remove the 100% width attribute from the table, but then the width of my table changes depending on the amount of text in it.
I have tried using
table-layout: fixed;
with no success. I've also tried removing width from one column at a time with no effect. All the examples I can find use pixels instead of % widths.
Have I missed something simple about table design?
Here's the relevant part of my external css:
table.border td {
border-width: 5px;
padding: 10px;
border-style: ridge;
border-color: white;
border-collapse: collapse;
-moz-border-radius: 0px 0px 0px 0px;
vertical-align: top;
width: 100%;
}
td.edge {
background-color: green;
width: 10%;
}
td.center{
width: 80%;
background-color: pink;
}
and here's the table's html:
<table class="border" >
<tr>
<td class="edge"> hi there</td>
<td class="center">it's me</td>
<td class="edge"> bye there</td>
</tr>
</table>
The table it gives me has a wide first column and narrow second and third columns.
Correct the CSS as follows (just removing "td" from this line: "table.border td") and it will work as expected:
table.border{
border-width: 5px;
padding: 10px;
border-style: ridge;
border-color: white;
border-collapse: collapse;
-moz-border-radius: 0px 0px 0px 0px;
vertical-align: top;
width: 100%;
}
td.edge {
background-color: green;
width: 10%;
}
td.center{
width: 80%;
background-color: pink;
}
This is jsfiddle example: https://jsfiddle.net/r281bv1z/
Hope this may help.

Certain classes no longer working but show in css and html

Created my first wordpress site and everything was styled and working correctly until today. We added an ssl, switched everything over to https, and since then a couple of my css classes no longer work. Most of them do, but my styling for a specific table on the testimonials page and the media queries for tables no longer work.
When inspecting the html and css on the site, the html shows the classes on the elements and the css file shows the classes and their elements, but the classes are not being applied. The testimonals page the table with the images and buttons was centered and had the buttons overlapping the images but now none of that shows.
The css for this table is:
table.test {
width: 66%;
margin: auto;
}
td.nopad {
padding: 0 !important;
margin: auto;
text-align: center !important;
}
td.nopad-btn {
padding: 0 !important;
margin:auto;
text-align: center !important;
position: relative;
top: -10px;
}
And the html:
<table class="test">
<tr>
<td class="nopad"><img src="https://eyealivedrops.com/wordpress/wp-content/uploads/2015/11/group-people.jpg" alt="group-people" width="290" height="199" /></td>
<td class="nopad"><img src="https://eyealivedrops.com/wordpress/wp-content/uploads/2015/11/pets.jpg" alt="pets" width="290" height="199" /></td>
</tr>
<tr>
<td class="nopad-btn">People Testimonials</td>
<td class="nopad-btn">Pet Owner Testimonials</td>
</tr>
</table>
However, the site is not displaying these styles on the page and I can't figure out why..
This is the link to the full css file, in case its something somewhere else Thank you in advance to anyone who looks into this, I've been looking through the Q&A's here and can't find anything else that fits my problem.
You have an error in your CSS file...
#media screen and (max-width: 767px) {
table:not(.shop_table.woocommerce-checkout-review-order-table, .shop_table.cart {
display: block
;
}
You forgot to close the ), so the rest of your CSS is not loading proper.
It has nothing to do with http or https as it fails in both cases. You might have more css issues... I'll look further.
UPDATE
You also have this error:
.product-total {
padding: 0, 10px, 10px, 10px;
}
Should be:
.product-total {
padding: 0 10px 10px 10px;
}
UPDATE 2
You have another error here:
button.button,
input.button,
a.button,
input.wpcf7-form-control.wpcf7-submit {
background: #AABBD4 !important;
background-image: -webkit-linear-gradient(#AABBD4, #4873A6);
background-image: linear-gradient(#AABBD4, #4873A6) !important;
-webkit-border-radius: 28;
-moz-border-radius: 28;
border-radius: 28px;
text-shadow: 1px 1px 3px #666666;
font-family: 'Lato', 'Open Sans', Arial, sans-serif;
font-weight: 400;
color: #ffffff;
padding: 10px 20px 10px 20px;
text-decoration: none;
line-height: 95%;
}
Missing unit of measure on -webkit-border-radius: 28; -moz-border-radius: 28; which I assume should be px

I can't find an error, text-align in th tag

I can't find error, trying this for the last 1h.
Here is page http://kushke.5gbfree.com/SecondPage.html
I want to center "To do list" header
table {
border: 3px solid orange;
background-color: yellow;
width: 100%;
text-align: center;
}
td, th {
color: black;
border: 2px dashed black;
}
#th1 {
padding-right: 160px;
text-align: center;
}
<table>
<tr>
<th id="th1" nowrap><h3>To do list</h3></th>
<th><h3>Done</h3></th>
<th><h3> Hard</font></h3></th>
</tr>
</table>
The problem appears to be
#th1 {
padding-right:160px;
}
If you need padding, add it to both sides of the th:
#th1 {
padding-left: 20px;
padding-right: 20px;
}
You shouldn't use the padding property to maintain a certain width for the column of your table. By adding a padding property, you lose the center alignment.
So, remove
#th1 {
padding-right: 160px;
align: center;
}
and replace it with the code below:
#th1 {
width: 180px;
padding: auto;
}
Of course, you can set your custom width by modifying the value at the code snippet above.
Try to add this to th element: To do list
Because of your help, I have solved this.
No further comments needed, but if you want upvotes, write anything,
I will respond.
Best regards!

How can you center text (vertically and horizontally) in a table, and prevent cell resizing?

Overall what I'm aiming for is a table where all the text is centred, and when text is entered, the cells won't resize.
Originally my code was like this:
HTML
<table id="main_table">
<tr>
<td><div/></td>
<td><div/></td>
<td><div/></td>
<td><div/></td>
<td><div/></td>
</tr>
<!--several more rows here-->
</table>
CSS
#table-main
{
height:1000px;
width: 100%;
border-collapse: collapse;
border-spacing: 0;
table-layout:fixed;
}
#table-main td
{
background-color: #F3F5EF;
border: 1px #bbb solid;
color: #333;
font-family: sans-serif;
font-size: 100%;
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
cursor: default;
}
#table-main td > div {
overflow: hidden;
text-align: center;
vertical-align: middle;
height: 100%;
line-height: 20px;
}
Which appears like this. Not that the rows with text in them are higher than rows without text.
I read that you can stop this resizing by adding:
display: inline-block;
This does stop the resizing, but it then prevents the text from being centered:
Is there any way to have the best of both worlds? And in addition, is there any way to centre the text vertically as well?
Posted an example on Fiddle
CSS
table {width:100%;;}
table, th, td
{
border: 1px solid #eee;
}
table td{ padding:10px;
width:19% !important;
vertical-align: middle;
height: 80px !important;
overflow:visible;
line-height: 40px;
}
td > div {
overflow: hidden;
text-align: center;
line-height: 14px;
display:inline-block
}
HTML
<table id="main_table">
<tr>
<td align="center"><div>1</div></td>
<td align="center"><div>Please note, the easing function names changed in version 1.2.Please note, the easing function names changed in version 1.2. </div></td>
<td align="center"><div>3</div></td>
<td align="center"><div>4</div></td>
<td align="center"><div>5</div></td>
</tr>
</table>
EDIT
CSS update for better vertical align (please note rest of text is hidden ... Fiddle and old one
Okay while hsobhy posted some working code, I think a better solution is to explain how to fix the original code. Adding display: inline-block; to the div worked fine to get rid of the cell resizing, but then:
The table cells (not the div) needed to be specified as centered in order to get the horizontal centering:
#main_table td, #main_table th{
/*All the other properties*/
text-align: center;
}
I was setting the height of the div, which I shouldn't have. Removing it gave me vertical centering as well:
#table-main td > div {
/*Other stuff/*
height: 100%; /*This needed to go/*
}

CSS not working for button appearence - Internet Explorer

I Have the following HTML and CSS for the current scenerio:
As you can see, the search textbox and the filter dropdown are appearing perfectly in-line. But the button is appearing down.
Here is the HTML code for all the 3 controls:
<table>
<tbody>
<tr>
<td>
<div class="search_result_div">
<div>
<input type="text" style="width:200px;" id='searchButton' value="some text"><span> in </span>
<select id="filterDropdown">
<option value="all" selected="selected">All Areas</option>
<option value="docs">Documents</option>
</select>
<a onclick="return callSearch();" class="btn" id="searchButton" href="../sys/SearchResults.aspx?q="><span>Search</span></a>
</div>
</div>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</tbody>
</table>
Here is the CSS for all the controls:
.search_result_div a.btn
{
background: url("/images/bg_btn_left.gif") no-repeat scroll left center transparent;
display: inline !important;
float: none;
font-size: 11px !important;
line-height: 21px !important;
margin: 0 !important;
outline: medium none;
padding: 3px 0 3px 2px !important;
text-indent: inherit !important;
}
.search_result_div a.btn span
{
background: url("/images/bg_btn.gif") no-repeat scroll right center transparent;
font-weight: bold !important;
margin: 0 !important;
padding: 4px 8px 4px 6px !important;
}
Note: The button is divided into two images.
bg_btn_left.gif :
bg_btn:
Please suggest where am I going wrong?
Thanks
Try this:
<style type="text/css">
.search_result_div a.btn
{
background: url("bg_btn_left.gif") no-repeat scroll left top transparent;
display: inline !important;
float: none;
font-size: 11px !important;
line-height: 21px !important;
margin: 0 !important;
outline: medium none;
padding: 4px 0 3px 2px !important;
text-indent: inherit !important;
}
.search_result_div a.btn span
{
background: url("bg_btn.gif") no-repeat scroll right top transparent;
vertical-align:top;
font-weight: bold !important;
margin: 0 !important;
padding: 4px 8px 4px 6px !important;
}
</style>
Its one of the problems I had to go through myself. I think I solved it by setting all default margins and paddings to zero. See if that helps you.
*{margin:0px; padding:0px;}
or if its a problem of aligning use
vertical-align: middle;
For inline elements, you can use the vertical-align: middle; CSS property to align verticaly.
look here it is: http://jsfiddle.net/YUXxf/
your code is working as you wish but i think the image has a top border bigger which is pushing the image downwards..
I always add this css file css.reset to my project to make sure i don't use the default css settings defined by the browser.
Hey i think you should give to some properties your .search_result_div a.btn
as like this
input{
vertical-align:top;
}
.search_result_div a.btn{
display:inline-block;
vertical-align:top;
*display:inline; // for ie
}

Resources