How can I create this simple form example in HTML? - html

I'm a developer with limited HTML/CSS design experience. I have been stuck trying to create this simple form for over an hour so I'm giving up and asking for help.
I tried doing something like this:
<ul>
<li><label>Name:</label><span class="line">&nbsp</span></li>
...
</ul>
li label {
display: inline-block;
}
li span {
display: inline-block;
width: 100%;
border-bottom: 1px solid #000;
}
I have no idea how I can express that I want the span to take up 100% of the width between the label and the containing div.
I would like the rendered HTML to look exactly like my example image. That is, the entire list item should not be underlined, only the space where the customer is to fill in the information.
Please let me know how I can achieve this. Thank you!!!

Here's a simple example of what you want to do. Basically, you give the li a bottom border, and overlap it with the label's border to cover up the black line.
li
{
border-bottom: 1px solid black;
width: 250px;
}
label
{
border-bottom: 2px solid white;
padding-right: 5px;
}
I'm not sure how cross browser the above solution is, so you might want to use a few extra directives, just in case (untested):
li
{
border-bottom: 1px solid black;
width: 250px;
}
label
{
background: white;
position: relative;
border-bottom: 2px solid white;
padding-right: 5px;
}
Cross browser solution (as far as I can tell):
Thanks to #Joseph, there's this solution to a thin line being displayed under the label.

OK I really hate answering my own question but this seems like the least-hackish way of achieving this result. I'll let the votes decide. Thanks again for all the help. I can't believe how long it took me to figure this out!
Solution using display:table-cell
li label {
display: table-cell;
}
li span {
display: table-cell;
width: 100%;
border-bottom: 1px solid #000;
}
<ul>
<li><label>Name:</label><span></span></li>
<li><label>Address:</label><span></span></li>
<li><label>City:</label><span></span></li>
<li><label>State:</label><span></span></li>
<li><label>Zip:</label><span></span></li>
</ul>

EDIT
meh... I like my adaptation of JamWaffles' answer better (comments). He should get the credit. :P
Demo
Here's a very hackish way of doing it :P
HTML
<ul>
<li><label>Name:</label></li>
<li><label>Address:</label></li>
<li><label>City:</label></li>
<li><label>State:</label></li>
<li><label>Zip:</label></li>
</ul>
CSS
li label {
margin-bottom:-1px;
display: inline-block;
border-bottom: 1px solid #fff;
padding-right:10px;
}
li {
width: 100%;
border-bottom: 1px solid #000;
}

add a class to the span that you want to have a border-bottom
example
li span.underline {
display: inline-block;
width: 100%;
border-bottom: 1px solid #000;
}

Interesting concept. I'd tackle it something like this:
<style type="text/css">
input.line {
border: 0;
border-bottom: 1px solid #000;
}
</style>
<ul><li><label for="name">Name: </label><input class="line" name="name" /></li><br />
<li><label for="address">Address: </label><input class="line" name="address" /></li><br />
<li><label for="city">City: </label><input class="line" name="city" /></li><br />
<li><label for="state">State: </label><input class="line" name="state" /></li><br />
<li><label for="zip">ZIP: </label><input class="line" name="zip" /></li></ul><br />
Edit This is code for a functional form that you can TYPE things into, I didn't realize you just wanted the underline. Either way, this solution should work for both.

Here's a solution:
html:
<ul>
<li><span class="label">Name:</span><span class="line name"></span></li>
<li><span class="label">Address:</span><span class="line address"></span></li>
<li><span class="label">City:</span><span class="line city"></span></li>
<li><span class="label">State:</span><span class="line state"></span></li>
<li><span class="label">Zip:</span><span class="line zip"></span></li>
</ul>
css:
ul {width: 300px;}
.line {
float: left;
display: inline-block;
border-bottom: 2px solid black;
margin-left: 5px;
width: 100%;
margin-top: -5px;
}
.label {
display: inline-block;
background-color: white;
margin-top: 10px;
padding-right: 5px;
}
li span {font-family: sans-serif;}
li {line-height: 1.3em;}

For future reference, this is another way to do it: http://jsfiddle.net/thirtydot/7SFDV/.
The only real difference this has (over your answer) is that it will work in IE7, which is probably not relevant to you. I have no idea if it will work with your "proprietary HTML > PDF renderer".
li {
overflow: hidden;
margin: 8px 0
}
li label {
float: left;
margin-right: 3px
}
li span {
display: block;
overflow: hidden;
border-bottom: 2px solid #000;
line-height: 1.1
}

Related

apply the :focus on child element when parent selected css3

