Centering text with CSS not behaving right. Will not center - html

I've been fiddling with this for 2 days, and can't seem to get it right. So thought I would ask for a resolution here. (I'm not a css expert and that is where the problem lies.)
So I have the following code:
<table class="demo">
<tr>
<th style="background:#FFFFFF;border:0px solid #FFFFFF;" WIDTH="140">
<img src="https://xxxxxxxxxx.com/images/genesys_logo_1.png" border="0"><BR><BR>
</th>
<th>
<form method="post" action="https://xxxxxxxxxx.com<?php echo $thisPage; ?>" onsubmit="return mysubmit(this);">
<input type="hidden" name="primary" value="<?php echo array_values($p_key)[$i]; ?>">
<input type="hidden" name="archived" value="y">
<input style="float: left; display: block;margin: 42px 0px 0px -1px ;!important;" type="submit" VALUE="&#9988"/>
</form>
<span style="font-size: 16px; !important;"><?php if(array_values($link_kt)[$i]!="") {?><?php } ?><?php echo $cust_name[$i]; ?><?php if(array_values($link_kt)[$i]!="") {?><?php } ?></SPAN>
<BR>
<span style="font-size: 11px; text-align: middle; !important;">PID: <?php if(array_values($link_oa)[$i]!="") {?><?php } ?><?php echo array_values($pid)[$i]; ?><?php if(array_values($link_oa)[$i]!="") {?><?php } ?></span>
<form action="<?php echo $linkUpdate; ?>" method="post">
<input style="float: right; display: block;margin: 6px -1px 0px 0px ;!important;" type="submit" value="✎ " />
</form>
</th>
</tr>
</table>
And the following css:
.demo {
width:100%;
border:0px solid #333333;
border-bottom: 1px solid #333333;
border-spacing:0px;
padding:3px;
border-collapse: collapse;
}
.demo th {
min-width:160px;
max-width:160px;
border:1px solid #333333;
padding:3px;
background:#999999;
font-family: 'Helvetica Neue', sans-serif;
font-size: 14px;
}
It displays the cell like this: Notice the 2 lines of text (in spans above) are NOT centered ... and it is driving me crazy !
I want everything to stay in place when resizing the screen. Right now the buttons are behaving perfectly but I cannot for the life of me get the text to stay centered.
Thoughts ?

I think this is the span that need to be centered
<span style="font-size: 16px; !important;"><?php if(array_values($link_kt)[$i]!="") {?><?php } ?><?php echo $cust_name[$i]; ?><?php if(array_values($link_kt)[$i]!="") {?><?php } ?></SPAN>
<BR>
<span style="font-size: 11px; text-align: middle; !important;">PID: <?php if(array_values($link_oa)[$i]!="") {?><?php } ?><?php echo array_values($pid)[$i]; ?><?php if(array_values($link_oa)[$i]!="") {?><?php } ?></span>
For making it centered give both the span a fixed width and margin:0 auto
For example if you want the width for the 1st span to be 1060px then in style add width and margin as:
<span style="font-size: 16px; width:1060px; margin:0 auto;"><?php if(array_values($link_kt)[$i]!="") {?><?php } ?><?php echo $cust_name[$i]; ?><?php if(array_values($link_kt)[$i]!="") {?><?php } ?></SPAN>
I hope this is what you are looking for:)

Not sure what your problem is, but two points which might help:
1.) It's text-align: center , not text-align: middle like in your code (for horizontal centering)
2.) A span is an inline element. To center something inside a span therefore doesn't do anything. You have to center the span inside it's parent, so in this case the table cell around it has to have text-align: center (or in your case actually the th - maybe you should insert a td here in case that doesn't work)

Related

Div stretching to browser width and not the content inside it

Hi i have a problem i need to fix i have a form that i need to put inside a box so i put the form inside a div and assigned a background-color to the div the only problem is the div is sretching the whole browser width when i want it to only stretch as far as the content.
Heres a screenshot:
Screenshot
CSS CODE:
.content-wrapper {
background-color: #FFFFFF;
width: auto;
height: auto;
}
.input-text {
background-image: url("images/input-text.png");
background-repeat: no-repeat;
width: 214px;
height: 39px;
font-size: 14px;
font-family: "custom font", Tahoma, sans-serif;
color: #9aa1aa;
border: none;
padding-left: 11px;
padding-right: 11px;
}
.input-text:focus {
background-image: url("images/input-textf.png");
color: #34495e;
outline: none;
}
HTML CODE:
<div class="content-wrapper">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<?php
echo $dbnameErr;
echo $dbuserErr;
echo $dbpassErr;
echo $dbhostErr;
?>
Database Name<input class="input-text" type="text" name="db-name" value="<?php echo $dbname;?>" ><br />
Username<input class="input-text" type="text" name="db-username" value="<?php echo $dbuser;?>" ><br />
Password<input class="input-text" type="text" name="db-password" value="<?php echo $dbpass;?>" ><br />
Database Host<input class="input-text" type="text" name="db-host" value="localhost" ><br />
<input type="submit">
</form>
</div>
You need an outer DIV styled text-align:center
<div style="text-align:center" >
Then you need to change the CSS for your content wrapper to:
.content-wrapper {
display:inline-block;
text-align:left;
background-color: #FFFFFF;
margin-left: auto;
margin-right: auto;
}
Note the first two lines and the last two lines.
I have to look this up every time I need to do it :)
.content-wrapper {
background-color: #FFFFFF;
width: 400px; //Set width of the content wrapper.
height: auto;
}
This will set your width of the content-wrapper width.

