Aligning buttons vertically - html

I am working on an add to cart button to something I am making.
Currently, I hardcoded a fixed margin space of:
margin: 10px 20px;
From the text Lab and + ADD ME!
As you can see, it works, but when I have classes of differing number of letters, the alignment is all messed up.
So I looked into having a Linux-style/C-style tab separator string that could allow me to denote a fixed separator length so all my elements would align vertically, using left-padding: 5em.
However, that did not work.
Could someone tell me how I could align all my add to cart buttons?
A sample of the HTML:
<div
class="margin-class-type"
>
<h4>
<div class="title-container">{{ $type }}
<a
href="javascript:void(0)"
class="btn btn-material-yellow-600 btn-xs btn-raised cart-button mdi-content-add-circle-outline">
Add Me!
</a>
</div>
</h4>
<table
class="table table-striped"
>
<th>Class</th>
<th>Section</th>
<th>CRN</th>
<th>Day</th>
<th>Time</th>
<th>Professor</th>
<th>Enroll</th>
<th>Max Enroll</th>
<th>Credits</th>

Depending on how your code is structured, there are several ways to accomplish this.
1) If your titles are not dynamic (you know that they will always be "Lab" and "Lecture") you could set a width on the title element's container that is equal to the width of your widest title with a little extra. Then, you place your "add to cart" button inside the container holding the title and position it absolute so it will line-up vertically always.
Example:
<div class="title-container"><h2>Lab</h2>Add Me</div>
<!-- YOUR TABLE -->
<div class="title-container"><h2>Lecture</h2>Add Me</div>
<!-- YOUR TABLE -->
<style>
div.title-container{width:300px;position:relative;}
a.cart-button{display:block;position:absolute;top:0;right:0;}
</style>
2) If the titles will be dynamic, you can use a bit of Javascript to loop through each and take the widest element, setting that as fixed-width for all others. This is a bit more involved and based on your question I am guessing it would be overkill.
Good luck!

You can add a div for lab and add me and for "button" float : right
or
you might create a div
and inside that 2 inner divs.
the left inner div should be of specific length (max length you expecting for a label,e.g.lab)
all inner divs are float left in this case
or any alternative way
basically you need to fix the positions anyway.
Thanks
Sam

Put your titles and buttons inside an inline element and give them a fixed width large enough to accommodate. No example of code or anything but you don't appear to need one Hope it fixes your problem.

Related

Aligning money numbers to the left bootstrap

Hi im having trouble with some money number alignment. I want my data do be aligned to the left side of the columns BUT the numbers of the money have to look relative to each other like in the screenshot.
This screenshot is what I have atm:
This is what I want to do:
Here is my structure:
<tr>
<td style="text-align: left">name</td>
<td style="text-align: right">money</td>
<td style="text-align: center">date</td>
</tr>
And the only css atm that I use for positioning is setting the widht of every of those td's to 30%
At first I thought I could position them simply by putting a <p> in there that would align the content to the right and give the rest its relative widht, however that way would be possible but then I get a ball of js or jquery that I prefer not to have.
I have bootstrap installed but as of now I havent really touched it in this project except for the column grid positioning.
Does anyone have some kind of way to achieve what I am trying, or can someone push me in the right direction? Thanks in advance.
ADDITION: Semi complete code sample:
Codepen
The above code is the whole section the table is located in but I copied all css relative to the issue and not every single css class my problem is reconstructed there exactly even the random <p> tag I tried is in there.
You should use two columns:
<div class="row">
<div class="col-lg-6">List of money values</div>
<div class="col-lg-6">[Empty]</div>
</div>
And align text to right in the first one:
<p class="text-right">Your text.</p>

Centered Button, Not Centered?

