Into a page I have the following
<div id="submitEventButtonDiv">
<div id="wwctrl_backButton" align="right">
<input id="backButton" type="submit" onclick="return clickSubmitButton();" value="Back">
</div>
<div id="wwctrl_submitEventButton" align="right">
<input id="submitEventButton" type="submit" onclick="return clickSubmitButton();" value="Submit">
</div>
</div>
As you can see there is an external div having id="submitEventButtonDiv" that contains 2 divs containing in turn 2 input fields.
Obviously when the 2 input field are displayed appear one below the other (because they are contained into a div that is block element).
How can I display one beside the other? (I can't delete the div that contains each input field because it is automatically rendered by a tag library that I am using, this that I have post is the rendered HTML obtained from a page that us Struts 2 tag library that wrap HTML following its logic, so in this case I can only work on CSS to do it)
Tnx
Just display the child elements inline.
#submitEventButtonDiv > div {
display:inline;
}
codepen here http://codepen.io/anon/pen/jEmaed
Depending on your cross browser needs, use flexbox:
#submitEventButtonDiv {
display: flex;
}
Will make all of the children flex items, which by default, stack horizontally, like you want.
If you float them both they'll be positioned next to each other. Adding
#submitEventButtonDiv > div {
float:left;
display:inline;
}
To your css should position them both to the left of the page next to eachother.
If the inner div IDs are always same, then you can add the following styles in your css:
div#wwctrl_backButton {
display: inline-block;
width: 50%;
}
div#wwctrl_submitEventButton{
display: inline-block;
width: 50%;
}
This generates the desired effect.
#submitEventButtonDiv > div {
display:inline;
float:right;
}
Related
I'm trying to position two HTML elements with the CSS attribute float: right;, an input element next to it the metric unit of the input. So far I've tried placing the unit next to input without placing it in an element, also placing it in a p element, and both input and the element inside a div element; didn't work. I'd like to ask whether there's a way to stick an element next to another?
here's the code:
.caloriesinput {
position: relative;
float: right;
}
<div>
<h5>Calories</h5>
<div class="caloriesinput"><input type="text">
<p>kcal</p>
</div>
</div>
and here's how the code shows:
much appreciated for your time.
I think you must change the display of p tag so add this line of code to your CSS:
.caloriesinput p {
display: inline-block;
}
.caloriesinput {
position: relative;
float: right;
}
<div>
<h5>Calories</h5>
<div class="caloriesinput"><input type="text"<p>kcal</p>
</div>
</div>
I have design this box with angular material. I can not break these two words in two line(up and down).i have included a image. Here i want 1349 and New Feedback in two line. I am new in angular material. thanks
<style>
.box-item {
background-color: cornflowerblue;
width: 100px;
height: 120px;
}
.box-text {
color:white;
}
</style>
<div layout="row" style="padding: 32px;" ng-cloak>
<md-whiteframe class="md-whiteframe-2dp box-item" md-colors="[enter image description here][1]background:'blue-400'}"
flex-sm="45" flex-gt-sm="35" flex-gt-md="25" layout
layout-align="end center" layout-margin>
<span class="md-display-1 box-text">1349</span>
<span class="box-text">New Feedbacks</span>
</md-whiteframe>
</div>
That is a css question.
You want to order 2 inline elements (span) in 2 lines.
You should try to style one of them as block element or to add br tag between them.
<style>
.box-item {
display: inline-block;
background-color: cornflowerblue;
height: 120px;
}
.box-text {
color:white;
display: block;
}
</style>
Example Here
That's because the <span> tag is an inline element by default and only takes up as much width as necessary.
If you need to use a span and require the item's on separate lines then either change the behaviour of the element through CSS by changing it's display property to block as stated by Cuzi, add a single line break between the elements using the <br> tag or use a block-level element such as the <div> tag.
I recommend using the right element for the job. So a block-level tag like the <div> tag would be ideal. This would cause both elements to take up the full width available and thus be on separate lines without the requirement for an extra line of css, (plus you save a byte of space per element within the HTML!
Heres how to do it in CSS.
.box-text {
color:white;
display: block;
}
Heres with a <br> tag:
<span class="md-display-1 box-text">1349</span>
<br>
<span class="box-text">New Feedbacks</span>
And the simplest and most semantic of the three, with div tags:
<div class="md-display-1 box-text">1349</div>
<div class="box-text">New Feedbacks</div>
Image
I tried this with the following CSS and HTML. It looks fine when the browser is of full width and scrambled when browser is resized. I WANT the elements to be where there and a HORIZONTAL SCROLL has to appear when the BROWSER is RESIZED. Pretty new to web programming. Text-align:center for positioning the center column would not work because, every time a new text is added in the left or right, it gets relocated and also center column element in ROW1(text) and ROW2(Button) do not appear along the same line. That is, text appears a bit right and the button a bit left. Text-align won't work here.
CSS:
#charset "utf-8";
/* CSS Document */
body
{
background-color:#000;
}
.wrapper
{
width:70%;
margin:0 auto;
padding:2px;
background-color:#fff;
}
.second_row
{
padding:2px;
margin-top:10px;
}
.center_container
{
width:30%;
margin:0 auto;
}
.left_container
{
width:33%;
float:left;
}
.right_container
{
width:33%;
float:right;
}
.topelements
{
margin-top:0px;
color:#777;
padding:2px;
}
.topelements a:link
{
color:#29a3cc;
}
.topelements a:active a:hover
{
color:#29a3cc;
}
.logo
{
overflow:hidden;
}
HTML code:
<div class="wrapper">
<span class="topelements float_left" >Mail us: admin#admin.com</span>
<span class="topelements float_right">Left links My xyz</span>
<span class="topelements center_container">Welcome to xyz ! Sign in or Signup.</span>
</div>
<div class="wrapper second_row">
<span class="left_container">Srini</span>
<span class="right_container">Vas</span>
<form class="center_container">
<input type="text" placeholder="Goooooooooooo!" />
<input type="submit" value="Search" />
</form>
</div>
<div class="wrapper">
If you want to align you object in the center, there are a couple of different ways. First of all, there is the text-align:center; which you don't need right now. There is also object-position:center; which basically does the same, but with an object. This way isn't the best, but you could add a certain percentage of padding to either side but that's not recommended. Lastly, there's alignment-adjust:central;. This may not be perfect for your situation but just try out all of these and see if they work. Good luck!
One way that would work is to set your wrapper width to a fixed value (something in 800px for example). As long as this width was longer than all the content you are putting within that wrapper, everything should work as you want. The browser will automatically place a horizontal scroll bar when the window gets smaller than the width of the wrapper.
This is just a small error I found in the CSS and I don't know if this will help too much. The div you added was not referred to as a div, but a class. For example, if you wanted to style a div in CSS, you would do this:
#divname {
CSS for div goes here...
}
On the other hand, if you wanted to add a little style to a class, you would go like this:
.classname {
CSS for class goes here...
}
If you were wondering what the difference for each is, the answer is simple. A class can define multiple objects while the divs are just limited to one object or element.
I am trying to make the two elements in the header, the pink section and the green section, be inline ( in one line and not wrapping to a new line as the green section is currently).
However, I can't use display:inline; as the items need to have a width.
How can I achieve both of these elements being inline and keep their widths?
Here is the page where the elements are: https://dl.dropboxusercontent.com/u/270523/help/new.html
The inline-block solution:
#logo {
width: [WIDTH1]%;
min-width: 225px;
background: pink;
}
#input{
width: [WIDTH2]%;
background: green;
}
#input,#logo {
display: inline-block;
height: 100%;
vertical-align:top;
}
Where [WIDTH1] + [WIDTH2] = 100%.
For this to work, you need to delete the whitespaces between the two elements.
So not like now:
<section id="logo"></section>
<section id="input">
<input id="searchInput" type="text" name="search" autocomplete="off">
</section>
But instead:
<section id="logo"></section><section id="input">
<input id="searchInput" type="text" name="search" autocomplete="off">
</section>
You've set the float to the #input section but not the #logo section.
#logo {
width:20%;
float: left;
}
Your section input is dropping because it is having extra width, make it around 77% then it will work for you.
#input{width:77%;}
first of all it is really nice You use html5 tags its good for You. In my opinion the easiest way is use a float for all of elements in header, but remember to clear:both parent tag.
Here is demo of modified your code: http://jsfiddle.net/bartekbielawa/WgtAP/
I have the following HTML code and I want to make my form aligned in center.
<form action="advsearcher.php" method="get">
Search this website:<input align="center" type="text" name="search" />
<input type="submit" value="Search"/>
</form>
How can I do that?
#Lucius and #zyrolasting have it right.
However, you will probably need to give the form a specified width for it to work properly.
form {
margin: 0 auto;
width:250px;
}
Just put some CSS into the stylesheet like this
form {
text-align: center;
}
then you're done!
Being form a block element, you can center-align it by setting its side margins to auto:
form { margin: 0 auto; }
EDIT:
As #moomoochoo correctly pointed out, this rule will only work if the block element (your form, in this case) has been assigned a specific width.
Also, this 'trick' will not work for floating elements.
This will have the field take 50% of the width and be centered and resized properly
{
width: 50%;
margin-left : 25%
}
May also use "vw" (view width) units instead of "%"
Use center:
<center><form></form></center>
This is just one method, though it's not advised.
Ancient Edit: Please do not do this. I am just saying it is a thing that exists.
Just move align="center" to the form tag.
<form align="center" action="advsearcher.php" method="get">
Search this website:<input type="text" name="search" />
<input type="submit" value="Search"/>
</form>
The last two lines are important to align in center:
.f01 {
background-color: rgb(16, 216, 252);
padding: 100px;
text-align: left;
margin: auto;
display: table;
}
#form{
position:fixed;
top:50%;
left:50%;
width:250px;
}
You can adjust top & left depending on form size.
Try this :
Set the width of the form as 20% by:
width : 20%;
now if the entire canvas is 100 %, the centre is at 50%. So to align the centre of the form at the centre, 50-(20/2) = 40.
therefore set your left margin as 40% by doing this :
left : 40%;
simple way:Add a "center" tag before the form tag
<center><form></form></center>
does work in most cases like The Wobbuffet mentioned above...