How to hold three different text alignments in one CSS Box? - html

Good day,
I've got a simple CSS question.
I'm trying to change a table into a CSS box, but aligning the table content is difficult to me right now.
Below there's an example of what's inside of the css box i created. How can I align these three elements (calendar and icon to the left , a text link to the center, and the other date field to the right ?) correctly ?
I've tried several things but the problem is getting it aligned properly. I want to change everything in this application that has been created with tables, to css. And I've been an 80% succesful so far.
I'd like to see some easy to understand code, to see how I can apply it on my code.
Thank you for your kind help. I might be burned out due to stress.
[Calendar (icon) Link Date]
UPDATE #1
This is the code for what I'm saying:
<asp:UpdatePanel runat="server" ID="updHoldingsPanel" UpdateMode="Always">
<ContentTemplate>
<div class="sitenote">
<table valign="absmiddle" border="0" cellpadding="0" cellspacing="0">
<tr style="height: 19px">
<td valign="absmiddle" style="text-align: left; width: 9%;">
<asp:Panel ID="pnlDateZero" runat="server" Width="187px">
<table valign="middle" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="middle">
<asp:Label ID="Label1" runat="server" Text="As of" Width="40px"></asp:Label></td>
<td valign="middle" style="width: 80px">
<asp:TextBox ID="txtDate" runat="server" AutoPostBack="True" Width="80px" Height="15px" OnTextChanged="txtDate_TextChanged" ></asp:TextBox>
<%--<asp:TextBox ID="txtDate" runat="server" AutoPostBack="True" Width="80px" Height="15px" contentEditable="false" OnTextChanged="txtDate_TextChanged" ></asp:TextBox>--%>
</td>
<td valign="absmiddle">
<span style="float:left; vertical-align:top; padding-top:0px; padding-top:1px;">
<asp:ImageButton align="middle" ID="imgCalendar" runat="server" ImageUrl="~/images/calendar5.gif"/>
<%--<cc1:CalendarExtender ID="ceDate" runat="server" PopupButtonID="imgCalendar" Format="MM/dd/yyyy" TargetControlID="txtDate" FirstDayOfWeek="Monday"></cc1:CalendarExtender>--%>
</span>
</td>
</tr>
</table>
</asp:Panel>
<asp:Label ID="lblAsOf" Text="" runat="server" Visible="False"></asp:Label></td>
<td style="text-align:center; width: 27%;">
</td>
<td style="text-align:center; width: 11%;">
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LINK</asp:LinkButton>
</td>
<td style="text-align:left; width: 2%;">
<asp:UpdateProgress AssociatedUpdatePanelID="updHoldingsPanel" id="UpdateProgress1" runat="server" DisplayAfter="100" DynamicLayout="false">
<ProgressTemplate>
<asp:Image ID="Image3" runat="server" ImageUrl="~/images/live_com_loading.gif">
</asp:Image>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
<td valign="absmiddle" style="text-align: right; width: 1%;">
</td>
<td style="text-align: right; valign="absmiddle">
<asp:CheckBox ID="chkInclude" runat="server" AutoPostBack="true"
OnCheckedChanged="chkInclude_CheckedChanged" Text="Include Zero Holdings"
VerticalAlign="Middle" />
</td>
</tr>
</table>
</div>
AND THE CSS OF THE BOX IS :
.sitenote {
display:block;
padding:6px;
border:1px solid #bae2f0;
background:#e3f4f9;
line-height:130%;
font-size:13px;
margin-top: 0;
margin-right: 0;
margin-bottom: 0.5em;
margin-left: 0;
}

You need to combine float:left and float:right elements and text-align css property
Full code at : http://jsbin.com/ilano3/3/edit

<div style="float:left">left</div>
<div style="float:right">right</div>
<div style="text-align:center">center</div>

You can use something like this, I think that it's the simplest approach:
<style>
.wrapper {
width: 600px;
}
.column {
float: left;
width: 200px;
}
.first {
text-align: left;
}
.second{
text-align: center;
}
.third{
text-align: right;
}
</style>
<div class="wrapper">
<div class="column first">
icon
</div>
<div class="column second">
link
</div>
<div class="column third">
date
</div>
</div>
You can add CSS for .first, .second and .third to change their width, text alignment, color...
http://jsfiddle.net/T8JMM/2/

