I have a problem with the buttons on my webpage.
This is what they look like when I enter fullscreen
When I click next, and go back to this same page it then turns into this
I tried no matter what I try they always end up not aligned when I click next and go back to this same page.
The style of the buttons
.button1{
bottom: -70px;
right:0px;
position: absolute;
}
.button2{
bottom: 28px;
left:8px;
position: absolute;
}
The buttons
</div>
<div class="button1">
<button type="submit" name="Next">Next</button>
</div>
</form>
<form action="Time.html">
<div class="button2">
<button type="submit" name="Next">Back</button>
</div>
</form>
Also you can see that they don't belong in the same form.
The form where Next button belongs
.form1 {
border: 8px solid #7B93F4;
left:0;
position: absolute;
top: 43%;
width: 98.9%;
text-align:center;
}
Any idea on how can I fix this and prevent this from happening?
You could change the layout a bit, floating the buttons:
.cont {
overflow: hidden;
}
.button1{
float: left;
}
.button2{
float: right;
}
<div class="cont">
<button class="button1">button1</button>
<button class="button2">button2</button>
</div>
Floating is more flexible then position absolute.
There is an error with your HTML code. Edit it so that it'll be clear.
The two buttons are contained in different form elements which are stacked on top of themselves because they are block elements. Put them in the same form element and use the style below.
You should avoid positioning absolutely when you can. I'll suggest you float the buttons instead.
Your HTML might look something like this
<form>
<div class="button1">
<button type="submit" name="Next">Next</button>
</div>
<div class="button2">
<button type="submit" name="Next">Back</button>
</div>
</form>
and your CSS like this
.form1 {
/* your other codes */
overflow: auto;
}
.button1{
float: left;
}
.button2{
float: right;
}
Hope it works.
Related
As you can see in my Jsfiddle, I have a div and three buttons. I would like the buttons to be placed at right: 85% (so that you get what I mean), without me having to use position: absolute.
I also tried this:
.button {
float: right;
}
.. but the buttons fall out off the div.
Any ideas please?
Here's my JsFiddle.
I've added a div to hold your three button divs. You can update the margin right to have it more to the left.
div.button-holder div:last-child{
margin-right: 10px;
}
Change Markup and add class:
<div class="header_div">
foo
<div class='btns'>
<button class="button">New</button>
</div>
<div class='btns'>
<button class="button">Load</button>
</div>
<div class='btns'>
<button class="button">Delete</button>
</div>
</div>
Instead Of..
.button {
float: right;
}
Try This...
.btns {
float: right;
}
I have two divs encased in a larger div. I thought this would make the two divs display within the parent, but for some reason they display outsie of it. I have tried every different combination of position types I can think of, and I tried display: inline. Does anyone know how I can position the two divs inside of their parent?
Here's my css file:
#Buttons {
float: center;
height: 100px;
width: 900px;
#Button1 {
width: 20px;
}
#Button2 {
width: 20px;
}
}
application.html.erb
<div id="Buttons">
<div id="Button1">
<%= link_to "button1", "#", :class "btn btn-large" %>
</div>
<div id="Button2">
<%= link_to "Button2", "#", :class "btn btn-large" %>
</div>
</div>
UPDATE: Adding inline: display to #Button1 and #Button2 makes them display within #buttons:
#Buttons {
float: center;
height: 100px;
width: 900px;
#Button1 {
width: 20px;
display: inline;
}
#Button2 {
width: 20px;
display: inline;
}
}
but I added the exact same code to #SearchBar, and it's still displaying outside of it's navbar:
#SearchBar {
height: 30px;
width: 30px;
display: inline;
#p {margin: 0px;}
}
.navbar {
height: 130px;
}
Here's the html for my entire heading:
<header class=navbar navbar-fixed-top navbar-inverse">
<div id="Buttons">
<div id="Button1">
<a class="btn btn-large btn-primary" href="/subjects/1">1</a>
</div>
<div id="Button2">
<a class="btn btn-large btn-primary" href="/subjects/2">2</a>
</div>
</div>
<div id= "SearchBar">
<form accept-charset="UTF-8" action="/things" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>
<p id="p">
<input id="search" name="search" type="text" />
<button class="btn" type="submit"><i class="thing-search">Go</i></button>
</p>
</form> </div>
</header>
There are 2 problems with your CSS:
CSS does not allow nested rules. If you're using a CSS preprocessor like Less or Sass then you can build the Less/Sass source into plain CSS, which will allow you to nest rules in your Less/Sass source, but if you have nested rules in the final CSS that is served to the client then it will fail.
See Are CSS selectors case-sensitive?. "CSS itself is case insensitive, but selectors from HTML (class and id) are case sensitive." Your id attributes are uncapitalized but your CSS selectors reference capitalized ids.
If you fix these problems, your code will work. See http://jsfiddle.net/9mmnp6Lz/.
HTML:
<div id="buttons">
<div id="button1">
b1
</div>
<div id="button2">
b2
</div>
</div>
CSS:
#buttons {
float:center;
height:100px;
width:900px;
border:1px solid red;
}
#button1 {
width:20px;
border:1px solid green;
}
#button2 {
width:20px;
border:1px solid blue;
}
Edit: It looks to me like it's the <p> in your HTML; it has a default margin that is pushing the whole <p> content down, so that it's not flush with the div that sits above it. You should be able to fix it by setting margin:0 on the <p>. See http://jsfiddle.net/9mmnp6Lz/2/.
if you are in CSS this is Not Work for Child of Your syntax is for LESS
LESS must export to CSSand your Selector for CSS is start with Upper Char...
One more Float : Center its undefined you can see this source of CSS
W3SCHOOLS/CSS FOR FLOAT
here code :
buttons{
background: black;
height: 100px;
width: 900px;
}
#button1 {
background : red;
width: 20px;
}
#button2 {
background : yellow;
width:20px;
}
see this Sample on JSFiddle
http://jsfiddle.net/toxmgtup/
I have multiple divs with dynamic content and all of them have the same height. Beside the content a Submit Button is inside of each div, which is directly next to the content.
But i want to display the Button at the bottom of the div.
HTML Markup:
<div class="product-teaser-row">
<div class="product-teaser">
<h2>Title</h2>
<p>Content Content Content Content Content Content Content Content Content Content Content Content Content Content</p>
<button class="btn btn-grey" type="submit" name="action">Ansehen</button>
</div>
<div class="product-teaser">
<h2>Title 2</h2>
<p>Content</p>
<button class="btn btn-grey" type="submit" name="action">Ansehen</button>
</div>
</div>
CSS Code:
div.product-teaser {
border: 1px #c7d2d6 solid;
padding: 0px 10px 10px 10px;
width: 216px;
height: 100%;
display: table-cell;
}
div.product-teaser-row {
display: table;
border-collapse: separate;
border-spacing: 10px;
}
I've already tried different things like vertical-align: bottom on the div and display: inline-block on the Button, but nothing worked for me.
Here is a JSFiddle Demo of my code.
You can try this
CSS
div.product-teaser {
border: 1px #c7d2d6 solid;
padding: 0px 10px 20px 10px; /*Increase the bottom padding so the button does not overlap the content*/
width: 216px;
height: 100%;
display: table-cell;
position: relative; /*Add this css*/
}
/*Set the button at the bottom using position: absolute;*/
.btn-grey {
bottom: 5px;
left: 5px;
position: absolute;
}
To do that you just have to position absolute your button and define the bottom position and give a padding-bottom to your container to be sure that no content will override your button.
here for a jsfiddle exemple.
You could try adding a height property to the p element.
Example:
p{
height: 95px;
}
JSFiddle Demo : http://jsfiddle.net/robcabrera/g3p2Y/1/
why don't you put button in separate <div> tag like:
<div id=my>
<button class="btn btn-grey" type="submit" name="action">
Ansehen
</button>
</div>
set according margin-top to put the button at bottom like:
#my
{
margin-top:100px;
}
FIDDLE here
I'm designing a web page with a small label off to the right of the body on some lines. For this, I created an absolute-positioned <div> inside of a relative-positioned one.
The label is appearing exactly as I want it. However, even though the absolute-positioned <div> dimensions are 0 x 0, it still is taking up some room on the line.
This can be seen at http://jsfiddle.net/sznH2/. I would like the two buttons to line up vertically. Instead, the button next to the label is pushed left a few pixels.
Can anyone see what is causing this spacing and how to eliminate it?
HTML:
<div>
<div class="pull-right">
<button>Hello world!</button>
</div>
</div>
<div>
<div class="pull-right">
<button>Hello world!</button>
<div class="outer-relative">
<div class="inner-relative">
<span>XXX</span>
</div>
</div>
</div>
</div>
CSS:
body {
width: 500px;
margin-left: auto;
margin-right: auto;
}
.pull-right {
text-align: right;
}
.outer-relative {
display:inline-block;
position:relative;
height: 0px;
width:0px;
}
.inner-relative {
position: absolute;
left: 0px;
top: -15px;
background-color: Lime;
}
Inline block elements will render the spacing between the tags. Check this out: http://jsfiddle.net/sznH2/4/
<button>Hello world!</button><div class="outer-relative"><div class="inner-relative"><span>XXX</span>
Remove the spaces and you're good to go
I think You Need to make pull-right postiton:relative
and outer-relative absolute
http://jsfiddle.net/tousif123/sznH2/3/
is this what are you looking for?
.pull-right {
position:relative;
}
.outer-relative {
position:absolute;
}
So I have this HTML-
<div class="title" id="questionTitle">
<input type="button" class="button green" value="Save"/>
<input type="button" class="button blue" value="Preview"/>
<input type="button" class="button yellow" value="Save And Exit"/>
<input type="button" class="button red" value="Exit Without Saving"/>
</div>
and I'm trying to position the buttons so that they will be in the center of the .title div.
My CSS is
.button{
top:50%;
left:50%;
height:30px;
-moz-border-radius:10px;
border-radius:10px;
font-family:Arial;
font-weight:normal;
position:absolute;
top:50%;
}
.title{
-moz-border-radius:15px;
border-radius:15px;
width:30%;
height:100px;
background:#BDBDBD;
}
When I do position:absolute, all the elems position at the center of the page, which to me doesn't make sense because the ancestor of each .button is a div with id questionTitle, so it should be positioned relative to that.
Why are the buttons being positioned at the center of the page, and how do I make it so that they are positioned in at the center of the div?
Position: absolute makes the attribute ditch it's container. It basically frees the element to do whatever it wants.
I did a fiddle and fixed your problem. I changes it to position: relative and centered them. Obviously since you have a ton of variance in percentages, this isn't destined to work in the first place.. this is as good as it will get.
http://jsfiddle.net/jaEpt/1/
First of all if you position an element absolute it will be absolute positioned relative to the first non static positioned element in it's ancestors and here it gets to the body ancestor and fits it to 50%/50% of the body dimensions. For reference on positioning check here: http://www.w3schools.com/cssref/pr_class_position.asp.
Place a 'position:relative' in your title css for the desired outcome. Also if you want to position the button perfectly centered then subtract half of the pixels of the button you are trying to center. You can do this by applying a negative margin of half of the button's width.
I have tested the solution as far as IE6 and it works.
As Jonathan said, you shouldn't be using position absolute as it will is not relative to the parent. Perhaps you don't need to use position at all. Just let the browser do the right thing. Use this to display the buttons vertically:
.button {
margin-left: 10%;
margin-right: 10%;
width: 80%;
}
http://jsfiddle.net/7dYAA/
If you want the buttons from left to right, leave positioning alone and just add some padding: .title { padding: 10px 10%; } and/or margins/padding to the buttons. See http://jsfiddle.net/HY8UR/
adding break tag.
<input type="button" class="button green" value="Save"/><br>
<input type="button" class="button blue" value="Preview"/><br>
<input type="button" class="button yellow" value="Save And Exit"/><br>
<input type="button" class="button red"
value="Exit Without Saving"/>
</div>
css
.button{
height:30px;
-moz-border-radius: 10px;
border-radius: 10px;
font-family: Arial;
font-weight: normal;
}
.title{
text-align: center;
-moz-border-radius: 15px;
border-radius: 15px;
width: 30%;
height: auto;
background: #BDBDBD;
}
You can use text-align: center; on the parent:
<div class="title">
<input type="button" value="Save"/>
<input type="button" value="Preview"/>
<input type="button" value="Save And Exit"/>
<input type="button" value="Exit Without Saving"/>
</div>
.title { text-align: center; border: 1px solid #090; background: #efe; padding: 20px; }
.title [type=button] { display: inline; }
http://jsfiddle.net/chovy/cDafD/1/