Aligning labels at the center - html

I want to align 4 text labels at the center with a margin of 5px.
The Code:
.header_section span {
width: 100%;
}
.header_section min {
padding-left: 30%;
padding-right: 5%;
}
.header_section consume {
padding-right: 5%;
}
<div class="header_section">
<span class="min">Min</span>
<span class="consume">Consumption</span>
<span class="avg">Average</span>
<span class="max">Max</span>
</div>
Do I need to add an id instead of a class?
Do I need to use the label tag instead of the span tag?

<style>
.header_section{
text-align:center;
}
.header_section span {
width: 100%;
}
.header_section min {
padding-left: 30%;
padding-right: 5%;
}
.header_section consume {
padding-right: 5%;
}
</style>

Below style can do this. It adds a left-margin of 5px to all spans except the first.
.header_section{
text-align:center;
}
.header_section span + span {
margin-left:5px;
}
A bit improved version is here in this fiddle

Do I need to add an id instead of a class?
No
Do I need to use the label tag instead of the span tag?
No. Labels are for texts associated to a input in a form. Maybe is a list, depending of the semactic meaning.
.header_section{
text-align:center;
}
.header_section li{
display:inline-block;
margin-right:5px;
}
<ul class="header_section">
<li>Min</li>
<li>Consumption</li>
<li>Average</li>
<li>Max</li>
</ul>

Related

Hover pseudo-class affects other elements

I wrote the hover pseudo-class for all input and label elements as shown in the image ,but when when I hover my mouse on one label the other indent directly to the right
Preview
The code is shown:
<Style>
label {
width: 180px;
float: left;
text-align: right;
margin-right: 0.1em;
display:inline-block;
}
label[type:checkbox]+[type:radio]{
width: auto;
input:hover { font-size:25px }
label:hover { font-size:25px }
</style>
First of all, you should make clear that your markup is valid. As already mentioned in the comments, you forgot a curly brace { for your label[type...] descriptor.
To avoid the shifting of other elements on hover, you should make clear, that the hovered label height doesn't become greater than the height of the input element next to it. Therefore the line-height of the label and the height of the inputs should at least be 25px.
Since you haven't provided a Minimal, Complete, and Verifiable example the exact code is hard to guess, but the following should work:
input {
height: 25px; /* <- */
}
label {
width: 180px;
float: left;
text-align: right;
margin-right: 0.1em;
display: inline-block;
line-height: 25px; /* <- */
}
label[type:checkbox]+[type:radio] {
width: auto;
}
input:hover {
font-size: 25px
}
label:hover {
font-size: 25px
}

Need to right align in list number without using ol tag

I have a normal paragraph:
HTML:
<p><span>[1]</span> list-type-1</p>
<p><span>[2]</span> list-type-2</p>
...
<p><span>[10]</span> list-type-3</p>
CSS:
span {
text-align:right;
}
Need Output:
[1] list-type-1
[2] list-type-2
....
[10] list-type-10
But the list numbers are placed on left. So, how to fix right align.
Thanks in advance.
Set up span's width ie:
span {
text-align:right;
display:inline-block;
width:30px;
}
http://jsfiddle.net/hedgehog34/50tp475k/
Modify your css like this
span {
text-align:right;
float:right; // This style is responsible to put your list numbers on right side in your case
}
see Fiddle : https://jsfiddle.net/5mmgu9dk/
alternative
p{
padding-left: 35px;
position: relative;
}
span {
text-align: right;
position: absolute; top: 0; left: 0;
width: 30px;
}
<p><span>[1]</span> list-type-1</p>
<p><span>[2]</span> list-type-2</p>
<p><span>[23]</span> list-type-23</p>
<p><span>[10]</span> list-type-3</p>

CSS: How to align buttons and text horizontally

I have the following month selector:
It has a left and a right button with the text of the current month inbetween.
As you can see it doesn't look ok.
HTML:
<div id="seletor">
<a class="ui-button-icon-primary ui-icon ui-icon-circle-triangle-w" href="#" id="subtrair">subtrair</a>
<div id="mescorrente"></div>
<a class="ui-button-icon-primary ui-icon ui-icon-circle-triangle-e" href="#" id="somar">somar</a>
</div>
CSS:
#subtrair, #mescorrente, #somar {
display:inline-block;
vertical-align:top;
}
#subtrair, #somar {
margin-top:2px;
}
#mescorrente {
font-size:20px;
text-transform:uppercase;
padding:0 6px; /* optional padding.. */
margin-bottom:10px;
white-space: nowrap;
}
I tried all sorts of options in the display settings, like display:table and display:inline but it did not work.
In Chrome Dev Tools, if I uncheck and check again display:inline-block; it works!
What is wrong with this code?
Change the CSS for #mescorrente.
#mescorrente {
min-width: 200px;
text-align: center;
}
You can use this:
<a class="ui-button-icon-primary ui-icon ui-icon-circle-triangle-e" href="#" id="somar" style="float:right;">somar</a>
or
#somar {
margin-top:2px;
float:right;
}
but as long as you use px in your parameters, if the above ways does not help, you can set the distance form the left side like this:
#somar {
margin-top:2px;
left: 150px;
}
Just a slightly different approach - floating the three components left inside the div, then positioning the div - FIDDLE.
Did you want to do anything more with it?
CSS
#seletor {
width: 300px;
margin: 30px auto;
}
#subtrair, #mescorrente, #somar {
float: left;
vertical-align: top;
margin-left: 10px;
}
#subtrair, #somar {
margin-top:2px;
}
#mescorrente {
font-size: 20px;
text-transform: uppercase;
padding:0 6px; /* optional padding.. */
margin-bottom: 10px;
white-space: nowrap;
}
You have two options that I see here. Either you can create multiple div elements and display them inline, or you could use
<span>
element, as it is intended to display elements inline natively.
http://www.w3schools.com/tags/tag_span.asp
I would recommend using the span element, as I've had good success using this method, so long as you want them truly inline and not staggered/relatively aligned via script.

