I want to create a worksheet addition of, say, two five digit numbers. Using text-decoration:underline;, I get something like the following:
12345
+ 12345
-------
Wrapping in a div and using
style="width: 8em; margin: 1em; font-family: courier; text-align: right;"
gives me something like the following:
12345
+ 12345
-------
which is marginally better than before. How would accomplish aligning the digits on the ones? To be clear, the digits will be the same length, but the best answer would be robust to two digits of size m and n where m does not necessarily equal n, but I'm willing to trade robustness for not requiring javascript.
12345
+ 12345
-------
^---- align the ones digit
Thanks in advance!
I removed width: 8em and added float: left.
<div style="float: left; margin: 1em; font-family: courier; text-align: right;">
12345<br />
+ 66612345<br />
-------
</div>
Live Demo
I feel like I've misunderstood the problem because this seems too simple a solution :)
This was rather fun to put together: Live Demo.
Note: Only tested on Firefox!
HTML:
<div class="worksheet">
<span>12345</span>
<span class="add">54321</span>
</div>
<div class="worksheet">
<span>123</span>
<span class="sub">45678</span>
</div>
<div class="worksheet">
<span>54321</span>
<span class="add">1234</span>
<span class="sub">987</span>
<span class="add">1357924</span>
</div>
CSS:
.worksheet {
border: 1px dotted #000;
display: inline-block;
font-family: monospace;
margin: 0.5em;
padding: 10px;
text-align: right;
}
.worksheet .add:before {
content: "+";
float: left;
margin-right: 0.5em;
}
.worksheet .sub:before {
content: "-";
float: left;
margin-right: 0.5em;
}
.worksheet span { display: block; }
.worksheet span:last-child {
border-bottom: 2px solid #000;
margin-bottom: 1em;
}
Related
I've tried the obvious approach of trying color:firebrick in everything I could think of, as you'll see in the css link. This is the only thing google says to do. I had it working a bunch of edits ago before making my list inline, but figured it would be an easy fix as it was easy to do in the first place.
I hope asking "whats wrong with my code" isn't too situation specific for the guidelines, but I'm stumped.
I know the title appears to be an easily googled, repeat question. But nothing I have researched has solved it.
I need it to look like this:
This is what I have so far:
#headings {
background-color: firebrick;
font-family: Arial, Helvetica, sans-serif;
padding-left: 3em;
padding-bottom: 0px;
margin-bottom: 0px;
}
#headings h1 {
color: white;
padding-top: 0px;
margin-top: 0px;
padding-bottom: 0px;
margin-bottom: 0px;
}
h2 {
color: thistle;
font-family: Arial, Helvetica, sans-serif;
padding-left: 3em;
padding-bottom: 0px;
margin-bottom: 0px;
}
#nav {
background-color: lightgrey;
color: firebrick;
padding: 0px;
margin: 0px;
}
#nav ul {
color: firebrick;
padding: 0px;
margin: 0px;
}
#nav li {
color: firebrick;
text-decoration: none;
display: inline;
padding-right: 10%;
padding-left: 4%;
}
#content {
padding: 2em;
}
.figure {
float: right;
width: 30%;
margin-right: 40px;
clear: both;
padding: 1em;
}
.equation {
text-align: center;
}
#footnotes {
text-align: center;
clear: both;
padding: 3em;
}
#footer {
text-align: center;
clear: both;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="HW2.css" />
<title>Math 300 Assignment 2</title>
</head>
<body>
<div id="headings">
<h1>A Mathematical Web</h1>
<h2>Roots of Polynomials</h2>
</div>
<div id="nav">
<ul>
<li>Home</li>
<li>The Quadratic</li>
<li>The Cubic</li>
<li>The Quartic</li>
<li>Galois Theory</li>
</ul>
</div>
<div id="content">
<h1>The Quadratic</h1>
<p>
A polynomial of degree two is called a quadratic, and an equation involving a quadratic polynomial whose value is zero is called a quadratic equation. The solutions of a quadratic equation are called the <i>roots</i> of the polynomial. Figure 1
shows the graph of a quadratic polynomial. The roots of the polynomial are the points where the graph crosses the <i>x</i>-axis.
</p>
<div class="figure">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f8/Polynomialdeg2.svg"> Figure 1. A quadratic polynomial<sup>*</sup>
</div>
<p></p>
<p>
The means of finding the roots of quadratic polynomials were known to the Babylonians and others thousands of years ago. Today, we can write our solutions more elegantly using modern mathematical notation. A general quadratic polynomial can be written
in the form
</p>
<p class="equation">
p(x) = ax<sup>2</sup> + bx + c.
</p>
<p>
Using this notation, we can write the roots of <i>p</i> as
</p>
<p class="equation">
( 1/(2a) ) ( -b ± [ b<sup>2</sup> - 4ac ]<sup>1/2</sup> ).
</p>
<p>
We can see that whenever <span class="equation">b<sup>2</sup> - 4ac < 0</span> then there are two complex roots with non-zero imaginary parts. If
<span class="equation">b<sup>2</sup> - 4ac = 0</span> then there is exactly one root, which is real. Otherwise, there are two real roots.
</p>
</div>
<div id="footnotes">
* By Original hand-drawn version: N.Mori Updated hand-drawn version: Rubber Duck (☮ • ✍) [Public domain], via Wikimedia Commons
</div>
<div id="footer">
Copyright © 2018 Kevin Cooper
</div>
</body>
</html>
Add Color to #nav li a not #nav li
#nav li a{
color: firebrick;
text-decoration: none;
}
#nav li
{
display: inline;
padding-right: 10%;
padding-left: 4%;
}
You want to change the a color so use:
li a{
color: firebrick;
}
To remove the line under text use to li a css:
text-decoration: none;
At present I have 2 columns of content displaying inline on the same line.
The next challenge I am trying to overcome is getting these two elements to be closer together on that same line.
I think I may have found the answer here, but not really sure what it means. If this is the correct way of achieving said outcome, an explanation of the contents would be very helpful: Two column width 50% css
Alternatively, I have the current CSS set up on my stylesheet:
.fields-1 {
float: left;
width: 46%;
text-align: center;
margin: auto auto auto 0;
}
.fields-2 {
float: right;
text-align: center;
display: inline;
width: 46%;
padding-top: 5px;
padding-left: -15px;
margin: auto 0 auto auto;
}
.fields-2 p {
font-size: 25px;
font-weight: 500px;
}
#disclaimer {
font-size: 16px;
line-height: 17px;
font-family: calibri;
font-style: strong;
padding-bottom: 15px;
width: 45%;
}
#your-name {
width: 45%;
margin-right: 2px;
}
#your-email {
width: 45%;
margin-right: 2px;
}
#NewsletterOptions {
width: 45%;
height: 45px;
}
<div class="fields-1">
<p style="text-align: center">[text* your-name id:your-name placeholder: "Team Name/Filmmaker"] <b>(required)</b></p>
<p style="text-align: center">[email* your-email id:your-email placeholder: "Email Address"] <b>(required)</b></p>
<p id="disclaimer">*Your e-mail helps us discuss your contribution with you; this email will not be used for any third party or internal promotions without consent.</p>
</div>
<div class="fields-2">
<p>Would you like 3 new short films to watch each month? </p> <br>
[select* NewsletterOptions id:NewsletterOptions "Yes sure, sounds good!" "Not at the moment, thank you." "Already signed up."]
</div>
Just for context it is 1 half of a contact form.
Any feedback or information, you can provide on this matter would be much appreciated.
Also, if you cold suggest a way for me to line up the Disclaimer text at the bottom with the other elements in that first '.div' I would be most grateful.
Kind regards,
Dan
You can put a wrapper around the two divs and use flexbox, which will give you a column-like distribution of the two divs next to each other:
.wrapper {
display: flex;
justify content: space-around;
}
In the snippet below I erased some superfluous stuff - not sure what you'd want to keep and what not.
.wrapper {
display: flex;
justify content: center;
}
.fields-1 {
width: 46%;
text-align: center;
}
.fields-2 {
text-align: center;
width: 46%;
padding-top: 5px;
}
.fields-2 p {
font-size: 25px;
font-weight: 500px;
}
#disclaimer {
font-size: 16px;
line-height: 17px;
font-family: calibri;
font-style: strong;
padding-bottom: 15px;
}
#your-name {
margin-right: 2px;
}
#your-email {
margin-right: 2px;
}
#NewsletterOptions {
width: 45%;
height: 45px;
}
<div class="wrapper">
<div class="fields-1">
<p style="text-align: center">[text* your-name id:your-name placeholder: "Team Name/Filmmaker"] <b>(required)</b></p>
<p style="text-align: center">[email* your-email id:your-email placeholder: "Email Address"] <b>(required)</b></p>
<p id="disclaimer">*Your e-mail helps us discuss your contribution with you; this email will not be used for any third party or internal promotions without consent.</p>
</div>
<div class="fields-2">
<p>Would you like 3 new short films to watch each month? </p> <br>
[select* NewsletterOptions id:NewsletterOptions "Yes sure, sounds good!" "Not at the moment, thank you." "Already signed up."]
</div>
</div>
So this is actually more of a question why that is and not how I fix it. I could easily make a hack and just give the middle two strings classes that position them correctly, but I would like to know why that is and how I can properly fix it.
Heres an image to show what I mean. All 4 divs have the same code, just different images and text, still the middle two have the "XXXX players" on a different position.
Heres my html and css code:
.lp-popular {
height: 705px;
}
.lp-popular .title {
margin-top: 91px;
margin-left: 457px;
}
.lp-popular .game {
display: inline-block;
width: 240px;
height: 383px;
background-color: rgba(8, 9, 11, 0.5);
margin-top: 35px;
margin-left: 6px;
margin-right: 6px;
}
.lp-popular .game .heart {
float: left;
margin-top: 21px;
margin-left: 20px;
}
.lp-popular .game span {
float: left;
margin-left: 12px;
margin-top: 10px;
font-weight: 500;
font-size: 18px;
color: #ffffff;
}
.lp-popular .game p {
float: left;
margin-left: 15px;
font-family: Arial;
font-weight: normal;
font-size: 14px;
color: rgba(255, 255, 255, 0.5);
}
<div class="lp-popular">
<img class="title" src="img/lp_popular_header.png">
<div align="center">
<div class="game">
<img src="img/lp_popular_game_lol.png">
<img class="heart" src="img/lp_popular_heart_full.png">
<span>League of Legends</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_dota.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>DotA 2</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_csgo.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>CS:GO</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_hs.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>Hearthstone</span>
<p>4000 Spieler</p>
</div>
</div>
</div>
Thanks in advance!
Add the following line of CSS to clear the floats of the game title:
.lp-popular .game p {
clear: both;
}
why the middle images have different location for 'XXXX players': reason is pretty simple. note that first and last images have string length of 17 characters including space [League of Legends] and 10 characters [Heartstone] which fills up the the whole width available for that row. but in case of middle images, the string lenght is 6 [DOTA 2] and 5 [CS:GO] which is not enough to fill that top row. Hence the next text/string comes up to fill this gap and there-hence you get the 'XXXX players' on the same row instead of second row despite of having same css rules for them.
Fix: as #Ryan and #Akatosh have already given suggestion on how to fix this i.e.
.lp-popular .game p {
clear: both;
// clear: left;
}
I have html something like this http://jsfiddle.net/nLt9unxa/5/ and I want to place 3 block .number__label, .text__label, and .from__input in one line. .form__input must be align to the right side of form and all 3 elements must be vertical align in one line. How to do this? And I don't want use display: table-cell
And also if you know very good tutorial or book about alignment, where described all possible alignment and receipts how to do it, like cheatsheet, please share link.
you forgot to put : after max-width and min-width in .number__label
DEMO
.number__label {
display: inline-block;
background-color: #ffffff;
border: solid 1px;
max-width:20%;
min-width:20%;
}
Use vertical-align: middle (or top, or bottom). Here is the fiddle: http://jsfiddle.net/1ddewjxd/
.class
{
vertical-align: middle;
}
to align elements to right set the parent element to text-align: right, and the child elements to text-align: left. You could also float: right, but that can complicate things.
.item__label {
text-align: right;
}
.number__label, text__label, form__input {
text-align: left;
}
Run this code snippet to check whether all your requirements are done or not? also check fiddle
Check CSS Layout or learn from W3School
form {
width:70%;
background-color: #dddddd;
font-size: 20px;
}
.itme__label {
display: block;
}
.form__item {
display: block;
padding: 3px 5px;
}
.number__label {
display: inline-block;
background-color: #ffffff;
border: solid 1px;
max-width 20%;
min-width 20%;
}
.text__label {
display: inline-block;
background-color: #888888;
max-width: 50%;
}
.form__input {
display: block;
min-width: 20%;
max-width: 20%;
font-size: 1em;
margin-left:120px;
}
<form>
<div class="form__item">
<p>
<label class="item__label">
<span class="number__label">
01 12 31 23 123 2452 34534 5345
</span>
<span class="text__label">
text label long long long very long long for two or more lines ong very long long for two or more linesong very long long for two or more lines
</span>
<input type="text" class="form__input" value="input text">
</input>
</label>
</p>
<div class="errors">
<p class="error">
some error
</p>
</div>
</div>
</form>
At the top of a page I've got two divs, one floated to the left and one to the right. I can place text with a border between them, however, I now need to stack two such areas of text between them.
Here's a Fiddle illustrating my problem: http://jsfiddle.net/TcRxp/
I need the orange box under the green box, with each center aligned with the other. The "legend" (floated to the right) used to be at the same level but is shifted down now.
I tried adding another table to the mix but that didn't help.
Excuse the markup - it's not real slick, I know. A few people have touched this over time and none of us are gurus at this.
And yes, I have lobbied for a designer to be added to the team but it hasn't happened yet.
Thanks,
Paul
UPDATE: Incorporating #Jeremy B's suggestion
Does it have to be via CSS changes? When dealing with scenarios like this, you need to be careful of the order in which the HTML elements are defined.
Look at the modification here: http://jsfiddle.net/TcRxp/8/
I was able to acheive what you needed by changing the order of the three DIVs and using the CSS suggesion from #Jeremy B
Essentially, the logic for the layout is
Draw the float-right content
Draw the float-left content
Draw the content in the middle (as it will now render to the right of the float-left content.
First make your top span a block element to stack them:
<span class="color status active bold" style="display:block">Status:</span>
then float the middle div left as well:
add float:left to #headmiddle in your css
It's always going to be difficult to get the desired results when you're combining CSS and tables-for-layout.
I would suggest simplifying your HTML:
<div id="headleft">a little search form here</div>
<div id="headmiddle">
<div class="active"><strong>Status:</strong> Active</div>
<div class="search">Search results displayed</div>
</div>
<div id="headright">
<dl>
<dt>Legend:</dt>
<dd>Status numero uno</dd>
<dd>Status two</dd>
</dl>
</div>
and your CSS:
div { padding: 2px; }
strong { font-weight: bold; }
#headleft { float: left; font-size: 0.8em; }
#headmiddle { float: left; font-size: 0.8em; }
#headmiddle div { border: 1px solid #000; margin-bottom: 3px; }
.search { background: orange; }
.active { background: #8ed200; }
#headright { float: right; font-size: 0.8em; }
dt { float: left; font-weight: bold; }
dd { margin-left: 4.5em; }
The result is semantically correct HTML, easier to read and therefore easier to modify in the future. Supporting fiddle.
If you need to do it with CSS, see my changes: Fiddle
I added the following:
#headmiddle span.status { display: block }
This will cause your spans to "stack".
I got it by putting together many different sources. Alex Coles' solution was closest right off the bat but the middle wasn't centered. It was much cleaner than my mess too. I started with the code from this post:
<style type="text/css">
.leftit {
float: left;
}
.rightit {
float: right;
}
.centerit {
width: 30%;
margin-right: auto;
margin-left: auto;
text-align: center;
}
.centerpage {
width: 80%;
margin-right: auto;
margin-left: auto;
}
</style>
</head>
<body>
<div class="centerpage">
<div class="leftit">Hello Left</div>
<div class="rightit">Hello Right</div>
<div class="centerit">Hello Middle</div>
</div>
(fiddle for above)
I took the elements Alex cleaned up which got me even closer to my goal, but the center color blocks were way too wide. From this question I learned about "max-width", which ended up being the final piece I needed...or so I thought.
Edit: max-width doesn't work in IE7 quirks mode (which I have to support) so from this page I learned how to tweak my css to work in IE7 quirks mode, IE8, and FF.
The final code (fiddle):
.leftit {
float: left;
font-size: 0.8em;
}
.rightit {
float: right;
font-size: 0.8em;
}
.centerit {
width:220px;
margin-right: auto;
margin-left: auto;
font-size: 0.8em;
}
#headmiddle div {
border: 1px solid #000;
margin-bottom: 3px;
}
.centerpage {
margin-right: auto;
margin-left: auto;
text-align: center;
}
strong { font-weight: bold; }
.search { background: orange; }
.active { background: #8ed200; }
dt { float: left; font-weight: bold; }
dd { margin-left: 4.5em; }
<div class="centerpage">
<div class="leftit">a little search form here</div>
<div class="rightit">
<dl>
<dt>Legend:</dt>
<dd>Status numero uno</dd>
<dd>Status two</dd>
</dl>
</div>
<div class="centerit" id="headmiddle">
<div class="active"><strong>Status:</strong>
Active</div>
<div class="search">Search results displayed</div>
</div>
</div>
Thanks to all the great answers - I learned a lot from this question.
Paul