How to reduce the size of div in bootstrap? - html

I used bootstrap grid to set the size of the div, but I want the div to be a little bit less wide.
Here is my code
.single-box {
background: black
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<div class="col-md-3 ml-5">
<div class="single-box">
<p class="ml-5">1 марта, 18:00</p>
<h4 class="ml-5">Hi</h4>
<p class="ml-5">My name is..</p>
<button type="button" class="btn mx-auto btn-light gotham">Write to me</button>
</div>
</div>
Is there a way to reduce the width by bootstrap tools? Or the only way out is to forget about bootstrap grid and set the parametrs by myself?

You can set a margin like so:
.single-box {
background: green;
margin: 0 50px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<div class="col-md-3 ml-5">
<div class="single-box">
<p class="ml-5">1 марта, 18:00</p>
<h4 class="ml-5">Hi</h4>
<p class="ml-5">My name is..</p>
<button type="button" class="btn mx-auto btn-light gotham">Write to me</button>
</div>
</div>

You can use Bootstrap utility classes
w-25 for 25% width
w-50 for 50% width
w-75 for 75% width
w-100 for 100% width
If you want to have a div 25% less wider you can use it as below:
<div class="w-75">
<h1>Hello World</h1>
</div>
<!-- Next div 100% or even you don't need to add w-100 class -->
<div class="w-100">
<h1>Hello World</h1>
</div>

Related

Vertically Align Text within Bootstrap Button [duplicate]

This question already has answers here:
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 9 months ago.
I could use a hand vertically aligning text within a Bootstrap button.
If I use the class the text is vertically aligned like I want, but if I use the class the text is top-aligned and nothing I do seems to change it. Any ideas?
Screenshot of the buttons:
/* added by editor for demo purpose */
button {
min-height: 80vh;
}
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="d-flex justify-content-between px-1 py-1 vh-100 align-middle">
<a href="#link" class="btn btn-outline-primary btn-lg w-50 align-middle" type="submit">
<h1>Header 1</h1>
<p>This is text.</p>
</a>
<button class="btn btn-outline-primary btn-lg w-50 align-middle" type="submit">
<h1>Header 2</h1>
<p>This is more text.</p>
</button>
</div>
The issue is that an <a>nchor remains an inline-element in Bootstrap. As such it has a line-height to which it centers. You can solve this with flexbox by adding d-flex flex-column justify-content-center
/* added by editor for demo purpose */
button {
min-height: 80vh;
}
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="d-flex justify-content-between px-1 py-1 vh-100 align-middle">
<a href="#link" class="d-flex flex-column justify-content-center btn btn-outline-primary btn-lg w-50 align-middle" type="submit">
<h1>Header 1</h1>
<p>This is text.</p>
</a>
<button class="btn btn-outline-primary btn-lg w-50 align-middle" type="submit">
<h1>Header 2</h1>
<p>This is more text.</p>
</button>
</div>

Bootstrap div not placing as expected

I have a 'right-float' classed div placed inside a 'w-100' classed div. Inside the right-floated div I want to display at the top a button with 3 points inside (...) and at the bottom another Icon (see images below). So I added 'h-100' class to the float-right div and created two divs inside it: the first one with the ... button inside and the second one with 'align-bottom' class.
Problemthe second div does not stay at the bottom, I think because h-100 is not working as expected
Observed behaviour
Expected behaviour
HTML Tree
Example snippet
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<div class="clearfix w-100 border border-primary">
<div class="float-right h-100">
<div class="clearfix">
<div class="float-right">
<button class="btn btn-sm btn-primary">...</button>
</div>
</div>
<div class="align-bottom clearfix">
<div class="float-right">
<button class="btn btn-sm btn-primary">BTN2</button>
</div>
</div>
</div>
<div>
<div>FOO</div>
<div>FOO2</div>
<div>FOO3</div>
</div>
</div>
</body>
</html>
h-100 is working as expected, because the height is 100% of the childs inside. It is not usable to stretch a div to its parent height.
You could use flex, to make it work right
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<div class="d-flex align-items-stretch border border-primary">
<div class="flex-grow-1">
<div>FOO</div>
<div>FOO2</div>
<div>FOO3</div>
</div>
<div class="d-flex flex-column bg-danger">
<div class="flex-grow-1">
<button class="btn btn-sm">...</button>
</div>
<div>
<button class="btn btn-sm">BTN2</button>
</div>
</div>
</div>
</body>
</html>

How to resize bootstrap button without a side-scroll

I am very new to CSS responsive layouts and need help structuring my navbar. I am aware that there are many other similar SO Q&As, but none of them give me the desired output.
I tried using the suggestion from this SO question, but instead of the buttons resizing, a scrollable scrollbar appears upon window resize which is not what I want.
Here's what my HTML code looks like at the moment:
.nowrap{white-space: nowrap;}
.column2 {
float: left;
width: 33%;
text-align: center;
overflow:auto;
}
.column3 {
float: center;
width: 33%;
text-align: right;
}
.column4 {
float: right;
width: 33%;
text-align: right;
overflow:auto;
}
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.6.3/css/all.css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel='stylesheet' href='https://bootswatch.com/4/united/bootstrap.min.css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<div class="row">
<div class="container">
<div class="column2"><h4 >Welcome back <span>Example</span></h4></div>
<div class="column3">
<h1 style="font-size:2.5vw;" title='About'>Example<span class="text-primary">TEXT</span>Example</h1>
</div>
<div class="column4" >
<div class="col-md-6 col-md-offset-3 responsive nowrap">
<button type="button" class="btn btn-danger btn-responsive">Search</button>
<button type="button" class="btn btn-primary btn-responsive" id="logoutButton " >Logout</button>
<button type="button" class="btn btn-primary btn-responsive" data-toggle="modal" data-target="#loginModal" >Login</button>
</div>
</div>
</div>
</nav>
Summary of button requirements:
The three buttons in the same row
Buttons responsively get smaller without the need to scroll.
The content in the three <div> tags don't overlap
Please do take into consideration that I am very new to CSS styling and so would appreciate all the constructive feedback!
You can use bootstrap 3 classes. Is that close to what you try to achieve?
(Edit snippet per comments:)
.nowrap{white-space: nowrap;}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar navbar-default">
<div class="container">
<div class="row">
<div class="col-xs-3 col-sm-4 text-left"><h4 >Welcome back <span>Example</span></h4></div>
<div class="col-xs-2 col-sm-4 text-center">
<h1 style="font-size:2.5vw;" onclick="about()" title='About'>Example<span class="text-primary">TEXT</span>Example</h1>
</div>
<div class="col-xs-7 col-sm-4 text-right">
<div>
<button type="button" class="btn btn-danger btn-responsive" onclick="search()" >Search</button>
<button type="button" class="btn btn-primary btn-responsive" id="logoutButton " >Logout</button>
<button type="button" class="btn btn-primary btn-responsive" data-toggle="modal" data-target="#loginModal" >Login</button>
</div>
</div>
</div>
</div>
</nav>

Images getting bigger then defined size and out of div

I am using bootstrap to create a html page where I am showing a list of images. But some images are showing bigger and the last image sometimes get out of my main container div. Also, if i reduce the browser size then some items overlap at some point. How do I solve it?
My css:
* { arial, sans-serif !important; }
body{ padding-top: 50px; }
img.img-thumb{
height: 180px;
width: auto; }
My html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<title>Test Web</title>
</head>
<body>
<div class="container-fluid">
<!-- ------------------ Main ----------------------- -->
<div class="col-md-2">Left sideBar</div>
<div class="col-md-8">
<h2 class="text-center">Mens shoes</h2>
<hr>
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3">
<h4>shoe-1</h4>
<img src="https://cdn.sweatband.com/asics_gel-pulse_11_mens_running_shoes_asics_gel-pulse_11_mens_running_shoes12.jpg"
alt="shoe-1" class="img-thumb" />
<p class="list-price text-danger">List Price: £50 </p>
<button type="button" class="btn btn-sm btn-success" onclick="">Details</button>
</div>
<div class="col-sm-6 col-md-4 col-lg-3 ">
<h4>shoe-1</h4>
<img src="https://images.sportsdirect.com/images/products/21113502_l.jpg" alt="shoe-1"
class="img-thumb" />
<p class="list-price text-danger">List Price: £50 </p>
<button type="button" class="btn btn-sm btn-success" onclick="">Details</button>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<h4>shoe-1</h4>
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/merrell-nova-mens-0506-1563371874.jpg"
alt="shoe-1" class="img-thumb" />
<p class="list-price text-danger">List Price: £50 </p>
<button type="button" class="btn btn-sm btn-success" onclick="">Details</button>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<h4>shoe-1</h4>
<img src="https://absolute-snow.cdn.rlab.net/Larger/6e291399-33da-47c3-97df-3e5712d6c932cloudventure-mens-trail-running-shoes-flare-dawn-p9007-8363_.jpg"
alt="shoe-1" class="img-thumb" />
<p class="list-price text-danger">List Price: £50 </p>
<button type="button" class="btn btn-sm btn-success" onclick="">Details</button>
</div>
</div>
</div>
<div class="col-md-2">Right sideBar</div>
<!-- ----------------------- footer ------------------------- -->
</div>
<br><br>
<hr>
<div class="col-md-12 text-center">
© Copyright 2013-2015
</div>
</body>
</html>
here is the link: https://jsfiddle.net/rashed007/xeukaqr4/1/
One solution I found is that instead of defining image width I can say max-width: 100%;
So, if I use the below code then images loose their ratio :
img.img-thumb{
height: 180px;
width: auto;
max-width:100%;
max-height:100%;
}
and if I use the below then the images get into different sizes:
img.img-thumb{
max-width:100%;
max-height:100%;
}
How to properly do it?
Since you're using BS3 give the images the class img-responsive and remove the max-* attributes you added. That's a built-in BS3 class that sets the max-width to 100% and the height will adjust automatically based on the intrinsic aspect ratio of your image.

How to display input buttons on one line in Bootstrap?

I've made a small little Bootstrap panel, and I have 3 Bootstrap buttons in the panel at the bottom. What I'm trying to do is make all the buttons be on one line and have a small gap, not bunched together. Here's what I have right now, and here's what it's doing:
.recent
{
margin-top: 50px;
margin-right: 500px;
}
.recent input
{
float: left;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<div class="recent">
<div class="container">
<div class="col-lg-3">
<div class="panel panel-primary">
<div class="panel-heading"><center><span class="label label-danger">Recent</span></center></div>
<div class="panel-body">
<p>- Aurora, Colorado : Blah Blah Blah</p>
<input type="button" value="View all" onClick="#" class="btn btn-primary">
<input type="button" value="Last 24 hours" onClick="#" class="btn btn-danger">
<input type="button" value="Last 48 hours" onClick="#" class="btn btn-warning">
</div>
</div>
</div>
</div>
</div>
What's happening is this:
https://gyazo.com/46b7c219adc26be516475c8f3b4d803d
Is there any way to make them stay on one line, or would I have to make the column larger?
You'll need to make the column width wider. Since you're using col-lg-3 class, the last button is wrapping to the next line. Try changing it to a larger column (i.e. col-lg-6). To answer the second part of your question, you can add a CSS rule like .btn {margin: 0 5px;} if you want some space between the buttons.
you can also achieve with out using float property. You use display:inline-block instead of float.
or you use 3 multiple division(.col-sm, .col-md, .col-lg) in .row or .container
You can try this code
<div class="recent">
<div class="container">
<div class="row">
<div class="panel panel-primary">
<div class="panel-heading"><center><span class="label label-danger">Recent</span></center></div>
<div class="panel-body">
<p>- Aurora, Colorado : Blah Blah Blah</p>
<div class="col-lg-2"><input type="button" value="View all" onClick="#" class="btn btn-primary"></div>
<div class="col-lg-2"><input type="button" value="Last 24 hours" onClick="#" class="btn btn-danger"></div>
<div class="col-lg-2"><input type="button" value="Last 48 hours" onClick="#" class="btn btn-warning"></div>
</div>
</div>
</div>
</div>
</div>
Here are few points.
Why are you giving 500 margin right to recent class? it will create problem in responsiveness. Even if you are targeting only desktop screen it is not good practice. 500 margin forcing to reduce width of recent.
you are using col-lg-3 It might be fine to use col-lg-3 for larger screens more than 1200px wide.. for small screens there are col-md-3, col-sm-3 and col-xs-3
Give a little margin-right to buttons so that they have a little space.
.recent
{
margin-top: 50px;
}
.recent input
{
float: left;
}
.m-right{
margin-right:5px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<div class="recent">
<div class="container">
<div class="col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading"><center><span class="label label-danger">Recent</span></center></div>
<div class="panel-body">
<p>- Aurora, Colorado : Blah Blah Blah</p>
<input type="button" value="View all" onClick="#" class="btn btn-primary m-right">
<input type="button" value="Last 24 hours" onClick="#" class="btn btn-danger m-right">
<input type="button" value="Last 48 hours" onClick="#" class="btn btn-warning m-right">
</div>
</div>
</div>
</div>
</div>