Unwanted borders appearing and div shifting positions in IE10 when div is clicked on

I tried searching for answers online, couldn't find anything.
When I click on a div in IE10, a thin red border appears. The intention is for nothing to happen when the divs are clicked on. I've tried "border:none" and "outline:none" on a few divs to test it out and that solution doesn't work.
Also, when some divs are clicked on, it shifts all adjacent divs over to the right.
Any ideas on what could be causing this and how to resolve them?
More info:
Neither of these issues are happening in Mozilla or Firefox.
Using Bootstrap.css for input field stylings but not for individual div
stylings.
I can include my code but the problem is occurring on
almost all other divs throughout my files
UPDATE:
I started to notice a pattern (still in process of testing all occurrences) that the red border appears when the div contains label tag and input type in it.
Below is the HTML/CSS/JS code.
HTML:
<div id="setup-container">
<div class="ppp-intro font-size-130">
<h1 class="center" style="margin-bottom: 30px;">TEXT</h1>
<h4 style="margin-bottom: 40px;">TEXT</h4>
</div>
<form action="/setup" method="post" class="form">
<div id="signup">
<?php foreach ( $results['setup'] as $setup ) { ?>
<div class="setup-wrapper">
<div class="settings-label"><input type="checkbox" name="setup[]" id="<?php echo strtolower( $setup->name ) ?>" class="setup" value="<?php echo $setup->id ?>" style="visibility: hidden" /></div>
<label for="<?php echo strtolower( $setup->name ) ?>" class="<?php echo strtolower( $setup->name ) ?>"><?php echo $setup->name ?></label>
<div class="setup-label"><?php echo $setup->name ?></div>
</div>
<?php } ?>
</div>
<div class="messageContainer"></div>
<div class="buttons"><input type="submit" name="setupSelect" value="Select" /></div>
</form>
<script type="text/javascript" src="/js/checkmate.js"></script>
<script type="text/javascript" src="/js/checkmateCall.js"></script>
</div>
CSS:
.setup-wrapper {
float: left;
width: 154px;
margin: 0 18px 22px 18px;
border: none;
outline: none;}
.setup-label {
text-align: center;
font-size: 110%;
font-weight: bold;
margin: 0 0 0 14px;}
.settings-label {
width: 20%;
float: left;}
#signup {overflow: hidden}
#signup label {float: left;}
#setup-container {
overflow: auto;
width: 980px;
margin-left: auto;
margin-right: auto;
padding: 10px;}
Thank you

How to align text in the center of an element without considering floated elements