Position spans within a p tag so one part stays on the left, the other on the right

Here's what I've tried so far:
#billingsummary span.billingitem {
color: White;
text-align: left;
}
#billingsummary span.billingvalue {
text-align: right;
}
<p>
<span class="billingitem">#Model.ProductName</span>
<span class="billingvalue">$ <span id="billingproductcost">4.00</span></span>
</p>
So I'd like billingitem to be as far to the left as possible.
And I'd like billingvalue to be as far to the right as possible.
The outcome isn't what I want:
Use float:
#billingsummary span.billingitem {
color: white;
float: left;
}
#billingsummary span.billingvalue {
float: right;
}
#billingsummary p {
clear: both;
}
do float:right; and float:left; instead. The elements after that should include clear:both; if you want them to be below both of those items.
what text-align does is align text inside a block element to the side specified:
http://www.w3.org/TR/CSS2/text.html#alignment-prop
Span are inline elements, so text-align has no effect for them. You should float them:
#billingsummary span.billingitem {
color: white;
float: left;
}
#billingsummary span.billingvalue {
float: right;
}
Floating them you make them block elements and tell them to be in the extrem and out of the normal flow. If you have some problem with following elements you should clear: both them

Link with image on one line

Can someone help me to bring the arrows and the text on one line? (see image) The link tag should fill out the "th" (display:block).
HTML:
<th colspan="1" rowspan="1" class="ui-state-default">
example
<span class="ui-icon ui-icon-carat-2-n-s"></span>
</th>
CSS:
.ui-icon { width: 16px; height: 16px; background-image: url(../images/ui-icons_222222_256x240.png); }
.ui-icon-carat-2-n-s { background-position: -128px 0; }
table#example th a {
display:block;
}
table#example th span {
float: right;
}
Can I may be realize that with the z-index CSS-attribute or something like that?
Try adding float left to the anchor:
table#example th a {
float: left;
display:block;
}
Are you sure you want to be using tables for this? If you're using tables purely for layout; don't. There's a few ways to do this using css:
Method 1:
HTML
<a class="link" href="http://www.example.com">example</a>
<span class="arrows"></span>
CSS
.link, .arrows {
float: left;
}
.link {
margin: 0px 10px; /* Spacing either side of link */
}
Method 2
HTML
<a class="link" href="http://www.example.com">example</a>
<span class="arrows"></span>
CSS
.link {
display: inline;
margin: 0px 10px; /* Spacing either side of link */
}
Change the CSS so that the <a> and <span> both float left:
table#example th a {
float: left;
}
table#example th span {
float: left;
}
Example here.