If you really need your data/text in columns, you shouldn't shun tables. Tables are used for tabular data and if that's what your data is then just keep using them. The only bad thing about tables is when you use it for design. It looks to me that what you are trying to display is tabular data so just use 'em :)
To check if your data is bound to be shown in tables, answer the following questions:
Should the icon, link and date be on the same row ALWAYS?
Is the date on the right side bound to the link on the left side?
If your answer is yes to both questions, just use a table.
Otherwise, use lists. Separate the icon, link and date data into lists like this:
<ul class="icon-list column">
<li>Calendar (icon)</li>
<li>Calendar (icon)</li>
<li>Calendar (icon)</li>
</ul>
<ul class="link-list column">
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
<ul class="date-list column">
<li>Date</li>
<li>Date</li>
<li>Date</li>
</ul>
Then using css, just float them and add some width:
.column {
float: left;
width: 33%;
}
Don't forget to clear the floats! :)

Try something like this:
<style type="text/css" media="all">
.row { border: 1px solid black; text-align: center; }
.row > .left { float: left; }
.row > .center { display: inline-block; }
.row > .right { float: right; }
/* after/inline-block (FF, IE5.5-7, S2, O9) */
.row:after { content: ""; display: block; height: 0; clear: both; visibility: hidden; }
.row { display: inline-block; }
.row { display: block; }
</style>
<div class="row">
<div class="left">Calendar (icon)</div>
<div class="center">Link</div>
<div class="right">Date</div>
</div>
The left and right divs are simply positioned with float and are contained within the float by the .row:after… CSS at the end. The center div will accept the row's text-align: center, since it's inline-block.
Note that the center piece is aligned based on the available space between the floats; multiple rows have have mis-aligned centers. Also, as it stands, too narrow of a width will cause the last piece (of left/center/right) to go to a new line; there may be a way to truncate it with overflow, but that depends on what you're going for.
Hope this helps!

Related

Unable to stretch HTML footer to the full width

I made a HTML email layout using table, the design is working fine in my machine but when I put the code to test in putsmail the footer moves to the left when I view the mail in the dekstop.
It should come like this:
Its coming like this:
My HTML code:
<!--Footer-->
<table class="footer">
<tr>
<td style="padding: 50px;background-color: #f7f7f7">
<table width="100%">
<p style="text-align: center; font-size: 12px; line-height: 1.5;">
Having Trouble with something?
<br>
Reach out to us support#vantagecircle.com
</p>
<img style="display: block; margin-right: auto;margin-left: auto; padding-bottom: 25px;" src="https://i.ibb.co/1Z05xTH/vc-footer-logo.png" width="120px" />
</table>
</td>
</tr>
</table>
My CSS code:
.footer{
align-content: center;
width: max-content;
position: relative;
}
Thank You in advance
It’s safer to use inline CSS for email templates, I also don’t think any email clients supports the align-content property or even max-content on width. Maybe try it like this:
<table width="100%">
<tr width="100%">
<td style="padding: 50px;background-color:#f7f7f7">
<div style="margin-left:auto;margin-right:auto;">
<p style="text-align: center; font-size: 12px; line-height: 1.5;">
Having Trouble with something?
<br>
Reach out to us support#vantagecircle.com
</p>
<img style="display: block; margin-right: auto;margin-left: auto; padding-bottom: 25px;" src="https://i.ibb.co/1Z05xTH/vc-footer-logo.png" width="120px" />
</div>
</td>
</tr>
</table>
Note that I'm using width inline there, and added a div in the inner td to align to the center.
Change the width: max-content; to width: 100%; and it should work.
You can read more about how "max-content" works here
Use width: 100% for the table.

Div is too small and text overcome

I'm working on my ASP.NET project (written in C#).
I can't code div to have the correct size for the text inside him. I want to have a div to capture the text well and resize itself when I shrink the page.
Can somebody help me, please?
Here is a photo with what happens.
Css code:
.box {
width: 500px;
height: 500px;
border: 1px solid #e0e4e8;
padding: 20px;
border-radius: 10px;
height: 100px;
color: #717171;
float: left;
position: relative;
display: block;
}
Html code:
<div class="box">
<p class="date">Datele contului</p>
<br />
<table class="profil">
<tr>
<td>Nume:</td>
<td>
<asp:Label ID="lblNume" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td>Prenume:</td>
<td>
<asp:Label ID="lblPrenume" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:Label ID="lblEmail" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
<hr />
</div>
Just remove the height attribute in css. (or)
Try Setting height to auto.
You have set height twice in your css. Remove Both.

