2 label inside td alignment - html

Am having 2 label inside a td and am trying to make the alignment work
Is it possible ?
Here is Fiddle for the same explaining issue and how i need.
jsFiddle
<tr>
<td><label >Some Label Test:</label><label>Some Label Test:</label></td>
<td>
<label >Some Label Test:</label>
<label >here is the long test which exceeds the width and comes to second line but i want it like it should start below after test: instaead from some</label></td>
</tr>
Am looking for second label inside if the length is long it is coming to next line and starts from where the second label has started.

Here is a simple div usage of how to get what you want. http://jsfiddle.net/KHAJz/3/
HTML
<div class="container">
<div class="first">Some Label Test:</div>
<div class="first">Some Label Test:</div>
<div class="first">Some Label Test:</div>
<div class="text">here is the long test which exceeds the width and comes to second line but i want it like it should start below after test: instead </div>
</div>
CSS
.container{
width:700px;
height:60px;
display:inline-block;
}
.first{
width:60px;
height:60px;
display:inline-block;
float:left;
}
.text{
width:300px;
display:inline-block;
float:left;
}
What you do is make a container that holds everything together so that the tables or divs don't go everywhere.

If you don't want (or cant) change your DOM,
just add this to your CSS
label
{
display: inline-block;
height: 100%;
}
See this Working Fiddle
But if you can change your DOM, I'd recommend you to leave the Table layout and reconstruct your layout with divs. -like in Keith's answer.

Related

two divs on the same line within a parent on the same line

