I'm trying to figure out how to place my <h4> tag and <button tag to be side by side.
Current Behaviour - Right now they are underneath my image and I want them to put in a horizontal position.
Required Behaviour - I want the <h4> to be side by side with the image and the <button> side by side with the <h4>.
I tried floating to the right and display blocks, but the elements are still underneath the image and one another.
Codepen Link
Browsers by default typically display header elements as block. Use inline-block to not have it be in it's own line.
HTML
<h4>title</h4>
<button>button</button>
CSS
h4 {
display: inline-block;
}
DEMO: http://codepen.io/anon/pen/bVPXOK
Maybe
<h4 style="display:inline-block;">
heading
</h4>
<button> submit </button>
?
I saw your codepan the real problem was that your button was outside the right div that is why it was not aligned next to <h4>. I have edited the code (Updated Working Codepan)-
Modified CODE
<div class=" panel-body">
<div class="row-fluid">
<div class="row-fluid">
<img class="hotel-img img-responsive img-rounded" src="http://en.hotel-palaciodelmar.com/static/galerias/hotel/01-hotel-santander-sercotel-palacio-del-mar-fachada-foto.jpg" />
<h4 class="hotel-title""><span class="hotel-location"></span> Grand Master Flex</h4>
<button class="btn btn-primary" type="button" href="#more-info" data-toggle="modal"><i class="fa fa-info-circle"></i> More info</button>
</div>
</div>
</div>
instead of this (your previous code) -
<div class=" panel-body">
<div class="row-fluid">
<div class="row-fluid">
<img class="hotel-img img-responsive img-rounded" src="http://en.hotel-palaciodelmar.com/static/galerias/hotel/01-hotel-santander-sercotel-palacio-del-mar-fachada-foto.jpg" />
<h4 class="hotel-title""><span class="hotel-location"></span> Grand Master Flex</h4>
</div>
<button class="btn btn-primary" type="button" href="#more-info" data-toggle="modal"><i class="fa fa-info-circle"></i> More info</button>
</div>
</div>
and to align both <h4> and <Button> next to image you have to change your css and add display: inline-block !important; like this (Updated Codepan with image alignment) -
CSS
/* Hotel Search Panel */
.hotel-img {
display: inline-block !important;
width: 250px;
}
Another option you can use is the "float-right" class. If you nest your button in the h4, it can be accomplished like so:
<h4>Title<button class="float-right">My Button</button></h4>
Hope that helps!
Related
I have the following problem in html: Cannot move the add button to the side. I have tried inserting the words within the div of the button or removing the br/ in the button div. It doesnt work. I know this seems to be a stupid question to all the pros out here but im seriously stuck
<h4>More details: </h4>
<div class="col-md-1">
<div class="form-group">
<div class="text-sm-center">
<button type="button" class="btn btn-outline-success btn-rounded" id="addrow"><i class="dripicons-plus"></i></button>
</div>
</div>
</div>
If I understand correctly, you want the <h4>More details:</h4> element to be side-by-side with the + button in a row format. Since <h1>-<h6> and <div> tags are block-level the only way to have your h4 in the same row as the nested <button> is to manipulate the amount of space each element occupies, ie change their layout with CSS.
A Block-level element occupies the entire horizontal space of its parent element (container), and vertical space equal to the height of its contents, thereby creating a "block".
To make the <h4> and the + button right next to eachother, you could use CSS Flexbox and nest your HTML in a parent container <div class="row">.
.row {
display: flex;
align-items: center;
}
.row .btn {
margin-left: 10px;
}
<div class="row">
<h4 class="details-heading">More details: </h4>
<div class="col-md-1">
<div class="form-group">
<div class="text-sm-center">
<button type="button" class="btn btn-outline-success btn-rounded" id="addrow">+<i class="dripicons-plus"></i></button>
</div>
</div>
</div>
</div>
In this case you can just use CSS. You need all three of the parent DIV elements to have zero px for border-left, margin-left and padding-left.
Try adding another class to each, like:
<h4>More details: </h4>
<div class="col-md-1 left-side">
<div class="form-group left-side">
<div class="text-sm-center left-side">
<button type="button" class="btn btn-outline-success btn-rounded" id="addrow"><i class="dripicons-plus"></i></button>
</div>
</div>
</div>
CSS
.left-side {
margin-left: 0px;
border-left: 0px;
padding-left: 0px;
}
Some prefer 0 to 0px.
The reason to use another class, i.e. left-side is to avoid messing with any other elements elsewhere of the existing classes.
This method/answer is a bit of a hack; more elegant solutions will be out there.
I have a bootstrap row containing a header tag and a link tag. They are aligned on the same row when the screen width is less than 768 pixels. When the container width is 768 or greater the link element shifts a few pixels higher.
Here is an example that demonstrates this behaviour: https://jsfiddle.net/bz3399x8/
<div class="row">
<div class="col-sm-12">
<a class="btn btn-primary" href="#" style="width: 80px; float: right;">
<i class="icon-plus">
Add
</i>
</a>
<h1>
Hello World
</h1>
</div>
</div>
Here are screenshots demonstrating this behaviour.
There are two issues:
what is causing this?
how to i fix this?
your syntax according to Bootstrap Docs is wrong,
it needs the .container to wrap .row
and
h1 and a button elements needs to be wrapped in Bootstrap columns.
So, you can use .col-sm-10 + .col-sm-2 in this case.
Added .col-xs for demo
.row {
/* demo*/
background:red
}
.btn {
margin-top:20px /* choose as it fit you better */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-10 col-sm-10">
<h1>
Hello World
</h1>
</div>
<div class="col-xs-2 col-sm-2">
<a class="btn btn-primary" href="#">
<i class="icon-plus">
Add
</i>
</a>
</div>
</div>
</div>
While wrapping elements in different column will help answer your problem. If you are looking at wrapping both elements inside single column you need to specify elements to be inline. Problem is occurring since h1 element and a element even though in same row for bootstrap but are displayed as block and inline-block.
Add display: inline-block to h1 element with top padding to a element. This should answer it as well.
Try it with display: inline on h1 see the difference in behavior. inline element dont support vertical margins.
Fiddle: https://jsfiddle.net/dk_dragonknight/m8ey6mba/
I have one silly question about Bootstrap Grid System.
Is that okay to use <a href="#" class="col-lg-4"> instead of <div class="col-lg-4">?
Is it because I want create a column-4 grid menu with hyperlink.
Basically, it should look like this which the hyperlink only cover the text not the whole column even if I had styled width: 100%; height: 100%; inside the <a> tag.
<div class="row">
<div class="col-lg-4">
Menu 1
</div>
</div>
After I change the code, it should look like
<div class="row">
<a href="#" class="col-lg-4">
Menu 1
</a>
</div>
Is this a best practice of using Bootstrap?
Or we have to follow the standard which define by Bootstrap?
do it like this and it will be looking great:
just add a class or style to your a element.
or add class "btn btn-default btn-block" to use bootstrap button styles
<div class="row">
<div class="col-lg-4 text-center">
<a href="#" class=" btn-block">
Menu 1
</a>
</div>
</div>
The only problem I see with that is that the A won't have the css property display: block; by default so you might run into styling issues. If you fix this issue by adding this property, I can see any problem with that.
I have the next code:
<div class="container-fluid">
<img src="images/w2.png" alt="W logo" class="center-block visible-xs-block visible-sm-inline-block visible-md-inline-block visible-lg-inline-block">
<h2 class="center-block visible-xs-block visible-sm-inline-block visible-md-inline-block visible-lg-inline-block">This is h2 header</h2>
<div class="hidden-xs visible-sm-inline-block visible-md-inline-block visible-lg-inline-block pull-right">
<div class="row">
<img src="images/user.png" alt="User image" class="col-sm-3 img-circle">
<span class="col-sm-9">Non register user</span>
</div>
<div class="row">
<button type="button" class="btn btn default btn-large col-sm-6">Log in</button>
<button type="button" class="btn btn default btn-large col-sm-6">Register</button>
</div>
</div>
</div>
The above code just show a div which have inside it a image with 50x50px and a h2 and another floated div by the .pull-right class. My problem appear when the viewport size come to set more than extra-small size (xs); the floated div disappear in xs size (at this point everything works well) but later when the viewport come to be small (sm) or higher, the floated div appear in another line: just below from the img and h2.
How can I solve this? thank you.
Edit the question above:
The behavior which I'm looking for is that the div.hidden-xs appear only when the viewport have more size than extra-small size (xs) and also that it appear horizontally aligned to the right (right float) at the same line of img and h2.
Thank you
if <div class="hidden-xs visible-sm-inline-block visible-md-inline-block visible-lg-inline-block pull-right"> is troubling you, that is because you only put class hidden-xs. Because that class means only hidden if viewport is xs. On the other hand, you put visible-sm-inline-block and visible-md-inline-block, so of course that div appear below the img and h2.
reference: bootstrap
Why don't you try
<div class="hidden-xs pull-right">
EDIT:
reference: learnlayout
I think I've got the wrong concept before, sorry. I think your <img> and <h2> not inside the <div> with class visible-*-*.
This is my code: http://www.bootply.com/Tm5C3Ja7RL
<div class="col-md-12">
<h3>Test</h3><button class="btn btn-default pull-right">Button</button>
</div>
It drops the button onto a second line as well as aligning it to the right. I only want to push it to the right. Can anyone show me the best way of doing this.
As EWit mentioned, a header is a block element.
This block will push down other elements behind it.
There are several solutions, one better/cleaner than the other
Changing the header to an inline element
h3 {
display:inline;
}
This will result in your title with the button right next to it.
I don't think the pull-right will have an effect on it. Should be tested.
You could also add the condition that the h3 must have a certain class or must be inside an element with a certain class.
Splitting the column in 2
<div class="col-md-10">
<h3>Test</h3>
</div>
<div class="col-md-2">
<button class="btn btn-default pull-right">Button</button>
</div>
By also using col-sm, for example, you could alter this so that the button is displayed next to the title in a medium/large screen and under it in a small screen.
However, the pull-right might make it look pretty weird then.
<div class="col-md-10 cold-sm-12">
<h3>Test</h3>
</div>
<div class="col-md-2 col-sm-12">
<button class="btn btn-default pull-right">Button</button>
</div>
Put the button in the h3-element
As EWit mentioned, you can also put the button inside the h3-element.
This will keep the button in the same line, but might alter the text formatting.
<div class="col-md-10">
<h3>Test <button class="btn btn-default pull-right">Button</button></h3>
</div>
Put it inside the <h3>. Headers in HTML take up the full width as a block object. As such other objects are pushed down.
Try:
<div class="col-md-12">
<h3>Test <button class="btn btn-default pull-right">Button</button></h3>
</div>
I myself extend it with some markup for basic links but to align it to the same height as the text in the header.
h1 .pull-right {
padding: 15px 5px 0 0;
}
But I have no idea what values would be best for a button to align it. Trial and error I guess.