I need help converting a table to responsive divs and do not know the best method

I need to convert this layout or look that is made with a table in html to Divs, I believe. The table's structure is two columns with an image on one side and text associated with the image on the other. When squeezed small enough (like on a mobile device) I need the columns to go from two to stacked or one column. I don't know whether I need to use breakpoints and never have... or if there's any other better responsive solution to replicate the structure I have included below. This needs to be made in the Wordpress Divi theme's text editor.
Right now I am trying to make this work using Materialize (https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css) within this codepen. I have no idea if materialize will even work within wordpress...
Codepen
https://codepen.io/robmatthews/pen/qebwor
<table height="557" style="width: 800px; border-color: #ffffff; background-color: #ffffff; height: 702px; margin-left: auto; margin-right: auto;" border="#fff">
<tbody>
<tr>
<td style="width: 373px; border-color: #ffffff; background-color: #ffffff;">
<h2><img src="http://projectorbach.com/wp-content/uploads/2019/07/clipboard.png" width="174" height="171" alt="" class="wp-image-35671 alignnone size-full" style="display: block; margin-left: auto; margin-right: auto;" /></h2>
<h2 style="text-align: center;"><span>Create Team Rosters</span><span></span></h2>
<div class="col"></div>
</td>
<td style="width: 373px; border-color: #ffffff; background-color: #ffffff;">
<div class="col">
<div class="col">Easily input new clients and team rosters.</div>
<div class="col"></div>
</div>
</td>
</tr>
<tr>
<td style="width: 373px;"><span>Easy to create and easy to use. Our player evals are done through a grid. We start with templates based on age group and sport. Then, you can customize the skills and stats you want to track.</span></td>
<td style="width: 373px;">
<h2 style="text-align: center;"><span class="blue"><img src="http://projectorbach.com/wp-content/uploads/2019/07/eval.png" width="181" height="167" alt="" class="wp-image-35673 alignnone size-full" /><br /> </span><span class="blue">Evaluate Your Players</span><span></span></h2>
</td>
</tr>
<tr>
<td style="width: 373px;">
<h2 style="text-align: center;"><img src="http://projectorbach.com/wp-content/uploads/2019/07/multisport_player.png" width="174" height="171" alt="" class="wp-image-35689 alignnone size-full" /></h2>
<h2 style="text-align: center;">More Features</h2>
</td>
<td style="width: 426px;">
<div>
<div class="row">
<div class="col">
<p><span class="s1" style="font-size: 15px;"><span class="s3"></span></span>
</p>
<ul class="ul1">
<li class="li1"><span class="s1">Eases communication with parents decreasing ambiguity</span></li>
<li class="li1"><span class="s2"></span><span class="s1">Customizable evaluation criteria</span></li>
<li class="li1"><span class="s2"><span class="Apple-tab-span"> </span></span><span class="s1">Create practice plans and share videos</span></li>
<li class="li2"><span class="s3">Share data and progression with your club</span></li>
</ul>
</div>
</div>
</div>
<div id="lipsum"></div>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p style="text-align: center;">
To change to a non-table layout you just need to structure your divs like a table. I have applied classes that make that clear.
The div with .my-wrapper is taking the place of the table itself. The div(s) with .my-row are serving as the table rows, and the ones with .my-cell are the columns/cells of the "table".
Using flexbox we get a flexible layout that can be controlled very easily and allow you to change the layout where you want. Simply by applying:
display: flex;
...to a div, it becomes a flex container and the immediate child elements (the divs with .my-cell in this case) become flex items. I put several comments in the code below to point out what each line is doing. There are borders added just to make the layout clearer. Run the snippet and view in full page mode so you can adjust the width of your screen and see the responsive change.
Repeat the row layout to build out the rest of the table.
A great resource for more info on flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
More info on media queries: https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
* {
box-sizing: border-box;
}
.my-wrapper {
max-width: 800px; /* use max-width instead of width to get automatic responsive flexibility */
margin: 0 auto; /* centers the container on the page */
border: 1px solid blue;
}
.my-row {
display: flex; /* direction row by default, the cells will be side by side to start */
}
.my-cell {
width: 50%;
padding: 20px;
display: flex; /* yep, the cells can get flexbox layout too */
flex-direction: column; /* each cell will have its content laid out vertically */
align-items: center; /* centers content horizontally */
justify-content: center; /* centers content vertically */
border: 1px solid red;
}
.my-cell img {
max-width: 100%; /* make the images responsive too */
height: auto;
}
#media (max-width: 500px) { /* change the max-width in the media query to whatever width you want, you can use min-width too if you prefer */
.my-row {
flex-direction: column; /* force the layout to stack the cells vertically */
}
.my-cell {
width: 100%; /* cells should be full width at this point */
}
}
<div class="my-wrapper">
<div class="my-row">
<div class="my-cell">
<img src="https://picsum.photos/200/300" />
</div>
<div class="my-cell">
<h2>Some title text</h2>
<p>Some paragraph text...</p>
<ul>
<li>whatever</li>
<li>you</li>
<li>want</li>
</ul>
</div>
</div>
</div>
Rob,
Adding a class to your table tag (class=responsive_table for this example) and writing a media query will stack the columns one below the other.
#media screen and (max-width: 400px) {
table.responsive_table {
display: block;
}
table.responsive_table td {
width: 100%;
display: block;
}
}
<table height="557" style="width: 800px; border-color: #ffffff; background-color: #ffffff; height: 702px; margin-left: auto; margin-right: auto;" border="#fff" class="responsive_table">
<tbody>
<tr>
<td style="width: 373px; border-color: #ffffff; background-color: #ffffff;">
<h2><img src="http://projectorbach.com/wp-content/uploads/2019/07/clipboard.png" width="174" height="171" alt="" class="wp-image-35671 alignnone size-full" style="display: block; margin-left: auto; margin-right: auto;" /></h2>
<h2 style="text-align: center;"><span>Create Team Rosters</span><span></span></h2>
<div class="col"></div>
</td>
<td style="width: 373px; border-color: #ffffff; background-color: #ffffff;">
<div class="col">
<div class="col">Easily input new clients and team rosters.</div>
<div class="col"></div>
</div>
</td>
</tr>
<tr>
<td style="width: 373px;"><span>Easy to create and easy to use. Our player evals are done through a grid. We start with templates based on age group and sport. Then, you can customize the skills and stats you want to track.</span></td>
<td style="width: 373px;">
<h2 style="text-align: center;"><span class="blue"><img src="http://projectorbach.com/wp-content/uploads/2019/07/eval.png" width="181" height="167" alt="" class="wp-image-35673 alignnone size-full" /><br /> </span><span class="blue">Evaluate Your Players</span><span></span></h2>
</td>
</tr>
<tr>
<td style="width: 373px;">
<h2 style="text-align: center;"><img src="http://projectorbach.com/wp-content/uploads/2019/07/multisport_player.png" width="174" height="171" alt="" class="wp-image-35689 alignnone size-full" /></h2>
<h2 style="text-align: center;">More Features</h2>
</td>
<td style="width: 426px;">
<div>
<div class="row">
<div class="col">
<p><span class="s1" style="font-size: 15px;"><span class="s3"></span></span>
</p>
<ul class="ul1">
<li class="li1"><span class="s1">Eases communication with parents decreasing ambiguity</span></li>
<li class="li1"><span class="s2"></span><span class="s1">Customizable evaluation criteria</span></li>
<li class="li1"><span class="s2"><span class="Apple-tab-span"> </span></span><span class="s1">Create practice plans and share videos</span></li>
<li class="li2"><span class="s3">Share data and progression with your club</span></li>
</ul>
</div>
</div>
</div>
<div id="lipsum"></div>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p style="text-align: center;">
You may change the breakpoint in media query where it says max-width