I have a label and drop down list behind it
it goes something like this :
<div class="=row dropdown" id="conTypeSelect" >
<label id="connectTypeLabel" class="label">Connector Type</label>
<select id="connecType" name="connecType" class="dropdownList" >
<option>type1</option>
<option>type2</option>
</select>
</div>
I want it so when clicking on the element to make the label change color to blue.
I know how to do it through a script by trigger off event on select and add css to the label to set it blue.
However I am wondering if there is a way to do it simply through css. Using script seem to make my code alot more messy for things like this.
So I thought of adding css to the parent and make it
.dropdown:focus {
color: #1A98C6;
}
.label:focus {
color: #1A98C6;
}
.dropdownList:focus {
border-bottom: solid 1px #1A98C6;
border-right: solid 1px #1A98C6;
outline: none;
}
however applying this to parent div doesn't seem to apply to child.
is there a way to make it so when I focus the parent the child would get focused too with css?
I have attempted to use this as the css but it doesn't seem to work:
.dropdown:focus .label {
color: #1A98C6;
}
.dropdown:focus .dropdownList {
border-bottom: solid 1px #1A98C6;
border-right: solid 1px #1A98C6;
outline: none;
}
You can achieve this by a + selector and putting the label after the select, so that you can do something like
.dropdown select:focus + label to select the label after the focused select box.
And use float:left on the label and a bit of right margin to pull the lable to the left of the select box.
.dropdown>select+label {
float: left;
margin-right: 10px;
}
.dropdown>select:focus+label {
color: #1A98C6;
float: left;
margin-right: 10px;
}
.dropdown>select:focus {
border-bottom: solid 1px #1A98C6;
border-right: solid 1px #1A98C6;
outline: none;
background: blue;
color: white;
}
<div class="=row dropdown" id="conTypeSelect">
<select id="connecType" name="connecType" class="dropdownList">
<option>type1</option>
<option>type2</option>
</select>
<label id="connectTypeLabel" class="label">Connector Type</label>
</div>
NOTE: I just added a background and color on select too just to show it effects the select too when focused.
This is the only way I can think of using CSS only to trigger by clicking the <input type="checkbox">.
body {
font-family: Arial;
font-size: 13px;
}
input[type=checkbox]{
display: none;
}
ul{
display: none;
border: 1px solid #ccc;
border-radius: 3px;
padding: 0;
width: 100px;
}
ul li {
border-bottom: 1px solid #eee;
cursor: pointer;
line-height: 30px;
list-style: none;
text-align: center;
}
ul li:hover {
background-color: #333;
color: #fff;
}
input[type=checkbox]:checked ~ ul {
display: block
}
<div class="dropdown" id="conTypeSelect">
<input type="checkbox" id="checkbox_toggle">
<label for="checkbox_toggle">Click to choose Connector Type</label>
<ul>
<li>type1</li>
<li>type2</li>
</ul>
</div>

Move border-bottom further away from text