So, I'm attempting to make my own website (Yeah, I finally sucked it up and started doing markup, sigh) - problem I'm having is I'm trying to center a button, and it's offset a little. Without the <center> it's all the way to the left.
Also tried :
style="align-items:center"
<div id="form-container" style="align-items:center;">
<div>
<fieldset>
<center><input class="button0" value="Install Redux" type="button" /></center>
</fieldset>
</div>
</div>
You just have to put <center> before your <div> and close it after </div>.
Like this:
<center>
<div id="form-container" style="align-items:center;">
<div>
<fieldset>
<input class="button0" value="Install Redux" type="button" />
</fieldset>
</div>
</div>
</center>
I've also made a CodePen and a JSFiddle for you.
Try text-align:center on the parent, or use left:0;top:0;position:relative;webkitTransform:translate3d(-50%,0%,0%); where parent doesn't have position:static (the default)
I would also recommend checking out Bootstrap because it has a nice grid layout that lets you define which 12ths of the page you want columns to lay in, simply by defining classes like .btn-default or .nav or in your case class="col-xs-12" inside that other column
They also have really nice styles for forms and input buttons etc. (see video on my example site below)
Try resizing your browser while looking at their examples. Pretty much, you define class="col-xs-12" if you want it to appear as 12/12 width of the row on extra small (mobile) and LARGER devices, and you can mix them class="col-xs-12 col-md-6" so it will split the row on larger (tablet) size devices. It's the number 1 repository on GitHub, and only takes about 30 minutes to read through the Grid Layout and search around for "Nav" and "Button" elements.
I recently made a quick site http://neaumusic.github.io, feel free to check it out, and good luck
Two ways:
1) Set margin-left: auto; AND margin-right: auto; to the containing div OR
2) Set display:flex; AND justify-content:center;to the parent container.
Google flex box for a little more information, its very useful for layout once you get the hang of it.
As stated in the comments, the center tag is no longer supported.
What about if you try #form-container { text-align: center; } ? It will center all children, including button.
I would definitely recommend using flexbox, the only issue being ie8/9 support.
It really makes layout so much easier and you don't have to create very specific, often arbitrary margins to get your stuff to align nicely, particularly vertical alignment.
Your alignment options are split between the container and the items. It does row and column layout too.
Here is a link I used to get me started.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Freeze div that shifts from dynamically sized text

In the code below I have 3 divs, where the 1st and 3rd divs are tables that are filled with text of varying lengths (decided by the user) on a user submit. The 2nd div is an image. When a user submits and text is filled into the tables the center image (2nd div) moves depending on the length of text. For example, if the longest word of either tables is on the left table, the image will shift to the right, along with the right table. If the longest word in each table are the same length, nothing will move.
What CSS positioning can I use to ensure that the 2nd div stays centered no matter the length of text in the divs on either side of it? Essentially I want the 1st div to expand to the left and the 3rd div expand to the right, so that any change in the length of the <span> will not move the centered image at all
<div class="text_tables" id="left_table">
<table>
<tr>
<td>
<span class="output render" id="text1"></span>
</td>
</tr>
</table>
</div>
<div class="text_tables">
<img id="img1" src="{{ url_for('static', filename='img/img.png') }}">
</div>
<div class="text_tables" id="right_table">
<table>
<tr>
<td>
<span class="output render" id="text6"></span>
</td>
</tr>
</table>
</div>
Well, to honor those who say that tables shouldn't be used for layout, I've put together a little FIDDLE with just divs.
Is this the type of behavior you're looking for?
HTML
<div class='holderdiv'>
<div class='leftdiv'> asdfasdfasdf</div>
<div class='centerdiv'></div>
<div class='rightdiv'>ASDASDFASDFASDFASDF </div>
</div>
V 2.0
Ok, this FIDDLE seems to do much of what you want.
I'm a bit confused about exactly what you want. Do we need to parse all of the spaces out and line up the words in a single column in either wing?
Provide more details, and I can spiff it up a bit more.

vertically aligning thumbnails in bootstrap css?