How to make JqueryUi Slider vertical-align middle?

here's my code:
<div class="search-option">
<div id="slider-days" class="search-opt-left"></div>
<input type="text" id="amount-days" class="search-opt-right input-small"/>
</div>
I want to make the slider and input field algin to the middle of the line.
How can i do that ? Thanks !
My CSS:
.search-opt-left {
float: left;
width: 250px;
vertical-align: middle;
}
.search-opt-right {
float: left;
margin-left: 20px;
}
This can be buggy.
What I usually do is make a table. And since table rows start with vertically-centered alignments, it's quite simple.
<div class="search-option">
<table cellspacing="0" cellpadding="0">
<tr>
<td>
<div id="slider-days" class="search-opt-left"></div>
</td>
<td>
<input type="text" id="amount-days" class="search-opt-right input-small"/>
</td>
</tr>
</table>
</div>
You may then alter your CSS to get rid of the un-needed stuff.

HTML formatting with styles -- Just give up and use tables?

I'll preface this question by stating I have historically used tables for my HTML formatting and am fairly good at getting it to look the way I'd like... I am aware that tables are meant for "tabular data" and not formatting. I always get a bit frustrated when I try to do it the "right way", so today I am seeking some help.
<div style="width: 90%;">
<div style="width: 50%; height: 75px; vertical-align: middle; float: left;">
<a href="a.html" style="margin: auto 0px auto 0px">
<img src="../../images/red_arrow_50.png" alt="a" width="50" height="50" style="border-width: 0px;" />
</a>
A Link
</div>
<div style="width: 50%; float: right;">
B Link
</div>
</div>
As you can see from my attempts above, I'd like for the image link and the 2 text links to all line up along the same horizontal line (i.e. text links at the center of the image). Depending on how wide the parent div is I'd like the A img/link and B link a reasonable distance from one another. I'd also like for the divs with the "float: left" and "float: right" styles to not extend south beyond the border of the parent div (for some reason it is doing that to me in firefox with the above code).
Please help set me straight? Am I the only one who finds "the right way" of formatting things to be a big pain in the rear? I'm hoping I'm missing something big that if corrected will get me going down the right path.
===============
Update, thanks for the comments, I went to jsfiddle and fiddled a table-based solution:
<table style="width: 90%; margin: 0px auto 0px auto;">
<tr>
<td style="width: 50%;"><img src="http://www.chemfindit.com/img/search_icon.jpg" alt="A" width="50" height="50" style="border-width: 0px; vertical-align: middle;" /><a href="a.htm" style="margin: auto 0px auto 0px; vertical-align: middle;" >A-Link</a></td>
<td style=""><img src="http://www.chemfindit.com/img/search_icon.jpg" alt="B" width="50" height="50" style="border-width: 0px; vertical-align:middle;" /><a href="b.htm" style="margin: auto 0px auto 0px; vertical-align: middle;" >B-Link</a></td>
</tr>
</table>
Yields the desired layout:
I think it must be my misunderstanding/usage of floats and positions that always stings me when I try div-based layouts.
Personally I'd do it like this - http://jsfiddle.net/spacebeers/nWNPm/7/
.magLink {
list-style: none;
height: 50px;
float: left;
margin: 0 50px 0 0;
}
.magLink li {
float: left;
height: 50px;
display: table;
}
.magLink li a {
height: 50px;
display: table-cell;
vertical-align: middle;
}
<ul class="magLink">
<li><img src="http://www.whg.uk.com/Image/Magnifying_glass_1.gif" width="50" height="50" /></li>
<li>Link A</li>
</ul>
You can just copy the <ul> to have more than one. Just adjust the right margin to space them out how ever you want. I've set up examples of single link, multiple links and links with extra styling for in in the JSFIddle.
EDIT:
JSFiddle's running pretty badly so here's an image of the output in case it's not working.
Vertical alignment can be a real pain in CSS but tables for layout have had their day man. Let them live out their days being used for tabular data in peace.
From what I can tell, your "floaters" are extending beyond the parent div because you have two 50% widths inside of a 90%. Try setting them both to 45%. Then set a class or an id on your two floater containers, set them to position:relative, set both your link and img within each floating div to position:absolute, and use left, right, top, and bottom to move them into place (the img and link will be confined to the relatively positioned parent div). Does this help?
Edit
<div style="width: 90%;">
<div style="width: 50%; height: 75px; vertical-align: middle; float: left; position:relative;">
<a href="a.html" style="margin: auto 0px auto 0px;">
<img src="http://www.chemfindit.com/img/search_icon.jpg" alt="a" width="50" height="50" style="border- width: 0px;" />
</a>
A Link
</div>
<div style="width: 50%; float: right; height:75px; vertical-align: middle; position:relative;">
B Link
<img src="http://www.chemfindit.com/img/search_icon.jpg" alt="b" width="50" height="50" style="border-width: 0px;" />
</div>
</div>
That is the code equivalent to your table layout.
I would have used jsfiddle but I got a 504 error... probably didn't hold my mouth right. :)