So I know this can be achieved using Flexbox, but especially when working with very lightweight eCommerce sites where Bootstrap isn't loaded (like Shopify themes), sometimes we just want to stick with pure CSS for simplicity.
How do I achieve the same effect as this using CSS?
<center>
<table>
<tr>
<td>
<div>
<img ... />
<br />
<label ... />
</div>
</td>
<td>
<div>
<img ... />
<br />
<label ... />
</div>
</td>
</tr>
</table>
</center>
(Crude example, but hopefully it gets the point across.)
You need to set margin's for the div to auto. This will centre the div in the parent container.
div {
margin: 0 auto;
width: 100px;
}
Related
On the left, I have buttons and the rest of the screen is a table, and I need a vertical line to act as a separator between the two but without any use of CSS/styles/classes.
Here is the base code:
<section align="left">
<div id="buttons">
<button type="button">Fire</button>
<br>
<button type="button">Water</button>
</div>
</section>
<!-- NEED A VERTICAL LINE HERE -->
<section align="center">
<table id="pokemons">
<tr>
<td>
<h5>Charizard</h5>
</td>
<td>
<h5>Blastoise</h5>
</td>
</tr>
<br>
<tr>
<td>
<h5>Pikachu</h5>
</td>
<td>
<h5>Squirttle</h5>
</td>
</tr>
</table>
</section>
I currently have this (for some reason in online editors the table isn't aligned to the middle, but on my local code it's fine):
I need this:
If you want to avoid using CSS, then your page will look atrocious.
There is not really a way to do that. I would make an <hr> tag and use transform: rotate(90); in your CSS.
I'm sorry but you will have to use CSS. No way around it, unless you use CSS or JavaScript.
I've found multiple post for aligning text next to an image, it works but at the same time it doesn't work. When gmail renders the html code, it renders it perfectly. When outlook renders the html code, the vertical alignment is off.
May I get some suggestions of how to get text and images to vertically align in a row in both gmail and outlook.
<td>
<div>
<img src="..." style="height:24px; width:33px; vertical-align:middle;" />
<span>Test</span>
</div>
<div>
<img src="..." style="height:24px; width:33px; vertical-align:middle;" />
<span>Test</span>
</div>
</td>
Email client compatibility is like cross-browser compatibility on a steroid induced rampage. I would suggest going old school with a TABLE to achieve the effect you want. Dated HTML practices tend to fare well in email clients.
<table>
<tbody>
<tr>
<td>
<img src="http://via.placeholder.com/150" />
</td>
<td>Hello world!</td>
</tr>
</tbody>
</table>
I'm working on a CSS/HTML project and I have a problem with the borders of the text fields. In the browser, the borders are shorter than the text fields.
I tried changing the size of the border to fit the text field and it worked but I tried opening the browser (IE) on a bigger screen and I faced the same problem again.
Here is my code:
<tr>
<td>First Name</td>
<td>
<div style="border:4px #26a570 solid;
background-color:white;
width:37.5%;
height:15%">
<input type="text" name="txtFirst" id="txtFirst" />
</div>
</td>
</tr>
I want the border to scale to the size of the text box in all the browser and screens.
First like #Nimsrules mentioned put your border around the input.
Second use a viewport. this will make it scaleable. Your viewport has to be in the head. And instead of using % you can use vw for the width en vh for the height.
Example
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<tr>
<td>First Name
</td>
<td>
<div >
<input type="text" name="txtFirst" id="txtFirst" style="border:4px #26a570
solid;background-color:white; width:37.5vw; height:15vh"/>
</div>
</td>
</tr>
Fiddle
Here you can read more about viewports.
Also I wouldn't recommend inline css. It is better to use a css file. Read this for more information why it is not recommended.
You need to set the style on the input element,
It does not work because you had width:37.5%;set to the parent also.
<table>
<tr>
<td>First Name
</td>
<td>
<div>
<input style="width: 200px; border:4px #26a570
solid;background-color:white; height:15%" type="text" name="txtFirst" id="txtFirst" />
</div>
</td>
</tr>
</table>
You can set border to the input field and check it on IE.
If it does not work then try to break out the border CSS you have applied, as
border-color: grey;
and
border-style:solid;
instead of single tagging, you can try this.
Hope it works!
Hi Firstly it is bad to write inline styles because editing can be a pain. You should set a class and write the styles in your CSS file :)
Here's your HTML
<table>
<tr>
<td>First Name</td>
<td>
<div>
<input class="input-wrapper" type="text" name="FirstName" />
</div>
</td>
</tr>
</table>
Here's your CSS
input.input-wrapper{
border:5px solid green;
}
And here's your INLINE style
<input style="border:5px solid green;" type="text" name="FirstName" />
Here is my page structure with three column: 30-40-30
Here is fiddle: http://codepen.io/karimkhan/pen/BDfhJ
Proble is :
I want to position div in right section at particular height with div-height is 200px.
When I put style="height:150px" in right section div, right div remains on top and left and middle section move at 150px height.
Why?
<table border="0" width="100%">
<tr>
<td style="width:30%">
<div class="left">
Hi
</div>
</td>
<td style="width:40%">
<div class="middle">
<input type="text" id="url" width="80%">
<button type="submit" onclick="GetSentiment()" value="Submit">GetSentiment</button>
</div>
</td>
<td style="width:30%">
<div class="right" style="height:150px">
nice
</div>
</td>
</tr>
</table>
This is because the text in the <td> elements is vertically centered by default. If you apply styles to the <div>s in the other <td> elements, they will also behave. Alternatively, you can do <td valign="top"...> for each <td>.
EDIT: I notice that the code you posted above is much simpler than the code you posted on github. There may be other factors, including JavaScript or other styles affecting your production code. Without the production HTML, CSS, and scripts, it's impossible to determine everything that could be affecting the layout.
I am having some problems getting a small piece of text to be centered while floating next to an image.
<html>
<head>
<style type="text/css">
img
{
float:right;
}
</style>
</head>
<body>
<p>In the paragraph below, we have added an image with style <b>float:right</b>. The result is that the image will float to the right in the paragraph.</p>
<div>
<img src="logocss.gif" width="95" height="84" />
<div style="position:relative; top: 20px;">
This
</div>
<div>
Other stuff...
</body>
</html>
(You can copy and paste this code into http://www.w3schools.com/CSS/tryit.asp?filename=trycss_float to see it in action.
What I would like is a way to vertically center the text while floating beside this image. and also not mess up text that comes after it. (as you can see, "Other Stuff..." is on top of "This")
I would prefer a pure CSS approach(or possibly restructuring of divs and such) because this is just an example showing the problem. The application it is being used in is very complex and having it all go into a table would require quite a bit of work, and possibly wouldn't look right.
UPDATE
Ok, I have ripped out part of my asp.net generated page that shows the problem I am having. I realize the code is ugly and apologize. It was generated by machine
<html>
<head>
<style type="text/css">
img
{
float:right;
}
</style>
</head>
<body>
<p>In the paragraph below, we have added an image with style <b>float:right</b>. The result is that the image will float to the right in the paragraph.</p>
<div>
<table>
<tr>
<td>
<div style="line-height:84px;">
<img src="logocss.gif" width="95" height="84" />
<span>This </span>
</div>
</td>
</tr>
</table>
Other stuff...
<br>
<br>
Actual application:
<br>
<div style="width:300px;">
<div style="width:300px;">
<input type="hidden"/>
<table border="0" style="border-collapse:collapse;border-spacing:1px;">
<tr>
<td style="width:250px;"><div style="line-height: 50px;">
<input type="image" title="Calculate Field" src="logocss.gif" style="border-width:0px;float: right;" /><span style="display:inline-block;color:Black;width:250px;">Email</span>
</div></td><td style="width:350px;"><table border="0">
<tr>
<td><input style="background-color:White;height:100%;width:300px;" /></td><td style="width:300px;"></td></tr></table></td><td style="width:300px;"></td>
</tr><tr style="height:0px;">
<td></td><td colspan="2" style="width:300px;"><span style="display:inline-block;height:0px;width:300px;"></span></td>
</tr>
</table>
</div>
</div>
</body>
</html>
Sorry for big code but its a working example of my problem. I did the line height trick but it seems to have no effect here. Basically what I want is for the edit control to be vertically centered in the middle of the image(which is easy because of the table) and for the "Email" text to be vertically centered in the middle of the image. I can not make it work though in this arrangement. What am I doing wrong?
What about this? (note that the line-height value equals the image's height):
<html>
<head>
<style type="text/css">
img
{
float:right;
}
</style>
</head>
<body>
<p>In the paragraph below, we have added an image with style <b>float:right</b>. The result is that the image will float to the right in the paragraph.</p>
<div>
<div style="text-align:right;line-height:84px;">
<img src="logocss.gif" width="95" height="84" />
This
</div>
Other stuff...
</body>
</html>
UPDATE:
Considering the updated code, I came up with this:
<div style="width:300px;">
<div style="width:300px;">
<input type="hidden"/>
<table border="0" style="border-collapse:collapse;border-spacing:1px;">
<tr>
<td style="width:250px;"><div style="line-height: 84px; width:250px; text-align:right;">
<input type="image" title="Calculate Field" src="logocss.gif" style="border-width:0px;float: right;" />Email
</div></td><td style="width:350px;"><table border="0">
<tr>
<td><input style="background-color:White;height:100%;width:300px;" /></td><td style="width:300px;"></td></tr></table></td><td style="width:300px;"></td>
</tr><tr style="height:0px;">
<td></td><td colspan="2" style="width:300px;"><span style="display:inline-block;height:0px;width:300px;"></span></td>
</tr>
</table>
</div>
</div>
I'm not saying it's the best way to do it, but I tried not to modify your code too much.
You don't need to wrap the text in a span in my opinion.
If you want to stick to using tables, then try looking at the valign="middle" property of the td element : http://www.w3schools.com/TAGS/att_td_valign.asp
But if you want to do that, you'll have to separate the image from the text and put them in different tds.
Slightly different solution than the one from Glennular. I'm not entirely sure how you want to do this, but the following centers the text This..., floats the image to its right (and it would wrap the text if it stretches to the image) and puts the Other stuff... below it.
<html>
<head>
<style type="text/css">
img
{
float:right;
}
</style>
</head>
<body>
<p>In the paragraph below, we have added an image with style <b>float:right</b>. The result is that the image will float to the right in the paragraph.</p>
<div>
<div style="position:relative; top: 20px; text-align:center;">
<img src="logocss.gif" width="95" height="84" />
This
</div>
<div style="clear:right;">
Other stuff...
</body>
</html>
This might be what you're looking for.
I think you mean you want the image on the right side of the DIV. The float right will put it on the Right end of the container. Which has no size, ie. the whole screen.
<html>
<head>
<style type="text/css">
img
{
float:left;
}
</style>
</head>
<body>
<p>In the paragraph below, we have added an image with style <b>float:right</b>. The result is that the image will float to the right in the paragraph.</p>
<div>
<div style=" top: 20px;float:left;">
This
</div><img src="logocss.gif" width="95" height="84" />
</div>
Other stuff...
</body>
</html>