Ok i got this markup
<th class="ai1ec-weekday <?php if( $day['today'] ) echo 'ai1ec-today' ?>">
<span class="ai1ec-weekday-date"><?php
echo Ai1ec_Time_Utility::date_i18n( 'l', $date, true );
?> </span>
</th>
which produces this output as the span has text-align: center
now i want to add a button which is floated to the right
<th class="ai1ec-weekday <?php if( $day['today'] ) echo 'ai1ec-today' ?>">
<div class="btn-group pull-right">
<button class="btn ai1ec-reveal-events"><?php _e( 'Reveal all events', AI1EC_PLUGIN_NAME ) ?></button>
</div>
<span class="ai1ec-weekday-date"><?php
echo Ai1ec_Time_Utility::date_i18n( 'l', $date, true );
?> </span>
</th>
and this is what i get
what i would like to obtain is that mondais still centered as it was before, but i would like to do that without using absolute positioning (if it's possible, of course)
the CSS ( i mean other than bootstrap CSS )
.ai1ec-week-view th .ai1ec-weekday-date,
.ai1ec-oneday-view th .ai1ec-weekday-date {
font-size: 10.5pt !important;
font-weight: normal !important;
}
.ai1ec-week-view th .ai1ec-weekday-day {
font-size: 9pt !important;
font-weight: normal !important;
}
.ai1ec-month-view th, .ai1ec-oneday-view th {
text-align: center !important;
}
see this approach: http://jsbin.com/uxejes/1/edit
(tested only on Fx18 and Chrome)
relevant css
button {
float: right;
margin-right: -100%;
position: relative;
left: -100%;
}
span {
display: block;
text-align: center;
}
the button (with position: relative) won't affect the position of the text contained inside the span element

The font is not being displayed at the bottom of the container?

This is my HTML code to display font with a background in a small container . .
here is the css
.cons_save h4{font:bold 22px/60px Arial,Helvetica, sans-serif;margin:20px 0px -15px 20px; color:#f78d1d;vertical-align: bottom; background:url(../images/save_bg_cons.png) no-repeat; width:151px; height:69px;}
im not able to put it ! in the bottom of that container whatever the other content above it in the container remains
My HTML CODE
<div id ="<?php echo $store->branch_id;?>Collect" style="display:block">
<span class="cons_save fl clr">
<h4><?php echo $save. " %"; ?> </h4>
</span>
</div>
First, I would write each property of the CSS separately as follows:
.cons_save h4 {
font-weight: bold;
font-size: 22px/60px;
font-family: Arial, Helvetica, sans-serif;
margin: 20px 0px -15px 20px;
color: #f78d1d;
vertical-align: bottom;
background: url(../images/save_bg_cons.png) no-repeat;
width: 151px;
height: 69px;
}
then, it seems that the class name does not match the one in the span tag.
You should actually try and set the class name in the header tag itself.
Don't put heading tags insides spans
<div id ="<?php echo $store->branch_id;?>Collect" style="display:block">
<div class="cons_save fl clr">
<h4><?php echo $save. " %"; ?> </h4>
</div>
</div>
And also heading having a lot of margin & padding by default. So might be the reason to come in the bottom. Be sure to clear it
.cons_save h4 { margin: 0;padding:0; }
It works without the reset too, check here
not sure what is the problem, if you could sepcify using http://jsfiddle.net/ then it would be nice.
anyway, i suggest you changing span to div, like this:
<div id ="<?php echo $store->branch_id;?>Collect" style="display:block">
<div class="cons_save fl clr">
<h4><?php echo $save. " %"; ?> </h4>
</div>
</div>
moreover, you have vertical-align which would not work, unless you add to your css display: table-cell [note: this will not work in IE7]:
.cons_save h4{display: table-cell;font:bold 22px/60px Arial,Helvetica, sans-serif;margin:20px 0px -15px 20px; color:#f78d1d;vertical-align: bottom; background:url(../images/save_bg_cons.png) no-repeat; width:151px; height:69px;}
I wouldn't recommend you to use that property (vertical-align) on block level elements. And don't put a heading inside a span.
Without changing the HTML I would do this:
#Collect{
border: 1px solid #ccc;
width: 151px;
height: 69px;
}
h4{
font-weight: bold;
font-size: 22px/60px;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
color: #f78d1d;
background: url(../images/save_bg_cons.png) no-repeat;
background:#eee;
position: absolute;
bottom: 0;
}​
You can even get rid of the span.

How to keep a facebook likebox on the same line as a header tag?

Hey, I want to add a likebox beside my header tag (h2) and keep it on the same line. So it appears like: This is the Title LikeBox
However what is happening is the likebox is going starting on a new line like this:
This is the Title
LikeBox
Is there anyone willing to help me with this? If it's possible?
My css is :
.post-details h2 {
border-bottom: 1px solid #E1E1E1;
font-size: 16px;
margin: 0 0 0 0;
padding: 0 0 5px 0;
font-weight: bold;
}
and html code is:
<h2><?php the_title(); ?><h2>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo get_permalink(); ?>" layout="button_count" show_faces="true" width="50" rel="nofollow"></fb:like>
Thanks for your time.
#jonny h1,h2,h3,<p> they all takes 100% width automatically . So, you have to given float to your h2 tag
.post-details h2 {
float:left;
border-bottom: 1px solid #E1E1E1;
font-size: 16px;
margin: 0 0 0 0;
padding: 0 0 5px 0;
font-weight: bold;
}
#fb-root {
float:right;
}
Use this instead:
<div id="fb-root">
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo get_permalink(); ?>" layout="button_count" show_faces="true" width="50" rel="nofollow"></fb:like>
</div>
<h2><?php the_title(); ?></h2>
Then in your CSS, add:
#fb-root {
float: right;
}