So, I did a search and it seems that every single person who's asked this exact same question has actually had success with an answer given by someone - I tried multiple different methods and honestly, I'm about to have a meltdown.
I've tried floating left, floating right, inline-block, etc, and none of it has seemed to work. I am at a loss as to what I'm doing wrong, but it's driving me nuts.
Here's the HTML I'm trying to get on the same line:
<div class="search-and-staff-app-button">
<div class="search-position">
<form method="get" id="sb_searchform" action="<?php bloginfo('home'); ?>/">
<div class='search-box'>
<input name="s" id="s" class='search-input' placeholder='Search' type='text' />
<img onclick="document.getElementById('sb_searchform').submit();" class='search-img' src='<?php bloginfo('template_url'); ?>/img/search.png'>
</div>
</form>
</div>
<div id="staffAppButtonPlaceholder" class="staff-app-position"></div>
</div>
and the CSS:
.search-and-staff-app-button {
width:360px;
margin:0px;
float:right;
display: inline-block;
}
.search-position {
float:left;
}
.staff-app-position {
float:left;
}
What am I doing wrong? I've tried Getting 2 divs on the same line and this doesn't work either.
Any help would be super appreciated!
-Stu
To place the search-position and staffAppButtonPlaceholder divs on the same line, first float the search-position div:
.search-position {
float: left;
}
Then add some content to the placeholder:
<div id="staffAppButtonPlaceholder" class="staff-app-position">Content</div>
Finally, increase the width of the containing div to allow the elements to fit side-by-side:
.search-and-staff-app-button {
width:760px;
Both divs will now be aligned horizontally.
http://jsfiddle.net/jzefu2j9/1/
Here is a little example, maybe it will help you. I used flexbox, which in my opinion is a great solution for aligning.
.search-and-staff-app-button{
display: flex;
background:red;
align-items:center;
}
.search-and-staff-app-button > div{
box-sizing:border-box;
display:block;
flex:1 50%;
align-self:center;
padding:1em;
}
http://jsfiddle.net/pulamc/u9nLwacs/
add style="position:relative" to your outer div. Then make the inner div's style="position:absolute;left:0". You will have to manually set the left value for each of the divs. The downside is that you will have to know the width of the other divs on the same line.

HTML/CSS <div> background

How do you set a background on a div? I have a block looking like this:`
<div class="span4">
<font color="000000">
<h4 class="text-center">This is the title</h4>
<p>This is my text</p>
<a href="#" class="btn btn-success">
<i class="icon-star icon-white"></i> This is my button</a>
</font>
</div>
I want to make this whole block have a background image, but when I try (I've tried 6 different methods already), It either doesn't work at all, doesn't fill the whole box, or fills the whole page.
After using JoshC's CSS related answer, I got this problem. In the image you can see my background, but it doesn't stretch across the whole area I want it to. The side bar, as far across as the left edge of the blue highlight on "Home", is meant to be a different image, (not set up yet) and the rest would be the displayed image.
This is the image
Another thing I'd like is a background applied to multiple divs, but not all, however that's optional...
Any help is much appreciated.
Apply a background-image like this:
.span4 {
background-image: url(http://example.com/image.png);
}
jsFiddle demo
or.. style within the HTML like this:
<div class="span4" style="background-image: url(http://example.com/image.png);"></div>
jsFiddle demo
You obviously have to change the URL to an image that exists.
See the specs on the background property here: https://developer.mozilla.org/en-US/docs/Web/CSS/background-image
.span4
{
background-image:url('your image path');/* by this image set*/
background-color:#cccccc;/* and can use color*/
}
You can give somethinglike this: <div class="span4" style="background:url(../Pictures/website.png) no-repeat fixed;">
We are going to warp your head for a second. Divs are like boxes that exist with no border, no per-defined styles other than 100% width.
You are combining table-line HTML3 standard structure to the nature of a HTML5 div. In the newest code does not contain such attributes like table cells did in the past.
We would accomplish this today through CSS bound to ID's or classes to call those elements that exist within the DOM.
css
<style type="text/css">
.span4{ background-image:url('images/myimage.jpg');
background-repeat:no-repeat;
width:100px; height:100px; }
.span h4{ color:#000; text-align:center; }
.span4 p{ font-weight:bold; /*or whatever*/}
.span4 a{ font-style:italic; color:#0f0; }
.span4 a:hover{}
.span4 a:active{}
.span4 a:visited{}
.span4 a.btn{ color:blue; }
.span4 a.btn-success{ color:green; }
.span4 a.btn.btn-success
.icon-star:before{ content: '* '; }
.icon-white:before{ color:#fff; }
</style>
html
<div class="span4">
<h4>This is the title</h4>
<p>This is my text</p>
This is my button
</div>`

How to style divs like a table (example as attached per SharePoint)?

How can I style a group of related divs to look like a table per the attached image? Thx!
<div class="collection"
<div class="group">
<div class="label">Label1</div>
<div class="value">Value1</div>
</div>
... repeats n times
</div>
Disclaimer: This particular html output is auto-generated and I don't have control over what is generated. I just have divs to work with and I want to style accordingly.
Sorry guys, but, what the float?
while you all tried to proscribe what you think the OP needs, the answer to the question actually is
.collection {display:table}
.group {display:table-row}
.label, .value {display:table-cell}
I believe
.label {
width: 200px;
float: left;
}
(apart from the other styling) will do the thing for you.
html
<div class="collection">
<div>
<div class="label">Label1</div>
<div class="value">Value1</div>
</div>
<div>
<div class="label">Label1</div>
<div class="value">Value1</div>
</div>
</div>
css
.label { float:left; width:200px; border-top:1px solid #ccc; }
.value { margin-left:200px; background:#fffced; border-top:1px solid #ccc; }
Code: http://jsfiddle.net/wWGG8/1/
I would just use a table. You can read about tables in HTML here The <tr> tag defines a table row. The <td> tag defines the table data. Each <td> tag is a new column.
<table>
<tr><td>This is the table data</td><td>This is more table data in the same row</td></tr>
<tr><td>Here is another row</td><td>This is more table data in the second row</td></tr>
</table>
True, you can just use a table. That would be semantically convenient.
Nonetheless, you can stick to your current HTML structure.
Just assign the divs with classes of label and value with a width and then float them to the left.
You might also need to specify a height for the div with class group.

CSS div alignment

I'm having problem in alignment of a div. Please see following html. I have basically a form fiend with label and input field, and a <p> on the right of the input field. For some of the fields, the <p> element has small text, which fits on same line. But for some fields, it has more text which goes to 2 or 3 lines.
How can I set the CSS of the <p> element that if its only one one line, then it should be displayed in the middle the input field, but if the text is over one line then it just goes up.
Hope my question is clear. Thanks for any help.
HTML:
<div class="container">
<label>Label</label><input class="input" />
<p>Lorem ipsum dolor. </p>
</div>
CSS:
.container{
border:1px solid black;
padding:20px;
float:left;
}
label{
line-height:2.5;
float:left;
border:1px solid green;
width:60px;
margin-right:10px;
}
input{
border:1px solid green;
height:34px;
padding:4px 6px;
width:200px;
float:left;
margin-right:10px;
}
p{
border:1px solid red;
float:left;
width:150px;
line-height:15px;
}
jsFiddle:
http://jsfiddle.net/JFjx4/
Please, explain what you mean "it should be displayed in the middle the input field"? May be what you need is jsfiddle. I replaced 'float: left' in 'LABEL INPUT P' with 'display: inline-block' and added 'vertical-align: middle' in 'P'.
#Grigor: "text-wrap" is css3 feature. It can be inappropriate for #Roman.
set a fixed width and put text-wrap: normal;
You could have a table for your form with 3 columns. The last one (with your p) you could style with vertical-align:middle in your css
Edit your jsfiddle html to this:
<div class="container">
<table>
<tr>
<td><label>Label</label></td>
<td><input class="input" /></td>
<td style="vertical-align:center"><p>Lorem ipsum asdf asd </p></td>
</tr>
</table>
</div>
I'm not one for recommending plugins because it generally doesn't help you learn... but in this case since you want different placements depending on length, AND because it sounds like you're using that for form validation... I'd recommend using the tipsy tooltip for this. its a pretty straightforward way to add messaging that also can move around your input element depending on your needs.
http://onehackoranother.com/projects/jquery/tipsy/

How to keep the text vertically aligned in any condition?

For example in the below image I want keep the text always vertically aligned in all condition. even if text is in one, two or three lines.
means the text should be vertically centered always. I don't want to add extra span
<div>
<img src=abc.jpg"> Hello Stackoverflow. Thank you for help me
</div>
I want to achieve with this html.
Edit
And I don't want to give fix width and height to any element
Chris Coyier wrote an excellent tutorial on just this: http://css-tricks.com/vertically-center-multi-lined-text/
I've used it myself, and it works perfectly.
try with
HTML
<div>
<img src="" height="155px" width="155px" style="float:left">
<div class="imageText">Hiiii <br/> how r u? <br/> use multiple lines</div>
</div>
CSS
.imageText {
display: table-cell; // this says treat this element like a table cell
vertical-align:middle;
border:1px solid red;
height:150px;
width:150px;
text-align:left;
}
DEMO
Note: width and height matters
I really like the method described # http://reisio.com/examples/vertcenter/