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/
Related
I would like my "Search by Name" #left div to extend the entire red area:
#main {
border: 1px solid black;
font-size: 20px;
font-weight: bold;
color: white;
}
#left {
width: 100%;
background-color: red;
}
#center {
float: right;
width: 230px;
background-color: blue;
}
#right {
float: right;
width: 45px;
background-color: green;
}
<div id="main">
<div id="right">
<button name="button" type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
</div>
<div id="center">
<div class="dropdown bootstrap-select show-tick select-picker navbar-margins">
<select name="tag_id[]" id="tag_id_" class="select-picker navbar-margins" data-actions-box="true" data-selected-text-format="count > 1" data-title="No Tags Selected" data-deselect-all-text="Select None" multiple="multiple" tabindex="-98"></select>
</div>
</div>
<div id="left">
<input type="text" name="q" id="q" placeholder="Search by Name or Contact Info">
</div>
</div>
When I add the following to span my #q div then the element gets bumped down:
css:
#left #q {
width: 100%;
}
Stop using floats and use flex instead:
#main {
border: 1px solid black;
font-size: 20px;
font-weight: bold;
color: white;
display: flex; /* use this instead of floats */
}
#left {
flex-grow: 1; /* make this grow to fill remaining space */
}
#left input {
width:100%; /* optional - make the input fill the div */
}
#center {
width: 230px;
background-color: blue;
}
#right {
width: 45px;
background-color: green;
}
<div id="main">
<div id="left">
<input type="text" name="q" id="q" placeholder="Search by Name or Contact Info">
</div>
<div id="center">
<div class="dropdown bootstrap-select show-tick select-picker navbar-margins">
<select name="tag_id[]" id="tag_id_" class="select-picker navbar-margins" data-actions-box="true" data-selected-text-format="count > 1" data-title="No Tags Selected" data-deselect-all-text="Select None" multiple="multiple" tabindex="-98"></select>
</div>
</div>
<div id="right">
<button name="button" type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
What has happened here is you have told the input inside left to be 100% of the red container, however the red container stretches all the way across the screen.
Then when you tell the input to also be 100% it hits into the other containers and drops down.
You could probably get this idea working by setting it to 85% instead of 100% but you will hit into issues every time you resize things.
A better way might be to look into a css property called flex. This allows you to do what you without having to set fixed values.
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.
So I am trying to make this admin page responsive and there are some problems when I resize the page. I want the div with the Inventory to be aligned with the 3 buttons.
This is my container which needs to properly adapt when resizing the viewport.
.reports{
border: 1px solid red;
overflow-y: scroll;
/*overflow-x: hidden; */
height: 100%;
}
.row{
height: 4.5em;
width: 100%;
margin-left: 0;
}
.actions{
float: right;
width: 30%;
}
.entry-group{
border: 1px solid red;
float: left;
width: 70%;
}
.title{
border: 1px solid red;
float: right;
width: 72.5%;
height: 3.7em;
word-wrap: break-word;
margin-left: 2em;
}
<div class="reports">
<div class="list-group-item row">
<div class="entry-group">
<button class="btn btn-primary date" >2016-09-19</button>
<div class="title">
<h4 class="list-group-item-heading">2080136 - Inventory</h4>
<p class="list-group-item-text">2 Napier Court West Southend On Sea SS1 1JU</p>
</div>
</div>
<div class="actions">
<button class="btn btn-primary download">Download</button>
<button class="btn btn-primary edit">Edit</button>
</div>
</div>
</div>
I think there is a few issues with the code here. Firstly, I believe it odd to have DIVs between your 'tr' and td', and not having a 'table' element.
I think you are trying to mix different ways of doing things: bootstrap and HTML tables.
My suggestion is use something like layoutit.com to build a layout with divs only in bootstrap. You can easily still integrate it into your back end technology, and get the divs responsive by editing the class names, e.g. col-sm-1.
I understand that you want to use tables for reports, having said that, it should be carried through completely, without divs inbetween.
Add this:
.list-group-item-heading {
margin-top: 0;
}
https://jsfiddle.net/kefhvc7y/
Add:
.title h4 {
margin-top: 0px;
}
.date {
float: left;
}
and remove margin-left: 2em; from .title.
Here is an updated version of your fiddle: https://jsfiddle.net/r11p5n4d/
I'm trying to create a chat area. It'll display the messages on top and the input on the bottom. I want to keep the "esc" button and "send" button the same width, but increase the textarea to maximum width while keeping all three elements inline. This is what I've tried so far.
<div class="col-sm-8">
<div id="chatArea">
</div>
<form class="form-inline" role="form" id="userInput">
<button id="endChat" type="button" class="btn btn-danger">Esc</button>
<div class="form-group">
<textarea class="form-control" rows="5" id="messageArea"></textarea>
</div>
<button id="sendMessage" type="submit" class="btn btn-info">Send</button>
</form>
</div>
and the css
#chatArea {
height: 500px;
background-color: black;
}
#messageArea {
width: 322px;
}
#endChat, #sendMessage {
width: 70px;
height: 110px;
}
But this is the result (didn't show the full chatArea div, only the bottom).
So how can we make it so the textArea resizes itself to be of maximum width while the 3 elements (esc, textArea, and send) are inline.
HTML:
<form role="form" id="userInput">
<button id="endChat" type="button" class="btn btn-danger">Esc</button>
<button id="sendMessage" type="submit" class="btn btn-info">Send</button>
<div class="form-group">
<textarea class="form-control" rows="5" id="messageArea"></textarea>
</div>
</form>
Note the order of #endChat, #sendMessage and .form-group elements.
CSS:
#endChat {
float: left;
}
#sendMessage {
float: right;
}
.form-group {
overflow: hidden;
}
#messageArea {
width: 100%;
}
#endChat, #sendMessage {
height: 110px;
}
When using bootstrap I suggest to try formatting the bootstrap classes in css. Often the bootstrap formatting overrides your own css file unless you override them in your own css-file. Try this:
#endChat {
float: left;
}
#sendMessage {
float: right;
}
.form-group {
overflow: hidden;
display: block;
}
.form-control#messageArea{
width: 100%;
}
#endChat, #sendMessage {
height: 110px;
}
remove following code from your css:
#messageArea {
width: 322px;
}
form-control class of textarea will auto resize its width to 100% of the area.
Putting two divs on the same line is an old question. But I can't find a solution when working with simple_form in rails. What I want to do is to display content and its label on the same line. The width of the label is 125px (.left) and the content is on the right (.right). The text in the label is aligned to the right and the text in content is aligned to the left.
Here is the HTML:
<form id="new_production" class="simple_form new_production" novalidate="novalidate" method="post" action="/projects/1/productions" accept-charset="UTF-8">
<div style="margin:0;padding:0;display:inline">
<input type="hidden" value="✓" name="utf8">
<input type="hidden" value="2UQCUU+tKiKKtEiDtLLNeDrfBDoHTUmz5Sl9+JRVjALat3hFM=" name="authenticity_token">
</div>
<div class="left">Proj Name:</div>
<div class="right">must have a name</div>
<div class="input string required">
Here is the CSS:
.simple_form div.left {
float: left;
width: 125px;
text-align: right;
margin: 2px 10px;
display: inline;
}
.simple_form div.right {
float: left;
text-align: left;
margin: 2px 10px;
display: inline;
}
However, in the result, there is a linebreak, like so:
Proj Name:
must have a name
The erb code of the simple form is:
<div class="left">Proj Name:</div><div class="right"><%= #project.name %></div>
I don't want to use a table but CSS only to solve the issue.
Your css is fine, but I think it's not applying on divs. Just write simple class name and then try.
You can check it at Jsfiddle.
.left {
float: left;
width: 125px;
text-align: right;
margin: 2px 10px;
display: inline;
}
.right {
float: left;
text-align: left;
margin: 2px 10px;
display: inline;
}
You can't float or set the width of an inline element. Remove display: inline; from both classes and your markup should present fine.
EDIT: You can set the width, but it will cause the element to be rendered as a block.
why not use flexbox ? so wrap them into another div like that
.flexContainer {
margin: 2px 10px;
display: flex;
}
.left {
flex-basis : 30%;
}
.right {
flex-basis : 30%;
}
<form id="new_production" class="simple_form new_production" novalidate="novalidate" method="post" action="/projects/1/productions" accept-charset="UTF-8">
<div style="margin:0;padding:0;display:inline">
<input type="hidden" value="✓" name="utf8">
<input type="hidden" value="2UQCUU+tKiKKtEiDtLLNeDrfBDoHTUmz5Sl9+JRVjALat3hFM=" name="authenticity_token">
</div>
<div class="flexContainer">
<div class="left">Proj Name:</div>
<div class="right">must have a name</div>
</div>
<div class="input string required"> </div>
</form>
feel free to play with flex-basis percentage to get more customized space.