I'm trying to move the border-bottom down so more of my active-link can be seen.
.navigation a.active-link {
background-border: #red;
border-style: solid;
border-bottom: solid white;
color: black;
padding:10px;
}
#navigation {
border-bottom: 1px solid currentColor;
text-decoration: none;
word-wrap: break-word;
padding-top: 10px;
margin-bottom: 15px;
overflow: hidden !important;
white-space: no-wrap;
text-overflow: clip;
height: 26px;
}
The problem is when I try and increase the padding-bottom it stacks my text and I'm trying to avoid that.
https://jsfiddle.net/akn5r7y5/2/
You can add the padding-bottom you need and set the anchor line-height accordingly so they don't stack
#navigation a {
line-height:26px;
}
#navigation {
padding-bottom:26px;
}
https://jsfiddle.net/akn5r7y5/3/
Adding padding-bottom to your navigation should fix your problem.
Read more about box model (paddings, margins etc.) here - https://css-tricks.com/box-sizing/
Remove your padding-top, and use line-height, must be equal to the height of the content, so it will be centered:
Your #navigation must look like this then:
#navigation {
border-bottom: 1px solid currentColor;
text-decoration: none;
word-wrap: break-word;
margin-bottom: 15px;
overflow: hidden !important;
white-space: no-wrap;
text-overflow: clip;
height: 26px;
line-height: 26px;
}
I think you're making this way harder than you need. Try to prevent using a fixed height. Also use a display: inline-block; on the anchor. This way it has a height you can actually work with. Example:
#navigation {
border-bottom: 1px solid currentColor;
}
.navigation a {
color: black;
padding: 10px;
display: inline-block;
text-decoration: none;
}
.navigation a.active-link {
background: red;
border: 1px solid black;
border-bottom: none;
}
<div class="navigation" id="navigation">
Show all
<a href="#" >title</a>
<a href="#" >title1</a>
<a href="#" >title2</a>
<a href="#" >title3</a>
<a href="#" >title4</a>
</div>
here is some clue for you.
ok forget what i just said about hr tags.
i just got what is your question, so you wanted to create a navigation with a border bottom, and a full border if you are in that page.. i suggest you to using ul li tags. its a bit comfotable, and dont use too many link if you dont have any responsive yet.
because, the whitegaps u think it's a easy task but it actually a big trouble in here. this <a></a> link should not seperated and you should type the code like this ridiculously like this
<a>link</a><a>link</a>
which mean, you should type it without a gaps in it, if only you put it in li tags, it would be easier to read like this
<li><a>link</a></li><li>
<a>link</a></li><li>
etc
so you only thinking about border inside of a, dont over think about a border in navigation div.
this is the code, have a look
.navigation a.active-link {
border: solid 1px black;
color: black;
padding:10px;
}
.navigation a{
padding:10px;
border-bottom: 1px solid black;
}
#navigation {
text-decoration: none;
padding-top: 10px;
padding-bottom:10px
}
hr{
border:solid black 1px;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-12 col-lg-10 col-lg-offset-1">
<div class="navigation" id="navigation">
Show all<a href="#" >title</a><a href="#" >title1</a><a href="#" >title2</a><a href="#" >title3</a><a href="#" >title4</a><a href="#" >title5</a>
</div>
</div>

Created color boxes for a legend in HTML and CSS, but can't get two color boxes on the same line

I'm currently in the process of creating a legend for a table that has highlighted rows, but I can't seem to get two color boxes on the same li.
<ul>
<li>
<div class="input-color">
<input type="text" value="Blue/White - Alternating Rows" readonly="true" style="border:0;width:200px"/>
<div class="color-box" style="background-color: #6DC2FF;"></div>
<div class="color-box" style="background-color: white;"></div>
</div>
</li>
</ul>
With the following CSS...
ul {
list-style: none;
margin: 0;
padding: 0;
}
.input-color {
position: relative;
}
.input-color input {
padding-left: 20px;
margin-bottom: 10px;
}
.input-color .color-box {
width: 10px;
height: 10px;
display: inline-block;
background-color: #ccc;
position: absolute;
left: 5px;
top: 5px;
border: 1px solid #000;
}
Any ideas? Assuming I know how to use JSFiddle, here it is:
https://jsfiddle.net/1ywpxxks/1/
You can use CSS float: left; to prevent div from breaking lines. You can also set disply: inline-block;.

Make border-bottom closer to the text

Fiddle
Try
I have applied line-height, display properties. But none of these works fine with double lined text.
.container span {
width:80px;
border-bottom: 1px solid #aaa;
text-decoration: underline;
}
.container {
width: 20%;
display: inline-block;
}
<div class="container">
<span>My Cash & Discounts</span>
(0)
</div>
I have found this.
But it's not working fine.
Ques:
Please take a look at my fiddle. How to make border-bottom to match with text-underline? How to remove the gap between that two lines?
You could insert another container:
<div class="container">
<span><span class="inner">My Cash & Discounts</span></span>
(0)
</div>
And assign a negative value for margin-bottom:
.container span
{
border-bottom: 1px solid #aaa;
text-decoration: underline;
display:inline-block;
}
.container span.inner {
border:none;
display:block;
margin-bottom:-3px;
}
.container
{
width: 20%;
display: inline-block;
}

Make the drop-down menu's width dynamic

My website uses a drop-down menu for the things you can do on the page.
HTML:
<table class="navbar">
<td class="menuNormal geometry" width="135px" onmouseover="menu('exp',this);" onmouseout="menu('col',this);">
<p class="tdesc">
<span lang="hu">Geometria</span>
<span lang="en">Geometry</span>
</p>
<div class="menuNormal dropdown" width="inherit">
<table class="menu" width="inherit">
<tr><td class="menuNormal">
<a href="javascript:geodesc('squa')" class="menuitem">
<span lang="hu">Négyzet</span>
<span lang="en">Square</span>
</a>
</td></tr>
...
</table>
</div>
</td>
</table>
CSS:
table {
padding:0;
margin:0;
}
table.navbar {
background-color: ButtonFace;
font: menu;
}
p.tdesc {
margin: 0;
padding: 0 3px 0 3px;
text-align:center;
font: menu;
}
table.menu{
font-size: 8pt;
margin: 0px;
padding: 0px;
}
td.menuNormal{
padding: 0px;
color: ButtonText;
vertical-align: top;
}
td.menuHover{
padding: 0px;
color: HighlightText;
vertical-align: top;
background-color: Highlight;
}
div.menuNormal{
display: none;
position: static;
}
div.menuHover{
border: 1.5px solid ButtonShadow;
background-color: Menu;
display: inline;
position: absolute;
}
a.menuitem:link{
text-decoration: none;
color: ButtonText;
padding: 2.5px;
border-bottom: 1px solid GrayText;
display: block;
}
a.menuitem:hover{
text-decoration: none;
color: HighlightText;
padding: 2.5px;
background-color: Highlight;
border-bottom: 1px solid GrayText;
display: block;
}
.hover {
border:3px ridge #8CA3FF;
background-color: #C9D4FF;
font-style:normal;
}
Currently, this solution is not the perfect one, since the menu's width is fixed, and when I tried to make it look like a bit more drop-down-ish, it extended the width of the top label when showing the actual options.
I need a method that I could use to make the options appear like an actual drop-down would, and make the label width fit the text that it contains.
If this is something new you are putting together and you have complete control over it and the goal is to make a nice website (not about showing an understanding of CSS) and you have no limitations such as not using an existing library, then I would suggest trying out Twitter Bootstrap and using a fluid container and navigation as a base and then add your own CSS on top for specific design changes if required.