I think this should be quite simple, but I just can't get it to work. In ASP.NET MVC I have a list of items like this:
<div id="FilmListContent" class="row">
<div class="span12">
<ul class="thumbnails">
#foreach (var film in Model.Films)
{
<li class="span4">
<div class="thumbnail">
<a href="#Url.Action("Details", "Films", new { id = film.ID })">
<img src="#(String.Format("../../Content/Uploads/{0}.jpg", new object[] { FileUpload.CheckImageExists(Server.MapPath("~/Content/Uploads/"), film.ID) ? "Image_Film_" + film.ID : "NoImage" }))" alt="#film.Title image" />
<span>
#film.Title (#film.Year, #film.MediaType_Name) </span></a>
</div>
</li>
}
</ul>
</div>
</div>
Generates a nice list with 3 items per row, but when the #film.Title etc. content wraps to the next line I get an empty position on the next line. Like this:
I've tried display: table-cell, vertical align text-bottom etc, but I can't get it to work. At the moment I have removed all css on the thumbnails. What css can I use to get 3 items per row no matter the size? Or do I need to fix the size?
This is caused by the varying height of the thumbnails. clear:left / clear:both will work but the boxes will still not be the same height (which is a minor detail).
Also, if doing responsive layouts, putting a clear after every three thumbnails will mess things up.
Another solution is to ensure the height of the contents inside the thumbnail. There are many ways to do this. In this example:
1) Either have an overflow:hidden with a text-overflow: ellipsis and an optional title attribute on the span with the full text.
2) Set a height on the variant text that allows two lines (or more) of text to wrap (and even then most likely a overflow: hidden)
Basically, you need to manage the height yourself and ensure that each box will have the same height.
Assuming you are using float: left to lay out the items, you can insert an element with clear: both after each set of three items to ensure that each line is positioned completely below the previous one.

justify align tagcloud in 100% width div?

hey guys,
i'm having a little problem which is probably really easy to solve for you. However i tried a long time now and i have no chance to get it done.
i'm retrieving a tagcloud from a database with different fontsizes. every tag is a link. and all tags have spaces between them.
all tags get printed into a div#tagcloud -> which is 100% in width and has text-align:justify
i wonder what i'm doing wrong in order to align them justified within the 100% div. i want to have more space between certain tags to have the same margin on the left and on the right.
e.g. this is my tagcloud. i made a new line out of every link to have a better structure in this forum here, however actually there is just one space between every link.
<div class="tagcloud">
<a style="font-size: 40pt;" title="6 posts" class="tag-link-5" href="http://mydomain.com/?tag=cars">cars</a>
<a style="font-size: 40pt;" title="6 posts" class="tag-link-6" href="http://mydomain.com/?tag=home">home</a>
<a style="font-size: 15pt;" title="3 posts" class="tag-link-10" href="http://mydomain.com/?tag=animals">animals</a>
<a style="font-size: 15pt;" title="3 posts" class="tag-link-9" href="http://mydomain.com/?tag=water">water</a>
<a style="font-size: 25pt;" title="4 posts" class="tag-link-8" href="http://mydomain.com/?tag=health">health</a>
<a style="font-size: 40pt;" title="6 posts" class="tag-link-7" href="http://mydomain.com/?tag=umbau">music</a>
</div>
any idea how i could solve that to make the tagcloud properly spaced inside of a 100% wide div?
css:
#tagcloud {
padding:15px;
line-height:22px; /*depending on the fontsizes set*/
text-align:justify;
}
thank you
text-align: justify;
This only works for multi-line columns. The last line will not be justified.
live example
In this example you can make the html-screen wider and smaller, and you can notice that the justification works only when the content has multiple lines. I'm afraid that I can't find a proper css-solution for your problem.
However, I've made a hack that you can use, but it only works when the page is wide enough for the tags.
hacked fix for one-line justified content
I am using a liner-span that has 300 pixels padding and only has one whitespace. Because of it's width, it will drop onto the next line and the first line will be justified. With the overflow hidden and the height, the tag-cloud box will always fit in the page. But when the page is too small to fit all the tags next to eachother, they will fall out of view. But it is one way to solve this problem...
If your question is about …
Web design and HTML/CSS layout, and your job title is "designer", ask on Doctype.
I had a similar problem. It only worked for me when I added spaces around the word inside the span. For example, like this worked:
<a class="tag-link-5"> cars </a>
whereas this did not:
<a class="tag-link-5">cars</a>