I want to align all my elements in the middle of my header, however it is impossible since header logo is expanding it.
Example here: http://jsfiddle.net/CPDNr/
Place image as background or set height/width to 100% in css.
use center tag in your header DIV, like this:
<div class="header">
<center>
<div class="logo">
<img src="http://html5doctor.com/wp-content/uploads/2011/01/HTML5_Logo_256.png" width="90" height ="90" />
</div>
<div class="search">
<input type="text" name="search" placeholder="Search" />
</div>
<div class="user">
</div>
</center>
</div>
<div class="header">
<div style="margin:0 auto;position:relative;display:inline-block !important;">
<div class="logo">
<img src="http://html5doctor.com/wp-content/uploads/2011/01/HTML5_Logo_256.png" width="90" height ="90" />
</div>
<div class="search">
<input type="text" name="search" placeholder="Search" />
</div>
<div class="user">
</div>
</div>
</div>
css:
.header
{
height: 60px;
width: 100%;
text-align:center;
background-color: red;
}
<style type="text/css">
.header {
background: url(http://example.com/path/to/image.jpg) no-repeat center center fixed;
}
</style>
<div class="header">
<div class="search">
<input type="text" name="search" placeholder="Search" />
</div>
<div class="user">
</div>
</div>
Also, check out this excellent tutorial on full-page background images.
This should do:
img
{
max-width:100%;
max-height:100%;
}
Related
How do we make an image "fit" inside the second column below? This is Bootstrap 4 and I want the right column to take the same height as the left column and then the image to fit inside it while keeping the aspect ratio. I also want it to be centered horizontally and vertically.
The HTML currently looks like this:
<div class="form-row">
<div class="col">
<div class="form-group">
<!-- Upload Image option -->
</div>
<div class="form-group">
<!-- Image URL option -->
</div>
</div>
<div class="col-md-4">
<img src="leg.jpg" height="70px" />
</div>
</div>
I simply don't want to specify that height="70px" attribute. The image should expand/shrink to cover the available height (dictated by the left column). Width of the image should then adjust to keep aspect ratio intact. The image should finally be centered horizontally or vertically.
By the look of the screenshot there's CSS from other classes and more HTML layout than what's provided. Here are the following styles relevant to the img with a <figure> wrapped around it.
<figure class='figure'> <img class='figure-img fluid-img'...> </figure>
img {
object-fit:contain;
max-width:100%;
height:auto
}
.col {
display:flex;
flex-flow:column nowrap;
justify-content: center;
align-items:center
}
.form-row {
max-width: 540px;
}
img {
object-fit: contain;
max-width: 100%;
height: auto
}
.column {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<main class='container'>
<section class="form-row">
<section class="column col-8">
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<div class="input-group-text">
<input type="radio">
</div>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input form-control">
<label class="custom-file-label">Choose file</label>
</div>
</div>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<div class="input-group-text">
<input type="radio">
</div>
</div>
<input type="url" class="custom-url-input form-control">
</div>
</section>
<section class="column col-4">
<figure class='figure'>
<img src="https://oehawkseye.org/wp-content/uploads/2017/01/chicken-leg.png" class='figure-img img-fluid'>
</figure>
</section>
</section>
</main>
The first image of the row doesn't have the same height as the other ones. I am using Bootstrap .img-responsive.
HTML
<div class="row">
<div class="down-content">
<div class="haber">
<!--HABER 1-->
<div class="col-sm-3">
<div id="haber1">
<div id="haberimg1">
<img class="img-responsive" src="http://www.avukatwebsite.net/public/_uploads/photos/temalar/avukat-web-site-tema-1.jpg" >
</div>
<div id="haberyazi1">
<h3>Kanser Affetmedi...</h3>
<p>Sanssiz genc Kanser yüzünden öldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
<!--HABER 2-->
<div class="col-sm-3">
<div id="haber2">
<div id="haberimg2">
<img class="img-responsive" src="http://medicare.bold-themes.com/clinic/wp-content/uploads/sites/2/2015/12/shutterstock_288977717-1200x800.jpg" >
</div>
<div id="haberyazi2">
<h3>Sizofreni Salgini</h3>
<p>Türkiyede ki Sizofren sayisinda artis görüldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
/* we deleted the other parts because of mostly code problem */
</div>
<!--HABER BÖLÜMÜ BITIS-->
</div>
</div>
Bootstrap CSS
.img-responsive,
.thumbnail > img,
.thumbnail a > img,
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
display: block;
max-width: 100%;
height: auto;
}
This is the issue:
There are a number of solutions. Here is a couple of similar solutions. First you would need to create a div that scales responsively. This can be achieved with:
.img-wrap {
height:0;
// adjust the padding to change the aspect ratio of the div
padding-bottom:60%;
}
you can then either add a background image to the .image-wrap element with background-size:cover. Or you could place an image inside .image-wrap and then position:absolute; it inside .image-wrap and add object-fit: cover; width: 100%; height: 100%;.
Answer 1:
You have to set a fixed height to the img parent div and then set height:100% to the img Check below Snippet:
.haberImg {
height: 75px;
}
.haberImg img {
height: 100%;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="down-content">
<div class="haber">
<!--HABER 1-->
<div class="col-xs-3">
<div id="haber1">
<div id="haberimg1" class="haberImg">
<img class="img-responsive" src="http://www.avukatwebsite.net/public/_uploads/photos/temalar/avukat-web-site-tema-1.jpg"></div>
<div id="haberyazi1">
<h3>Kanser Affetmedi...</h3>
<p>Sanssiz genc Kanser yüzünden öldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
<!--HABER 2-->
<div class="col-xs-3">
<div id="haber2">
<div id="haberimg2" class="haberImg">
<img class="img-responsive" src="http://medicare.bold-themes.com/clinic/wp-content/uploads/sites/2/2015/12/shutterstock_288977717-1200x800.jpg"></div>
<div id="haberyazi2">
<h3>Sizofreni Salgini</h3>
<p>Türkiyede ki Sizofren sayisinda artis görüldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
</div>
</div>
Answer 2:
You have to set a fixed height to the img parent div as the smallest img height and then add overflow:hidden. Check below Snippet:
.haberImg {
height: 80px;
overflow:hidden;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="down-content">
<div class="haber">
<!--HABER 1-->
<div class="col-xs-3">
<div id="haber1">
<div id="haberimg1" class="haberImg">
<img class="img-responsive" src="http://www.avukatwebsite.net/public/_uploads/photos/temalar/avukat-web-site-tema-1.jpg"></div>
<div id="haberyazi1">
<h3>Kanser Affetmedi...</h3>
<p>Sanssiz genc Kanser yüzünden öldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
<!--HABER 2-->
<div class="col-xs-3">
<div id="haber2">
<div id="haberimg2" class="haberImg">
<img class="img-responsive" src="http://medicare.bold-themes.com/clinic/wp-content/uploads/sites/2/2015/12/shutterstock_288977717-1200x800.jpg"></div>
<div id="haberyazi2">
<h3>Sizofreni Salgini</h3>
<p>Türkiyede ki Sizofren sayisinda artis görüldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
</div>
</div>
A simple way is to use images that have the same width and the same height! (You avoid a lot of problems and there is no need to fix something with CSS)
HTML
<div class="row">
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
</div>
Just give your images same class and add height.
Trick: avoid of giving height with pixels because getting issue in small screen instead give height with rem or
percentage
It's very easy actually, use display grid and grid-auto-columns: 1fr.
I have three div
Navbar
Banner
Content
What I want to do is make background of navbar full width, but all elements inside navbar have margin and center, also banner and content. So I add nav-topmost class to the div that contains navbar. But when I add this class. Three div is overlapped. Without this class, everything work fine but my navbar not full width.
Can anyone help me solve this issue? Thanks in advance !
Here is my code :
.nav-topmost
{
margin-bottom:20px;
padding:0;
height:50px;
background:#000;
}
.banner
{
height:100px;
background:#eee;
margin-bottom:15px;
}
.content
{
background:#bbb;
}
<link href="http://netdna.bootstrapcdn.com/bootswatch/3.0.0/united/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid nav-topmost">
<div class="container">
<div class="clearfix">
<div class="pull-right">
SET HOME
</div>
<div class="pull-right">
<input type="submit" value="Search" class="form-control"/>
</div>
<div class="pull-right">
<input type="text" class="form-control" />
</div>
</div>
<div class="banner">
BANNER
</div>
</div>
</div>
<div class="container">
<div class="content">
Some contents
</div>
</div>
I made some correction here and hope this is what you want.
I changed the structure and put .nav-topmost's div out of .container's div.
http://jsfiddle.net/amitv1093/z2eoxm4v/
---html---
<nav class="nav-topmost">
<div class="container">
<div class="pull-right">
SET HOME
</div>
<div class="pull-right">
<input type="submit" value="Search" class="form-control"/>
</div>
<div class="pull-right">
<input type="text" class="form-control" />
</div>
</div>
</nav>
<div class="container">
<div class="banner">
BANNER
</div>
</div>
</div>
<div class="container">
<div class="content">
Some contents
</div>
</div>
---css---
.nav-topmost
{
margin-bottom:20px;
padding:10px 0px;
background:#000;
}
Is this what you want:
.nav-topmost
{
position:relative;
top:0;
}
.container, .clearfix, .banner{
width:100%;
}
Here is the JSFiddle demo
remove nav-topmost class from container-fluid element and add it to the main navigation bar like this
<div class="container-fluid"> /* Remove nav-topmost */
<div class="container">
<div class="clearfix nav-topmost"> /* Add Here */
<div class="pull-right">
SET HOME
</div>
<div class="pull-right">
<input type="submit" value="Search" class="form-control"/>
</div>
<div class="pull-right">
<input type="text" class="form-control" />
</div>
</div>
<div class="banner">
BANNER
</div>
</div>
</div>
I've got a partial view that I want to have a sticky footer on. Unfortunately the scrollable div overflows with my footer no matter what I try.
<div id="wrap">
<div class="container">
<div class="scrollable">
<div class="scrollable-content">
<div class="list-group">
<a ng-repeat="msg in chatmessages" href="#" class="list-group-item">
<div class="bubble bubble-{{msg.dir}}">{{msg.text}}</div>
</a>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="container">
<form class="row row-chat">
<div class="input-group">
<input type="text" class="form-control" ng-model="messageText" placeholder="Type your message" />
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">Send</button>
</span>
</div>
</form>
</div>
</div>
Custom CSS:
#wrap {
min-height: 100%;
height: auto !important;
margin: 0 auto -60px;
}
#footer {
margin-left: -20px;
margin-right: -20px;
padding-left: 20px;
padding-right: 20px;
}
fix the footer with the specifec height like using styles
#footer
{
top:1200px;
left:300px;
}
In this bootply the welcome as well as the form is coming on the left hand side.But I want to bring it at the centre.Can any body please tell me how to do?
<form id="form1">
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span10" style="margin-bottom: 6px; margin-top: 0px; background: #efeee9">
<img src="ui_resources/img/ title.jpg" alt="" align="left">
<h2 align="center" style="margin-top: 18px;"></h2>
</div>
<div class="span1"></div>
</div>
<div class="row-fluid">
<div class="span1"></div>
<div class="span10" style="background: #eee; border: 1px solid #ddd;">
<div class="span7 center login-header">
<h2 style="color:#E86537 " align="center">Welcome </h2>
</div><!--/span-->
<div class="row-fluid">
<div class="well span7 center login-box">
<div class="alert alert-info">
Please login with your Username and Password.
</div>
<fieldset>
<div class="input-prepend" title="Username" data-rel="tooltip" style="margin-left:80px;">
<span class="add-on"><i class="icon-user"></i></span><input autofocus="" class="input-large span10" name="j_username" id="username" type="text" value="">
</div>
<div class="clearfix"></div>
<div class="input-prepend" title="Password" data-rel="tooltip" style="margin-left:80px;">
<span class="add-on"><i class="icon-lock"></i></span><input class="input-large span10" name="j_password" id="password" type="password" value="">
</div>
<div class="clearfix"></div>
<div class="input-prepend" style="margin-left:80px;">
<label class="remember" for="remember"><input type="checkbox" id="remember" style="display:">Remember me</label>
</div>
<div class="clearfix"></div>
<p class="center span6" style="margin-left:80px;">
<button type="submit" class="btn btn-primary">Login</button>
New Userregister
</p>
</fieldset>
</div><!--/span-->
</div><!--/row-->
</div><!--/row-->
</div>
<div class="span1"></div>
</div></form>
<div class="row-fluid">
<div class="span1"></div>
<div class="span10" style="margin-top: 6px;">
<div class="span1"></div>
</div>
</div>
try to set your welcome div in another div like this
<div class="row-fluid">
<div class="offset3 span6 center login-header">
<h2 style="color:#E86537 " align="center">Welcome </h2>
</div>
</div>
use offset
Move columns to the right using .offset* classes. Each class increases
the left margin of a column by a whole column. For example, .offset4
moves .span4 over four columns.
DEMO
Try using this in your CSS
.row-fluid .login-header,
.row-fluid .login-box{
float:none;
margin:0 auto !important;
}
Since .span* has float: left style by default, you can override it by using float:none;
.login-box {
margin:0 auto;
float:none;
}
margin:0 auto; is used to center your loginbox horizontally.