http://liveweave.com/73vub5
So I got the objects to display the way I want as seen in the image, but my problem now is when I choose the second object the first should become unchecked and choose the second one. Using regular input boxed just inside a form it does it automatically without the need for JavaScript. Anyway to fix this that'll same me tons of time coding so I don't have to define it in Javascript/JQuery each time an object has been selected/checked and deselected/unchecked.
<style type="text/css">
div#container div {
display:inline-block;
margin:1.25%;}
div#circle {
width:40px;
height:40px;
border:1px dashed #000;
border-radius:50%;}
div#square {
width:40px;
height:40px;
border:1px dashed #000;}
</style>
<div id="container" align="center">
<form>
<div id="square"><br><br>
<input type="radio" name="squareselec" checked="true"></div>
<div id="circle"><br><br>
<input type="radio" name="circleselec"></div>
</form>
</div>
To center the input element, you'll need to make the radio display: inline-block; - and it's container text-align: center;
I sugest staying away from id's unless using them for javaScript hooks or very special reasons. HERE is a jsfiddle with the code for you to play with. I hope this helps. -nouveau
HTML
<div class="object-wrapper">
<img alt="image name" src="http://placehold.it/50x50" />
<input type="radio" name="squareselec" />
</div>
<div class="object-wrapper">
<img alt="image name" class="circle" src="http://placehold.it/50x50" />
<input type="radio" name="squareselec" />
</div>
CSS
.object-wrapper {
width: 3em; /* arbitrary */
text-align: center;
/* to explain visually */
border: 1px solid red;
padding: .1em;
/* to grid them */
float: left;
margin-right: .5em;
}
.object-wrapper img {
display: inline-block;
width: 100%;
height: auto;
}
.object-wrapper input[type="radio"] {
display: inline-block;
}
.circle { /* to make a circle */
-webkit-border-radius: 100%;
border-radius: 100%;
}
Related
I'm looking to create the desired styling in the photo shown. Having trouble getting the custom SVGs I created to be inline with the text field. How would I go about creating this effect?
Here's a snippet of the code I'm using at the minute, where am I going wrong?
I'm mostly using the JQM library if that is of any help.
<div class="box2" style="display: inline-block; position:relative; width: 40vw;">
<img src="img/icon/regicons/usernumber.svg">
<input type="text" name="userNo" id="userNo" placeholder="Number" required><br>
</div>
Ensure that the <input/> has the same height as your <image/> and position it at top of it's parent element.
height: 32px; box-sizing: border-box;
absolute; top: 0;
Snippet:
input {
height: 32px;
box-sizing: border-box;
position: absolute;
top: 0;
}
.box2 {
display: inline-block;
position:relative;
width: 40vw;
}
<div class="box2" style="">
<img width="32" height="32" src="https://lh4.googleusercontent.com/-HhNoCFJ803s/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbAXJpr-jDsvmXVw0tx4PHId84zrlw/mo/photo.jpg?sz=32">
<input type="text" name="userNo" id="userNo" placeholder="Number" required>
</div>
I would use a flexbox, which is responsive by nature.
.box2 {
display: flex;
background-color: lightgrey;
align-items: center; /* Vertical alignment */
}
<div class="box2" style="position:relative; width: 40vw;">
<img src="https://via.placeholder.com/50x50/00ff00">
<input type="text" name="userNo" id="userNo" placeholder="Number" required><br>
</div>
Sorry, I know this is super basic but I've been through my coding reference books all day and I think my mind's a little buggered. I need to get BOTH the input field AND the "submit" button in one line, in the center of the page, similar to Google.
.logo {
width: 50%;
display: block;
margin: auto;
}
.input-fields {
padding: 3%;
width: 40%;
display: block;
margin: auto;
font-size: 90%;
}
.submit {
padding: 3%;
width: 15%;
}
<header>
<img class="logo" src="OnSaleTodayMobile.png" alt="OnSaleToday.co.za">
</header>
<div class="form-wrapper">
<form class="center">
<input class="input-fields" name="search" type="text" placeholder="Search for anything...">
<input class="input-fields submit" name="find" type="submit" value="Find">
</form>
</div>
The problem I'm getting is that the button is stacking underneath the text-field. What am I missing out?
Well Google has it vertically and horizontally aligned so you should try something like this (simplified version):
* {margin: 0; padding: 0; box-sizing: border-box}
html, body {width: 100vw; height: 100vh}
body {
display: flex;
justify-content: center;
align-items: center;
}
.align-me {
display: flex;
flex-direction: column;
align-items: center;
}
.align-me > .form-wrapper > .center {
display: flex;
}
<div class="align-me">
<header>
<img class="logo" src="OnSaleTodayMobile.png" alt="OnSaleToday.co.za">
</header>
<div class="form-wrapper">
<form class="center">
<input class="input-fields" name="search" type="text" placeholder="...">
<input class="input-fields submit" name="find" type="submit" value="Search">
</form>
</div>
</div>
But their design is not responsive and this is.
What you are seeing is the default behaviour of display:block.
Using display:inline-block will make them block elements so you can add padding, etc, but make them inline so they will appear beside each other (assuming they fit, and other styles don't change the default behaviour).
Just change the display from block to inline-block in your CSS here:
.input-fields {
[...]
display:inline-block;
}
Working snippet:
.logo {width: 50%; display:block; margin:auto;}
.input-fields {
padding:3%;
width:40%;
display:inline-block; /* change this from block to inline-block */
vertical-align: middle; /* this will help with any vertical alignment issues */
margin:auto;
font-size:90%;
}
.submit {
padding:3%;
width:15%;
}
/* Add this this to center your inputs -
you included the "center" class in your HTML but not it in your CSS */
.center { text-align:center}
<header><img class="logo" src="OnSaleTodayMobile.png" alt="OnSaleToday.co.za"/></header>
<div class="form-wrapper">
<form class="center">
<input class="input-fields" name="search" type="text" placeholder="Search for anything..."/>
<input class="input-fields submit" name="find" type="submit" value="Find"/>
</form>
</div>
You are missing a
display: inline-block;
on the elements you want to display in line. You currently have 'display: block;' This will push elements on to there own line.
You may also want:
vertical-align: middle;
To make them vertically aligned relative to each other.
To make sure they both stay dead center in the page put them all in a container (or just use your existing form container) and style it like:
position: absolute;
top: 50%;
left: 0;
right: 0;
transform: translateY(-50%);
text-align: center;
This will ensure no matter what the screen size is the container is in the middle both vertically and horizontally.
I am currently converting an old HTML form to not use tables. The label requires a fixed width, which I've achieved using an answer from this site. The current code is as follows:
HTML
<div id="form">
<label for="field1">Name </label>
<input type="text" id="field1" value="default name" />
</div>
CSS
label {
float: left;
width: 50px;
white-space: nowrap;
}
input {
display: block;
overflow: hidden;
width: *;
}
#field1 {
width: 150px;
}
Currently, the label is vertically aligned at the top. How can I vertically align the label and field to the centre?
Edit: I'm getting a lot of answers to basically pad my label into the correct position via a specified number of pixels. I don't want to do that as it's basically hard-coding and not true vertical alignment to the middle.
Following some advice I've received here, I've cleaned up my code some. See the above edited code.
I've tried vertical-align: middle; in label but it doesn't work. Please note that the user's platform will be IE.
If I get this right, You want the label and the input to vertically center align W.R.T each other and not the page. For that, there are couple of ways.
The Flexbox Way
If you want to use something new from the CSS world and be future ready, use flexbox. Example -
.fieldHeading {
width: 50px;
}
.fieldSpan {
overflow: hidden;
}
#field1 {
width: 150px;
}
/*flexbox approach.
* height and background added for clarity.
*/
#form {
height: 100px;
background: #bada55;
display: flex;
align-items: center;
}
<div id="form">
<label for="field1" class="fieldHeading">Name </label>
<span class="fieldSpan"><input type="text" id="field1" value="default name" /></span>
</div>
The vertical-align Way
This works well when you have both the label and the input on one line as inline-block elements. Example -
.fieldHeading {
width: 50px;
vertical-align:middle;
}
.fieldSpan {
overflow: hidden;
vertical-align:middle;
}
#field1 {
width: 150px;
}
<div id="form">
<label for="field1" class="fieldHeading">Name </label>
<span class="fieldSpan"><input type="text" id="field1" value="default name" /></span>
</div>
The height & line-height Duo
This works well too but if your label is big and has the possibility of wrapping into multiple lines, it's gonna look terrible. Example -
.fieldHeading {
width: 50px;
}
.fieldSpan {
overflow: hidden;
}
#field1 {
width: 150px;
}
/*line-height and height be same for parent
* background added for clarity.
*/
#form {
line-height: 40px;
height: 40px;
background: #bada55;
}
<div id="form">
<label for="field1" class="fieldHeading">Name </label>
<span class="fieldSpan"><input type="text" id="field1" value="default name" /></span>
</div>
I hope these help you not only in this problem but for all other vertical alignment problems.
You can use line-height or margin-bottom until you get satisfactory results.
Example
#form label {
line-height:1.4;
margin-bottom:2px;
}
This will apply the selector to all labels under the form. If you want to be specific, you can use the specific css class like .fieldHeading instead of #form label.
Do you need like this?
<div id="form">
<div class="valign">
<label for="field1" class="fieldHeading">Name </label>
<span class="fieldSpan"><input type="text" id="field1" value="default name" /></span>
</div>
</div>
<style>
.fieldHeading {
float: left;
width: 50px;
}
.fieldSpan {
display: block;
overflow: hidden;
width: *;
}
#field1 {
width: 150px;
}
#form {display: table;height:100%;}
.valign {
display: table-cell;
vertical-align: middle;
}
</style>
I think, solution margin-bottom, use whatever px you want
.fieldHeading {
float: left;
width: 50px;
margin-bottom: 3px;
}
Use:
.fieldHeading {
display: inline-block;
width: 50px;
vertical-align: middle;
}
#field1 { width: 150px; }
Let span be an inline type.
You don't really need the span for enclosing your input element.
I've got a problem with my HW. I cant align 2 elements on the left side https://jsfiddle.net/tkjxLfjy/ This is the code and i tried things like float:left but didn't work... So can you help me to put the meter and the text under the picture (the black sqare)?
According to w3school:
Elements after a floating element will flow around it. To avoid this,
use the clear property.
Add Clear:both to the div. The image has float:left so the next elements sit behind that.
Jsfiddle
figure div
{
clear: both;
}
You can remove float:left and add display: block to the image
Basically display: block reserve the whole line for the element, so that no other element set beside it, unless it's positioned.
Here is a fiddle
You should try like like this-
.clr{
clear:both
}
body {
font-family: serif;
height:100%;
width: 100%;
}
#container {
width: 650px;
border-radius: 10px;
height: 280px;
background-color: pink;
}
.header {
text-align: center;
position:relative;
top: 15px;
}
/* Figure one */
figure{
float: left;
}
img {
width: 150px;
height: 150px;
background: black;
}
meter {
width: 90px;
}
.meter-col{
float: left;
}
<div id="container">
<div class="header">
<h2>Profile</h2>
</div>
<figure>
<figcaption>User: Kent</figcaption>
<img src="avatar.png" />
</figure>
<div class="meter-col">
<div>Profile completed: 60%</div>
<meter value="60" min="0" max="100">2 out of 10</meter>
</div>
<div class="clr"></div>
</div>
May it will helps you.
<div id="container">
<div class="header">
<h2>Profile</h2>
</div>
<figure>
<figcaption>User: Kent</figcaption>
<img src="avatar.png" />
<div>
Profile completed: 60%
<meter value="60" min="0" max="100">2 out of 10</meter>
</div>
</figure>
</div>
No need of other changing 'cause the tag has a default "block" behavior.
I changed a few things around. I also updated a few things to HTML5 (preferred). I changed everything to display block and changed the div that all of that lives in to float: left. JS fiddle link below.
https://jsfiddle.net/tkjxLfjy/6/
HTML:
<body>
<div id="container">
<header>
<h2>Profile</h2>
</header>
<figure>
<figcaption>User: Kent</figcaption>
<img src="avatar.png" />
<label for="meter">Profile completed: 60%</label>
<meter name="meter" value="60" min="0" max="100">2 out of 10</meter>
</figure>
</div>
</body>
CSS:
body {
font-family: serif;
height:100%;
width: 100%;
}
#container {
width: 650px;
border-radius: 10px;
height: 280px;
background-color: pink;
float: left;
}
header {
text-align: center;
position:relative;
top: 15px;
}
/* Figure one */
img {
width: 150px;
height: 150px;
background: black;
display: block;
}
meter {
float: left;
width: 90px;
}
I know there a many of these about but for some reason I keep failing to implement them.
So I need the content in the class .infobox to be in the middle of the div. So I need it aligned vertical and horizontally.
I have put ALL my code below as some of the "fixes" I tried worked but caused the layout to move and so on. So hopefully you guys can get it aligned without causing the layout to break.
Fiddle is at the bottom. On a side note if you have any tips on how to neaten the layout code please do let me know. But the main problem is aligning the content.
HTML:
<div id="con">
<div id="box">
<div id="header"><h1>Test</h1></div>
<div id="left">
<div class="infobox">Test: <br /> <input /> </div>
<div class="infobox">Test: <br /> <input /> </div>
<div class="infobox">Test: <br /> <input /> </div>
<div class="infobox">Test: <br /> <input /> </div>
</div>
<div id="right">
<div class="resultbox">
<ul>
<li>Test <br />Test</li>
</ul>
</div>
<div class="contactbox">
<ul>
<li>Phone Number: <br /> 00000 000000</li>
<li>Email: <br /> test#Test.com</li>
</ul>
</div>
</div>
</div>
</div>
CSS:
div {
outline: 1px solid #000;
}
#box {
width: 580px;
height: 300px;
}
#header {
height: 15%;
background: url(http://us.123rf.com/400wm/400/400/mechanik/mechanik1112/mechanik111200003/11665900-vector-cartoon-semi-truck.jpg) no-repeat;
background-size:80px 40px;
background-position:right top;
}
#left {
width:70%;
height: 85%;
float: left;
}
#right {
width:30%;
height: 85%;
float: right;
}
.infobox {
width: 50%;
height: 50%;
float: left;
text-align: center;
}
.resultbox {
width: 100%;
height: 50%;
}
.contactbox {
width: 100%;
height: 50%;
font-size: 12px;
}
.contactbox ul, .resultbox ul {
margin: 0;
}
.contactbox li, .resultbox li {
list-style: none;
}
DEMO HERE
What I have tried:
Tried to use padding-top and padding-bottom - This seemed to not align it correctly and then I couldn't get the layout to sit correctly.
Also looked into using position: relative and position: absolute but I have never been too good with them and couldn't manage to get the content to sit where I wanted it to.
I took the liberty of manipulating you mark-up a bit and added an extra div to achieve the output.
Fiddle
HTML
<div class="infobox">
<div class="cent">Test:
<br />
<input />
</div>
</div>
CSS
.infobox > .cent {
outline: 1px solid #0F0;
vertical-align: middle;
margin-top:20%;
}
Whats happening here??? : since your content div infobox has the styling, to give a different set of styling to inner content(which is not floating), you have to use a them under a child div for display!
add margin:0 auto; to #box
like so: http://jsfiddle.net/c82DU/2/
You could take a look at this site, it explains a bit about tables.
The layout u are using looks like a table, so why not use tables? easier text aligning
http://www.w3schools.com/html/html_tables.asp