I have the same issue.
.mainDiv {
border-spacing: 15px;
}
.formDiv {
width: 300px;
background-color: #F5F6CE;
padding: 10px;
margin-left: 20px;
display: table-cell;
vertical-align: top;
}
.resultDiv {
background-color: #F5F6CE;
padding: 20px;
box-shadow: 5px 5px 5px #888888;
margin-left: 20px;
display: table-cell;
width: 100%;
}
Now, I want to add <h1> to formDiv which results in:
I want the company registration to be aligned to top.
I found many threads giving answer:
vertical-align: top;
but it's not working for me. Please help.
HTML is:
<div class="mainDiv">
<div class="formDiv" align="center">
<h1 align="center">Company Registration</h1>
<form id="compReg" onsubmit="SaveData();return false;">
<Table align="center" cellspacing="5px">
<tr>
<td>
<Input id="txtEmail" type="email" class="text" placeholder="Contact Email" />
</td>
</tr>
<!-- other input types -->
<tr>
<td>
<Input type="submit" value="Submit" />
<Input type="reset"/>
</td>
</tr>
</table>
</form>
</div>
<div class="resultDiv" id="result">
<div align="right">
<input type="button" onclick="clearData()" value="Clear" />
<br>
<br>
</div>
<table class="dataTable" width="300">
<thead>
<th width="20px">Id</th>
<th width="250px">Email</th>
<!-- other headers -->
<th width="50px">Color</th>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
</div>
check JSFiddle I want the "problem" h1 to be aligned at top of left div.
h1 tag has default margin. Try to set it to 0px.
h1{
margin:0px;
}
Try resetting the default table padding and margin values
#yourtable {
margin: 0;
padding: 0;
}
As from my understanding if you are using table and trying to solve table cell spacing issue. try to make zero cell-spacing and cell-padding.
<table cellpadding="0" cellspacing="0">
CSS to H1 spacing
table h1{ margin:0; padding:0; }
JSFIDDLE DEMO
You mean this? Please post your HTML-Markup next time!
h1 { margin:0; background: blue; }
.formDiv {
width: 300px;
background-color: #F5F6CE;
margin-left: 20px;
padding: 0 10px 10px 10px;
display: table-cell;
}
<div class="wrapper">
<div class="formDiv">
<h1>Lorem</h1>
<p>ipsum dolor</p>
<input name="test" type="text">
</div>
</div>
Look at your fiddle: http://jsfiddle.net/xsmzLb3g/2/
You have to change the margin/padding of the h1 and div.
Related
I am new to CSS, and I am writting a web page with a form that has submit button, but I am not able to align well the submit button within the form
this is what I get with this: enter image description here
I don know how can I fix this, so any help is very appreciated.
h1 {
text-align: center;
color: blue;
}
body {
background-color: #1AD5EA;
text-align: center;
}
form {
display: inline-block;
text-align: center;
}
td {
/* text-align: center; */
font-weight: bold;
}
input[type=submit] {
padding: 5px 55px;
border: 5 none;
border-radius: 15px;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="estilo.css">
<title>Nuevo cliente</title>
</head>
<body>
<h1>Introduzca los datos del nuevo cliente</h1>
<br/>
<form action="procesar_form.php" method="post">
<table>
<tr>
<td>Nombre</td>
<td>
<input type="text" name="nombre">
</td>
</tr>
<tr>
<td>Dirección</td>
<td>
<input type="text" name="direccion">
</td>
</tr>
<tr>
<td>Tel</td>
<td>
<input type="text" name="tel">
</td>
</tr>
<tr>
<td>
<br>
<br>
<input align="center" type="submit" value="Enviar">
</td>
</tr>
</table>
</form>
</body>
</html>
If you want the button to be aligned to the right, you can set the parent td for the submit button to colspan="2" so that the cell will span both columns in your table, and assign text-align: right;
h1 {
text-align: center;
color: blue;
}
body {
background-color: #1AD5EA;
text-align: center;
}
form {
display: inline-block;
text-align: center;
}
td {
/* text-align: center; */
font-weight: bold;
}
input[type=submit] {
padding:5px 55px;
border:5 none;
border-radius: 15px;
text-align:center;
}
.submit {
text-align: right;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="estilo.css">
<title>Nuevo cliente</title>
</head>
<body>
<h1>Introduzca los datos del nuevo cliente</h1>
<br/>
<form action="procesar_form.php" method="post">
<table>
<tr>
<td>Nombre</td>
<td><input type="text" name="nombre"></td>
</tr>
<tr>
<td>Dirección</td>
<td><input type="text" name="direccion"></td>
</tr>
<tr>
<td>Tel</td>
<td><input type="text" name="tel"></td>
</tr>
<tr>
<td colspan="2" class="submit">
<input align="center" type="submit" value="Enviar">
</td>
</tr>
</table>
</form>
</body>
</html>
Since you are using a table to handle your formatting, I don't think what you're looking for needs to be a CSS answer.
In your case, if you are trying to align your button to be below the text input boxes, then you need to create a blank td in your last tr to fill the gap and align the next td that contains your button on the right.
<tr>
<td>
</td>
<td>
<br><br>
<input align="center" type="submit" value="Enviar">
</td>
</tr>
For a CSS-only solution, the easiest next step would be to remove all table references and rely on CSS for positioning of all elements.
Assuming that you want the button to go in the center:
You want to add colspan="2"
in the td which holds you submit button
Please try to avoid using table to position elements as that will never give you full control over your positioning and it is somewhat deprecated.
Try this.
CSS:
h1 {
text-align: center;
color: blue;
}
body {
background-color: #1AD5EA;
text-align: center;
width:100%;
}
form {
display: inline-block;
text-align: center;
}
td {
/* text-align: center; */
font-weight: bold;
}
input[type=submit] {
padding:5px 55px;
border:5 none;
border-radius: 15px;
margin:0 auto;
}
HTML;
<form action="procesar_form.php" method="post">
<table>
<tr>
<td>Nombre</td>
<td><input type="text" name="nombre"></td>
</tr>
<tr>
<td>Dirección</td>
<td><input type="text" name="direccion"></td>
</tr>
<tr>
<td>Tel</td>
<td><input type="text" name="tel"></td>
</tr>
<tr>
</table>
<div> <input type="submit" value="Enviar" ></div>
</form>
I want to create a border around my html component. HTML legend element can be used but i want to use it out of the form.
HTML Legend: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_fieldset
I tried but there is an issue title and border. Below is the jsfiddle for the same.
.temp {
border: 1px solid #999;
margin-top: 20px;
padding: 20px;
position: relative;
}
http://jsfiddle.net/alpeshprajapati/a6a93fg9/1/
How can i achieve output same as legend ? Thanks.
You are pretty much there. The last step to make your markup look like a legend would be to add a background-color to the span which matches the background-color of .temp and the element that contains it. This ensures that the border or .temp does not show behind the text (as background-color is transparent by default).
.temp > span {
background-color: white;
font-size: 21px;
left: 2%;
position: absolute;
top: -15px;
}
.temp {
border: 1px solid #999;
margin-top: 20px;
padding: 20px;
position: relative;
}
<div class="temp">
<span>Permissions</span>
<table class="table cs-table-no-bordered table-striped">
<thead>
<tr>
<th>Modules</th>
<th class="text-center">Edit</th>
<th class="text-center">Delete</th>
<th class="text-center">View</th>
<th class="text-center">All</th>
</tr>
</thead>
<tbody>
<tr>
<td>M1</td>
<td class="text-center">
<input type="checkbox" />
</td>
<td class="text-center">
<input type="checkbox" />
</td>
<td class="text-center">
<input type="checkbox" />
</td>
<td class="text-center">
<input type="checkbox" />
</td>
</tr>
</tbody>
</table>
</div>
I have this css caption effect:
.cell {
position: relative;
width: 180px;
height: 180px;
}
.caption {} .cell .caption {
opacity: 0;
text-decoration-color: gray;
text-align: center;
background: #eaeaea;
position: absolute;
font-weight: bold;
width: 180px;
height: 180px;
}
.cell:hover .caption {
box-shadow: 0 5px 2px #777;
cursor: pointer;
opacity: 0.7;
}
<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
<c:forEach var="product" items="${categoryProducts}" varStatus="iter">
<td>
<tbody>
<tr>
<td style="vertical-align: middle; width: 180px; text-align: center; height: 180px;" class="cell">
<a href="product?${product.id}">
<img class="img" alt="" src="${initParam.productImagePath}${product.name}.jpg" />
<div class="caption">
<br>view details</div>
</a>
<br>
</div>
</td>
<td style="vertical-align: middle; width: 140px; text-align: center;">${product.name}
<br>
</td>
<td style="vertical-align: middle; width: 125px; text-align: center;">$ ${product.price}
<br>
</td>
<td style="vertical-align: middle; width: 125px; text-align: center;">
<form action="addToWishlist" method="post">
<br>
<br>
<input name="productId" value="${product.id}" type="hidden">
<input class="submit" value="<fmt:message key='AddToWishlist'/>" type="submit">
</form>
<br>
</td>
<td style="vertical-align: middle; width: 123px; text-align: center;">
<form action="addToCart" method="post">
<br>
<br>
<input name="productId" value="${product.id}" type="hidden">
<input class="submit" value="<fmt:message key='AddToCart'/>" type="submit">
</form>
<br>
</td>
</tr>
</tbody>
</c:forEach>
</table>
The code in itself works perfectly fine. The caption shows as expected. The only thing tho, when there's an image inside of the cell, there is a display problem when mouse hover the image as shown from my local browser run from the IDE:
The caption overlays the next cell... What could cause this? I tried to play around with the .img and the .caption but cannot seem to find a solution...
Here the full image overlay caption effect i'm trying to accomplish:
http://www.corelangs.com/css/box/caption.html
So the problem in your screenshot is the caption of the bottom image overlaying on top of the first image? Not sure I understand this correctly, but if so there are three simple solutions I can think about:
Increase the margin between your images / rows
On :hover, increase margin, although that could be poor UX
Increase opacity from 0.7 to 1 so it overlays, but you cannot see the first cell through it
I'm trying to get a table to be 100% width of a div...
But when I use width=100% it expands outside of the borders... When using on different devices...
So I'd just like this table, across full width - and the N/A button right aligned...
Seems it is always extending past borders on different devices...
<div class=flist>
<table cellpadding=2 border=1>
<tr>
<td valign=middle>
<img src="images/plus.png" height=14 width=14 border=0 align=middle> <b>General Stuff</b>
</td>
<td align=right>
<input type="button" name="CheckAll" value="All N/A" class=verd8></td>
<td> </td>
</tr>
</table>
</div>
Take this example :
<html>
<body>
<head>
<style>
.flist{
border:1px solid red;
padding:5px;
width:500px;
}
table{
width:100%;
border:1px solid;
}
</style>
</head>
<div class="flist">
<table cellpadding="2" border="1">
<tr>
<td valign=middle>
<b>General Stuff</b>
</td>
<td align=right>
<input type="button" name="CheckAll" value="All N/A" class=verd8></td>
<td> </td>
</tr>
</table>
</div>
</body>
</html>
Just an inline css example, but it works if you change .flist width the table width changes, note the red color of the .flist versus black of table.
div.flist{width:500px;}
div.flist table{width:100%;}
This should work in most cases.
if you need mobile, use media queries instead.
Adding 1% each side is = 20px so just minus that from the table width. 1% = 10px;
*{
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
table{
width: 100%;
border-spacing: 0;
border-collapse: collapse;
empty-cells:show;
}
table.bordered{
border-collapse:separate;
border:1px solid #ccc;
border-radius:4px;
}
th,td{
vertical-align:top;
padding:0.5em;
}
tr:nth-child(2n){
background-color:#f5f5f5;
}
-
<table class="bordered">
<tbody></tbody>
</table>
Just write table tag like this
<table width=100%></table>
This might have worked
Added this also into table
style="table-layout:fixed"
.flist {
font-family: Verdana; font-size: 13pt; font-weight: bold;
overflow: hidden;
position: relative;
background-color: #e9e9e9;
padding: 5px;
margin-top: 5px;
margin-left: 1%;
margin-right: 1%;
border: 1px solid #000;
}
.flist > table
{
width: 100%;
}
<div class=flist>
<table cellpadding=2 border=0 style="table-layout:fixed">
<tr>
<td valign=middle>
<b>General</b>
</td>
<td align=right>input type="button" name="CheckAll" value="All N/A" class=verd8></td>
</tr>
</table>
</div>
I want to make first input have the width 100% and second + image = 100% so that second input get the rest of the space (100%-img size) on the same line. Is it possible to do using CSS?
<html><head><title>width test</title>
<style type="text/css">
.t {
width: 100%;
table-layout:fixed;
}
.caption {
text-align: left;
width: 35%;
}
.data {
text-align: left;
width: 65%;
}
.edt {
width: 100%;
}
</style>
</head>
<body>
<table class="t">
<tr>
<td class="caption">Caption:</td>
<td class="data"><input type="text" class="edt" /></td>
</tr>
<tr>
<td class="caption">Caption:</td>
<td class="data">
<input type="text" class="edt" /><img width="22px" src="cal.png" />
</td>
</tr>
</table>
</body>
</html>
Yes, this can be done with CSS. The trick is to use display: table and display: table-cell, where where width: 100% means "the rest of the available space".
Here is an example (with wrapper divs around .edt and the image link for better result): http://jsfiddle.net/zgw8q7vj/
The important CSS parts are these:
/*Use "table" layout in the 'data' cells,
and give them all the available width (after the captions)*/
.data {
display: table;
width: 100%;
}
/*Then give the textbox all the available remaining width...*/
.edt-wrapper {
display: table-cell;
width: 100%;
}
/*...after the image has claimed the space it needs*/
.img-wrapper {
display: table-cell;
}
If you don't want the caption column to take more space than it needs, you can even remove table-layout:fixed; and width: 35%; from .t and .caption
untested.
you didn't mention colspans can't be used, so this solution uses it.
<table class="t">
<tr>
<td class="caption">Caption:</td>
<td class="data"><input type="text" class="edt" /></td>
</tr>
<tr>
<td class="caption">Caption:</td>
<td colspan="3"><input type="text" class="edt" /></td>
<td class="data"><img width="22px" src="cal.png" />
</td>
</tr>
</table>
I have found that I can do it with tables. The question still remain, is it possible to do with div/css?
<html><head><title>width test</title>
<style type="text/css">
.t {
width: 100%;
table-layout:fixed;
}
.caption {
text-align: left;
width: 35%;
}
.data {
text-align: left;
width: 65%;
}
.edt {
width: 100%;
}
.joiningtable
{
border-spacing:0px;
border-collapse:collapse;
width:100%;
margin:0px;
border:0px;
padding:0px;
}
.joiningrest
{
width:100%;
margin:0px;
border:0px;
padding:0px;
}
.joiningfixed
{
margin:0px;
border:0px;
padding:0px;
}
</style>
</head>
<body>
<table class="t">
<tr>
<td class="caption">Caption:</td>
<td class="data"><input type="text" class="edt" /></td>
</tr>
<tr>
<td class="caption">Caption:</td>
<td class="data">
<table class="joiningtable">
<tr><td class="joiningrest"><input type="text" class="edt" /></td><td class="joiningfixed"><img src="cal.png" /></td><tr>
<table>
</td>
</tr>
</table>
</body>
</html>
If you're still interested, it is possible but you need to use a little magic..
With absolute positioning, you can stretch those entry fields as wide as you like, or rather, you make them stretch to 100% and put them inside spans that stretch as wide as you like because input fields are stubborn things and won't behave otherwise.
<html>
<body>
<div style="background-color:#DDDDFF; position:absolute; left:10px; top:10px; right:10px; height:80px;">
<span style="position:absolute; left:10px; top:10px;">Caption</span>
<span style="position:absolute; left:10px; top:40px;">Caption</span>
<span style="position:absolute; left:70px; top:10px; right:10px;">
<input type="text" style="width:100%" />
</span>
<span style="position:absolute; left:70px; top:40px; right:40px;">
<input type="text" style="width:100%" />
</span>
<img style="width:22px; position:absolute; top:40px; right:10px;" src="cal.png" />
</div>
<div>
</div>
</body>
</html>
P.S. I've left the style definitions on the entities for simplicity. In a real-world case, I'd move them to a .css file of course.