I'm building a website, but I have a problem.
I have one div that creates the content with a BG color!
The problem is, the text appears in line to the bottom but I want them next to each other!
Here is a link to a screenshot for an example:
http://www.mupload.nl/img/9x7jco1v45f.png
I've tried some code in my CSS but nothing worked.
This is what I have now:
CSS:
#rechts {
float: right;
margin-right: 10px;
}
#lings {
float: left;
margin-left: 10px;
}
.inhoud {
padding-bottom:100px; /* Height of the footer element */
padding-top:150px;
background-color: #f5f5f5;
z-index: 999;
margin-left: 10%;
margin-right: 10%;
}
HTML:
<div class="inhoud">
<p class="contactInhoudLings">
// Here is the personal info.
<p class="contactInhoudRechts">
// here is the PHP Contact form.
</p>
</div><!-- #inhoud -->
utilize display:inline-block; like below
.container {
background-color: lightgray;
}
.section {
display: inline-block;
vertical-align: top;
width: 49%;
}
<div class="container">
<div class="section">
Some random inforamtion here<br/>
more contact information
</div>
<div class="section right">
Name<br/>
<input type="text" /><br/>
Email<br/>
<input type="text" /><br/>
Phone<br/>
<input type="text" /><br/>
</div>
</div>
For the HTML you provided, simply change your css to
.contactInhoudLings{
float: left;
width: 50%;
}
.contactInhoudRechts{
float: left;
width: 50%;
}
Demo
You could use flex to split the container in two or any other number.
.container {
display: flex;
}
.col {
flex-basis: 0;
flex-grow: 1;
}
<div class="container">
<div class="col">
text
</div>
<div class="col">
your form
<form>
<label for=name>Name:<label/>
<input type=text name=name placeholder=name />
<input type=submit />
</form>
</div>
</div>
If you want margin-left and margin-right than try this:
HTML
<div class="inhoud">
<p class="contactInhoudLings">
// Here is the personal info.
<p class="contactInhoudRechts">
// Here is the PHP Contact form.
</p>
</div><!-- #inhoud -->
CSS
.inhoud{
width: 100%;
}
.contactInhoudLings{
background-color: red;
float: right;
margin-right: 1%;
width:49%;
}
.contactInhoudRechts{
background-color: green;
float: left;
margin-left: 1%;
width:49%;
}
Look also the jsfiddle example
Related
I don't know how to concisely describe what I'm trying to achieve in words, so here's an ASCII picture:
(+1) | Enter your phone number |
| Enter your name |
I have two <input>s, one for phone number and one for name. These should be horizontally aligned (in the same "column").
I also have a <span> (country code, another piece of data that has to be inputted along with the phone number). This should "hang off" the phone number input to the left.
I'd like to vertically center the country code so that it appears in the middle of the phone number input.
It seems that this is possible with CSS Grid. I'm wondering: is there a solution that does not involve CSS Grid?
Here is a snippet of what I have so far. I'm using a "size zero position: relative element with its content in a position: absolute child" technique to exclude the "country code" element from the flow, so it does not disrupt the horizontal alignment.
As you can see, it does not vertically center the country code.
input {
height: 2rem;
}
.container {
margin-left: auto;
margin-right: auto;
text-align: center;
}
.phone-number-input-container {
display: inline-flex;
align-items: center;
}
.name-input-container {
margin-top: 1rem;
}
.country-code-container {
position: relative;
width: 0;
height: 0;
}
.country-code {
position: absolute;
right: 1rem;
}
<html>
<body>
<div class='container'>
<div class='phone-number-input-container'>
<span class='country-code-container'>
<b class='country-code'>+1</b>
</span>
<input class='input' placeholder="Phone number"></input>
</div>
<div class='name-input-container '>
<input class='input' placeholder="Name"></input>
</div>
</div>
</body>
</html>
You are almost good, simply use position:absolute on the upper container and only adjust the left value since flexbox is already centring vertically (so no need to set top)
input {
height: 2rem;
}
.container {
margin-left: auto;
margin-right: auto;
text-align: center;
}
.phone-number-input-container {
display: inline-flex;
align-items: center;
position:relative;
}
.name-input-container {
margin-top: 1rem;
}
.country-code-container {
position: absolute;
left:-2rem;
}
<html>
<body>
<div class='container'>
<div class='phone-number-input-container'>
<span class='country-code-container'>
<b class='country-code'>+1</b>
</span>
<input class='input' placeholder="Phone number">
</div>
<div class='name-input-container '>
<input class='input' placeholder="Name">
</div>
</div>
</body>
</html>
Another idea is to consider negative margin like below and you no more need position:absolute
input {
height: 2rem;
}
.container {
margin-left: auto;
margin-right: auto;
text-align: center;
}
.phone-number-input-container {
display: inline-flex;
align-items: center;
position:relative;
}
.name-input-container {
margin-top: 1rem;
}
.country-code-container {
margin-left:-30px;
margin-right:30px;
width:0;
}
<html>
<body>
<div class='container'>
<div class='phone-number-input-container'>
<span class='country-code-container'>
<b class='country-code'>+1</b>
</span>
<input class='input' placeholder="Phone number">
</div>
<div class='name-input-container '>
<input class='input' placeholder="Name">
</div>
</div>
</body>
</html>
You can also do a translate:
input {
height: 2rem;
}
.container {
margin-left: auto;
margin-right: auto;
text-align: center;
}
.phone-number-input-container {
display: inline-flex;
align-items: center;
position:relative;
}
.name-input-container {
margin-top: 1rem;
}
.country-code-container {
transform:translateX(-30px);
width:0;
}
<html>
<body>
<div class='container'>
<div class='phone-number-input-container'>
<span class='country-code-container'>
<b class='country-code'>+1</b>
</span>
<input class='input' placeholder="Phone number">
</div>
<div class='name-input-container '>
<input class='input' placeholder="Name">
</div>
</div>
</body>
</html>
Why not flexbox? Grid might be a bit too beefy
.wrapper {
display:flex
}
input {
width:300px
}
<div class="wrapper">
<div class="country-code">
(+1)
</div>
<div class="right">
<div class="phone">
<input type="phone" placeholder="Enter your phone numner">
</div>
<div class="name">
<input type="text" placeholder="Enter your name">
</div>
</div>
</div>
I've HTML structure like following
<div class="box-search-select">
<div class="search-left">
<input id="search" type="text">
</div>
<button type="submit" class="button">Search</button>
<div style="clear:both"></div>
</div>
and CSS as following
.box-search-select{
width:100%;
padding:20px 0;
}
.search-left{
float:left;
width: 90%;
}
.search-left input{
width:100%;
}
button{
float:right;
}
Output : (Normal screen size)
I want to expand "search-left" div width to the Search button.
Which should work properly for fluid responsive layouts too.
Here I've created fiddle if you wish to play : https://jsfiddle.net/j7g8143a/1
Now if I decrease the width of screen then the search button move to next line like following picture
but I want the "search-left" div to automatically adjust it's width according to screen size like following picture.
I need only CSS solution without using any media queries
EDIT: It should have to be compatible with IE9.
Here is your solution with demo and it will be work on IE9 also:
<div class="box-search-select">
<div class="search-left">
<input id="search" type="text">
</div>
<button type="submit" class="button">Search</button>
</div>
.box-search-select {
padding: 20px 68px 20px 0; /* give padding-right equal to button witdh */
position: relative;
}
.search-left input {
display: block;
width: 100%;
}
button {
background: #cccccc none repeat scroll 0 0;
border: 1px solid #dddddd;
padding: 1px;
position: absolute;
right: 0;
top: 20px;
width: 60px;
}
Demo:
https://jsfiddle.net/0u83dbm7/
You can use Flexbox
.box-search-select {
display: flex;
align-items: center;
}
.search-left {
flex: 1;
}
input {
width: 100%;
}
<div class="box-search-select">
<div class="search-left"><input id="search" type="text"></div>
<button type="submit" class="button">Search</button>
</div>
You can also use CSS tables
.box-search-select {
display: table;
}
.search-left,
button {
display: table-cell;
vertical-align: middle;
}
.search-left {
width: 100%;
}
input {
width: 100%;
}
<div class="box-search-select">
<div class="search-left"><input id="search" type="text"></div>
<button type="submit" class="button">Search</button>
</div>
Its gonna work I think
<div class="box-search-select">
<div class="search-left" style="width:80%">
<input id="search" type="text">
</div>
<button type="submit" class="button">Search</button>
<div style="clear:both"></div>
</div>
<style>
#search{
width:100%;
}
.box-search-select{
width:100%;
padding:20px 0;
}
.search-left{
float:left;
width: 90%;
}
.search-left input{
width:100%;
}
button{
float:right;
}
</style>
please let me know if this is not the expected output.
Put your input and button inside the div and use display:flex
.box-search-select{
padding:20px 0;
float:left;
width:100%
}
.search-left{
float:left;
width:100%;
display:flex;
}
.search-left input{
width:100%
}
button{
float:right;
}
<div class="box-search-select">
<div class="search-left">
<input id="search" type="text">
<button type="submit" class="button">Search</button>
</div>
<div style="clear:both"></div>
</div>
WHAT I HAVE
I have this Table.
With this HTML
<div class="list-item">
<p>
<input type="checkbox">
<span class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></span>
<span class="list-title">{{this.title}}</span>
<span class="list-owner">{{this.owner}}</span>
<span class="list-date">16 Dec 2014</span>
</p>
</div><br>
With this CSS
.list-item{
display: inline-block;
width: 100%;
border: solid 1px #dddddd;
}
.list-type{
margin-left: 10px;
margin-right: 10px;
}
WHATH I WANTO TO ACCOMPLISH
But i want to create something like a table inside the <div>.
NOTE I KNOW that a <table> fits perfect, but for how this content is beign created i need to simulate a table with this <div>, so table unforntannly its not an option here.
I need to replicate something like this (check image).
NOTE ignore the Star icon
WHAT I ALREADY TRY
Settin margin-left to each of the <span> but the order of the "admin" and "date" are not equals, if i use margins i get this (check image).
Im getting this with this CSS
.list-item{
display: inline-block;
width: 100%;
border: solid 1px #dddddd;
}
.list-type{
margin-left: 10px;
}
.list-title{
margin-left: 10px;
}
.list-owner{
margin-left: 100px;
}
.list-date{
margin-left: 190px;
}
Try CSS tables:
.list-item {
display: table;
}
.list-item > p {
display: table-row;
}
.list-item > p > * {
display: table-cell;
}
I have changed some Tags and some CSS, I like the use of percentage width and divs. If this does not help you maybe it can give you more ideas.
.list-item{
display: inline-block;
width: 100%;
border: solid 1px #dddddd;
}
.cb{
float: left;
width:3%;
}
.list-type{
float: left;
width:8%;
}
.list-title{
float:left;
width:35%;
}
.list-owner{
float:left;
width:15%;
}
.list-date{
float: left;
width: 20%;
}
<div class="list-item">
<p>
<input type="checkbox" class="cb">
<div class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></div>
<div class="list-title">Title</div>
<div class="list-owner">Owner</div>
<div class="list-date">16 Dec 2014</div>
</p>
</div><br>
<div class="list-item">
<p>
<input type="checkbox" class="cb">
<div class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></div>
<div class="list-title">Title22</div>
<div class="list-owner">Owner22</div>
<div class="list-date">16 Dec 201422</div>
</p>
</div><br>
<div class="list-item">
<p>
<input type="checkbox" class="cb">
<div class="list-type"><img src="/images/types/{{this.type}}.png" title="{{this.type}}" /></div>
<div class="list-title">Title 333</div>
<div class="list-owner">Owner 333</div>
<div class="list-date">16 Dec 2014333</div>
</p>
</div>
Did this help???
Try with the below css:
.list-title{ margin-left: 10px; width: 200px;}
.list-owner{ margin-left: 10px; width: 40px;}
.list-date{ margin-left: 10px; width: 40px;}
Note: Change the width size according to your need.
Tabular data: use tables.
Or as #oriol suggested, use CSS tables.
I have this set (JsFiddle link) of labels and text inputs.
How do I center the whole thing in the middle of the page?
I tried wrapping them in a div and setting it's alignment to cetner - didn't do what i expected at all.
Any help is appreciated, than you.
Code for reference:
<div>
<div class="left">
label
</div>
<div class="right">
input element
</div>
</div>
<div>
<div class="left">
another label
</div>
<div class="right">
another input element
</div>
</div>
//align the labels and input nicely
.left {
width: 20%;
float: left;
text-align: right;
}
.right {
width: 65%;
margin-left: 10px;
float:left;
}
If you're going to use float, than you need to wrap the whole thing in a DIV and apply margin: 0 auto;
I'd do this in this case:
<style>
.field {
width: 80%;
margin: 0 auto;
}
.left {
width: 20%;
text-align: right;
display: block;
float: left;
margin-right: 5%;
}
</style>
<div class="field">
<label class="left">label</label>
<input type="text">
</div>
<div class="field">
<label class="left">another label</label>
<input type="text">
</div>
wrap the whole thing in a div and set
margin: auto;
also set a width, if you want to use the text-align: center; method , that should be applied to the parent pf the div to be centered.
Task: Make text box 100% width but allow enough room for button.
Problem: Button appears on next line and text box exceeds width of its container.
<div class="field">
<input type="text" name="my-field" />
<input type="button" id="my-button" value="Add +" />
</div>
.field {
margin-right: -70px;
width: 100%;
}
.field input[type=text] {
display: block;
float: left;
margin-right: 70px;
}
.field input[type=button] {
display: block;
float: right;
}
My primary layout uses the following trick to achieve flexible width with fixed sidebar, but for some reason this is not working on the above.
<div class="outer-wrap">
<div class="content">
...
</div>
<div class="sidebar">
...
</div>
</div>
.outer-wrap {
margin-right: -300px;
width: 100%;
}
.content {
float: left;
margin-right: 300px;
}
.sidebar {
float: right;
}
What mistake am I making here?
You have to screw with the HTML a bit, but otherwise this works perfectly in IE7+ and all modern browsers.
See: http://jsfiddle.net/thirtydot/25bZC/
CSS:
.field > span {
display: block;
overflow: hidden;
padding-right: 10px
}
.field input[type=text] {
width: 100%
}
.field input[type=button] {
float: right
}
HTML:
<div class="field">
<input type="button" id="my-button" value="Add +" />
<span><input type="text" name="my-field" /></span>
</div>
To pull this off you must ensure that the element which you are floating right comes before the one floating left. Like this
<div class="field">
<input type="button" id="my-button" value="Add +" />
<input type="text" name="my-field" />
</div>
try giving fixed width to
field input[type=text]
and
.field input[type=button]