.menu {
max-width: 350px;
margin: 50px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Booting the mind with Bootstrap</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container-fluid">
<div class="btn-group-vertical menu">
<button type="button" class="btn btn-default btn-block menuitem" data-toggle="collapse" data-target="#demo">Apple</button>
<div id="demo" class="collapse">
Hello world! I am Raj. I am trying to make something. But I don't know if I could do that.
</div>
<button type="button" class="btn btn-default menuitem">Samsung</button>
<button type="button" class="btn btn-default menuitem">Sony</button>
</div>
</div>
</body>
</html>
I am trying to create a collapsible button menu having a fixed initial width using Bootstrap. I want this menu to be responsive. By setting the width of the button group, I am being able to get a menu with a perfect width. However, I am loosing its responsive property. By replacing the width property in the CSS file with the max-width property, I am getting a responsive menu. But then the width of the menu is changing when a menu item is expanded and collapsed. I also tried to set the width, max-width and min-width of .btn class. But all these trials went in vain. Is there any way through which I can achieve both responsiveness and a fixed width?
Try this
.menu {
width: 350px;
margin: 50px;
}
#media only screen and (max-width: 769px) {
.menu{
width:25%;
}
}
sample fiddle..
Related
I am trying to use the outline buttons class(btn btn-outline-primary) in bootstrap but for some reason, all the buttons aren't colored at all I only see them as gray here what I am mean
this is how buttons should look like: https://ibb.co/ChKf83y
but here is how they look for me: https://ibb.co/8X1nHSn
here is the code:
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>toggle</title>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<style>
#p {
position: absolute;
top: 50%;
left: 50%;
}
</style>
<body>
<button id="p" class="btn btn-outline-warning ">Random Videos</button>
<button type="button" class="btn btn-outline-primary">Success</button>
</body>
</html>
You are using Bootstrap 3 and outline buttons were introduced in Bootstrap 4. You can either upgrade to Bootstrap 4 or use CSS instead.
The whole bootstraps thing is killing me. I'm so lost on this subject if there's anyone who can help me out on this, I'll be really thankful.
Sorry that my style sheet can't connect to this website.
My nav-bar looks like
this
but it should look like
this
I truly hope you can help me get out of this mess!
* {
font-family: 'Oxygen', sans-serif;
background-color: maroon;
}
/** Header **/
#header-nav {
background-color: #f6b319;
border-radius: 0;
border: 0;
}
#logo-img {
background: url('../images/flying-cat.png') no-repeat;
width: 150px;
height: 150px;
left: 15px;
background-size: contain;
margin: 10px 10px 10px 10px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<link href="https://fonts.googleapis.com/css?family=Oxygen:300,400,700" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<header>
<nav id="header-nav" class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a href="index.html" class="navbar-brand">
<div id="logo-img"></div>
</a>
</div>
</div>
</nav>
</div>
</div>
</nav>
</header>
</body>
</html>
The image doesn't fit because you've set it to be an absolute size, which is larger than the nav-bar. Your CSS class logo-img contains height: 150px which makes it break out of the nav-bar. Set a lower height property so that it fits within the nav-bar.
You've also used a div inside that navbar-brand div which isn't necessary and is causing problems, even in bootstrap boiler plates the navbar-brand image is an image element within that div. Put an image tag inside that navbar-brand div, specify a width and specify a height of auto so that it scales within its boundaries.
Here is the way it is done in Bootstrap examples, you will need to tweak this when using your own image source though.
Edit your navbar-header HTML so it looks like this:
<div class="navbar-header">
<a href="index.html" class="navbar-brand">
<img src="https://placeholdit.co//i/555x150"></a>
</div>
Add the following rule to your CSS:
.navbar-brand {
padding: 10px;
}
The problem was the unnecessary styling that bootstrap applies.
So
You'll need to set your Header to fixed height, Then set the div with the background to a height within the header's height for a logo it's should be problematic in the long run, In case of making the website responsive.
I made a somewhat close to what you need demo, take it from there to your desired design.
* {
font-family: 'Oxygen', sans-serif;
margin:0;padding:0;
}
header{
height: 100px;
}
#header-nav {
background-color: #f6b319;
border-radius: 0;
}
#header-nav,.container,.navbar-header,.navbar-brand{height: 100%;}
#logo-img {
background: url('4.png') no-repeat;
display:inline-block;
width:80px;
border:1px solid;
height: 80px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Oxygen:300,400,700" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<header>
<nav id="header-nav" class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a href="index.html" class="navbar-brand">
<div id="logo-img"></div>
</a>
</div>
</div>
</nav>
</div>
</div>
</nav>
</header>
</body>
</html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/
3.3.7/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<h2>Button Group</h2>
<p>The .btn-group class creates a button group:</p>
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
</div>
<style type="text/css">
button{
background-color:red;
}
</style>
</body>
</html>
In the above segment, Bootstrap is being used and when tried to apply the background-color property for the button tag,it is not being reflected.What is the reason for that?
Try to add !important:
<style type="text/css">
button{
background-color: red !important;
}
</style>
Or put your <style> upper, than your divs and buttons... sometimes that is the issue.
You can use !important, because bootstrap already written a style. So if you want to overwrite that style, maybe you will need to write it down under the bootstrap's style, otherwise you will need to add !important.
I think this website will help you to understand the reason of !important.
https://css-tricks.com/when-using-important-is-the-right-choice/
I'm doing a website that will be mostly displayed on a mobile.
I'm using bootstrap 4.
Currently I'm trying to display an element that has to be "vertically" centered in the available space.
By this I mean: I've a title, which use a fixed size, and I've one message + 2 button in a div that I need to display in the vertical middle of the available space(without overflow).
I found this: vertical-align with Bootstrap 3 --> the bootstrap 4 snippet doesn't work
One other answer which was about flexible box was promising, but it seems that if I have only one component that should use all the remaining space it doesn't work.
Also, one thing; the element that I need to have vertically aligned is displayed through a jquery call:
$('#btToShow').click(function(){
$('#card-container').fadeOut(200, function(){$('#wait-for-result-container').fadeIn();});
});
$('#change-choice').click(function(){
$('#wait-for-result-container').fadeOut(200, function(){$('#card-container').fadeIn();});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Some page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
crossorigin="anonymous">
</head>
<body>
<H1 class="text-center page-header">Somelist</H1>
<div id="card-container" class="container show center-block">
<div id="card-subcontainer" class="row center-block">
<!-- Here there is normally a lot of buttons -->
<button class="btn" id="btToShow">Show</button>
</div>
</div>
<div id="wait-for-result-container" class="container center-block text-center m-7" style="display: none;">
<h2>This is the part that is absolutely not vertically aligned</h2>
<div>
<button class="btn btn-primary btn-lg">Wait for it...</button>
<button id="change-choice" class="btn btn-danger">Change the choice</button>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
crossorigin="anonymous"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.2.0/js/mdb.min.js" crossorigin="anonymous"></script>-->
</body>
</html>
Any idea how I can align the content of #wait-for-result-container vertically in the middle?
You can vertically center content with flexbox
#wait-for-result-container {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
codePen
To fadeIn with display: flex
$("#wait-for-result-container")
.css("display", "flex")
.hide()
.fadeIn();
This method works really well for Bootstrap 3.x:
#wait-for-result-container {
position:absolute;
left:0;
right:0;
top:50%;
-webkit-transform:translateY(-50%) !important;
-ms-transform:translateY(-50%) !important;
transform:translateY(-50%) !important;
}
top:50% sets the position of the div 1/2 way down the container, then transform:translateY(-50%) shifts it back up half the distance, making a nicely vertically centered object relative to the parent container.
You could just position it absolutely:
#wait-for-result-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
$('#btToShow').click(function(){
$('#card-container').fadeOut(200, function(){$('#wait-for-result-container').fadeIn();});
});
$('#change-choice').click(function(){
$('#wait-for-result-container').fadeOut(200, function(){$('#card-container').fadeIn();});
});
#wait-for-result-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Some page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
crossorigin="anonymous">
</head>
<body>
<H1 class="text-center page-header">Somelist</H1>
<div id="card-container" class="container show center-block">
<div id="card-subcontainer" class="row center-block">
<!-- Here there is normally a lot of buttons -->
<button class="btn" id="btToShow">Show</button>
</div>
</div>
<div id="wait-for-result-container" class="container center-block text-center m-7" style="display: none;">
<h2>This is the part that is absolutely not vertically aligned</h2>
<div>
<button class="btn btn-primary btn-lg">Wait for it...</button>
<button id="change-choice" class="btn btn-danger">Change the choice</button>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
crossorigin="anonymous"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.2.0/js/mdb.min.js" crossorigin="anonymous"></script>-->
</body>
</html>
So I'm trying to make my website mobile-responsive as I have it how I want it to look on a desktop. However, my media queries won't work for classes in any other view than the index.html and I can't figure out why.
Index.html:
html ng-app='skypeClone'
`
<head>
<meta charset="utf-8">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"/> Have tried media queries with and without this-->
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Skype Clone</title>
</head>
<body ng-controller='mainCtrl'>
<ui-view class="view"></ui-view>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.js"></script>
<script src="//cdn.temasys.com.sg/skylink/skylinkjs/0.6.x/skylink.complete.min.js"></script>
<script src="js/app.js"></script>
<script src="js/mainCtrl.js"></script>
<script src="js/helpCtrl.js"></script>
<script src="js/loginCtrl.js"></script>
<script src="js/loginSvc.js"></script>
<script src="js/createUserCtrl.js"></script>
<script src="js/createUserSvc.js"></script>
<script src="js/service.js"></script>
<script src="js/userHomeCtrl.js"></script>
</body
</html>
`
If the commented out code isn't showing up, I have tried media queries with and without the meta name="viewport" content="width=device-width, initial-scale=1.0"
Other Route:
`
<div id="background-setter-homepage">
<div id="header-wrap">
<div id="header">
<button class="button" id="help" ui-sref='help'>Help</button>
<button class="button" id="about" ui-sref='about'>About</button>
<button class="button" id="login" ui-sref='login'>Login</button>
</div>
</div>
<br><br>
<div class="middleOfPage" id="container">
<div id="text-and-button">
<h2 id="phrase">Skyclone keeps the world talking, for free</h2> <br>
<button class="button" id="getStarted" ui-sref='createUser'>Create An Account</button>
<div>
</div>
</div>
`
All I want to test just to get it to work is to have the class 'phrase' of the h2 element turn red when the screen gets to a certain max-width.
CSS:
`
#media (max-width: 375px) {
#phrase{
color: lightgreen;
}
}
`
I've Also tried
`
#media only screen and (max-width: 800px) {
#phrase{
color: lightgreen;
}
}
`
The above code doesn't work, however it will work if I select the class on ui-view in the index.html and set the visibility to none at the same width. So It's kind of working...but not really.
Have any of you run into this problem before? I'm currently at a loss. Any and all help is SUPER APPRECIATED!! Thanks in advance (:
If setting visibility to none in the same media query does work, maybe all you need is to change color: lightgreen; to color: lightgreen !important;
Have you tried that yet?