I am using Bootstrap latest version and trying to center align contents in a span and section but nothing seems to work.
Here is my markup:
<div class="container body-content">
<ul id="CategoryMenu" class="list-inline">
<li>
<a href="/Category/Cars">
Cars
</a>
</li>
<li>
<a href="/Category/Buses">
Buses
</a>
</li>
</ul>
<hr>
<section>
<div class="gallery center-block">
<hgroup>
<h2>Products</h2>
</hgroup>
<div class="categories row">
<ul id="da-thumbs" class="da-thumbs">
<div id="MainContent_productList_ctrl0_itemPlaceholderContainer">
<li>
<a href="/Product/Convertible%20Car">
<img src="/Catalog/Images/Thumbs/carconvert.png">
<div><span>Natalie & Justin Cleaning by Justin Younger</span></div>
</a>
<div>
<a href="/Product/Convertible%20Car">
Convertible Car
</a>
</div>
</li>
<li>
<a href="/Product/Old-time%20Car">
<img src="/Catalog/Images/Thumbs/carearly.png">
<div><span>Natalie & Justin Cleaning by Justin Younger</span></div>
</a>
<div>
<a href="/Product/Old-time%20Car">
Old-time Car
</a>
</div>
</li>
<li>
<a href="/Product/Fast%20Car">
<img src="/Catalog/Images/Thumbs/carfast.png">
<div><span>Natalie & Justin Cleaning by Justin Younger</span></div>
</a>
<div>
<a href="/Product/Fast%20Car">
Fast Car
</a>
</div>
</li>
<li>
<a href="/Product/Super%20Fast%20Car">
<img src="/Catalog/Images/Thumbs/carfaster.png">
<div><span>Natalie & Justin Cleaning by Justin Younger</span></div>
</a>
<div>
<a href="/Product/Super%20Fast%20Car">
Super Fast Car
</a>
</div>
</li>
<li>
<a href="/Product/Old%20Style%20Racer">
<img src="/Catalog/Images/Thumbs/carracer.png">
<div><span>Natalie & Justin Cleaning by Justin Younger</span></div>
</a>
<div>
<a href="/Product/Old%20Style%20Racer">
Old Style Racer
</a>
</div>
</li>
<li>
<a href="/Product/Ace%20Plane">
<img src="/Catalog/Images/Thumbs/planeace.png">
<div><span>Natalie & Justin Cleaning by Justin Younger</span></div>
</a>
<div>
<a href="/Product/Ace%20Plane">
Ace Plane
</a>
</div>
</li>
</div>
</ul>
</div>
<span id="MainContent_it" class="btn-group btn-group-sm text-center">
<a class="customDisabledClassName btn btn-default">|<</a>
<a class="customDisabledClassName btn btn-default"><</a>
<span class="btn btn-primary disabled">1</span>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$MainContent$it$ctl01$ctl01','')">2</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$MainContent$it$ctl01$ctl02','')">3</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$MainContent$it$ctl02$ctl00','')">></a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$MainContent$it$ctl02$ctl01','')">>|</a>
</span>
</div>
</section>
</div>
Basically I want that the images in the div gallery should be centered horizontally. So I added center-block and used the following CSS:
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
I also want to center align elements inside the <span> called 'MainContent_it' and I added the same center-block to it too, but nothing seems to work.
What else do I do?
IWantToLearn, Hi there. Is this what you are wanting to align.
Have a look at the Fiddle.
.center-this-block {
position: absolute;
left: 0;
right: 0;
margin: auto;
}
Your code is not so much clear but just on a guess
.center-block
{
width: 600px;
margin: 0 auto;
}
give width to the image if you want margin:0 auto.
You need to define the width of the element you are centering, not the parent element.
Apply the above class to the elements that you want to center.
Have a look at the link Why can't I center with margin: 0 auto?
Related
I am a beginner and use Bulma CSS and try to make a side menu by default CSS. Everything seems to be simple, but my content in the column is cut and has the wrong width.
`
<div class="columns is-fullheight" style="background-color: lightgrey;">
<aside class="column is-2 section is-narrow-mobile is-hidden-mobile is-fullheight" style="background-color: lightblue;">
<div class="menu">
<p class="menu-label is-hidden-touch">Navigation</p>
<ul class="menu-list">
<li>
<a href="#" class="">
<span class="icon"><i class="fa fa-home"></i></span> Home
</a>
</li>
<li>
<a href="#" class="is-active">
<span class="icon"><i class="fa fa-table"></i></span> Links
</a>
<ul>
<li>
<a href="#">
<span class="icon is-small"><i class="fa fa-link"></i></span> Link1
</a>
</li>
</ul>
</li>
</ul>
</div>
</aside>
</div>
`
Result
If I remove class "columns" I did size what I want
So, what I do incorrect?
I realized that the Bulma dropdown embeded in a modal card body gets covered by the modal body, so this causes an UX issue, imaging if the dropdown is higher than the card body it self, user has to scroll down or move the mouse cursor and move down the scrollbar, what would be the appropriate CSS fix for this? i.e. having the dropdown appear at the top layer (i increased the z-index for the ddl but no luck, please note: I DO need the overflow-y: scroll or auto for the modal card body section.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.9.3/css/bulma.min.css">
</head>
<body>
<div id="modal-ter" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Modal title</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body" style="height: 188px">
<div class="dropdown is-active">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu3">
<span>Click me</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" id="dropdown-menu3" role="menu">
<div class="dropdown-content">
<a href="#" class="dropdown-item">
Overview
</a>
<a href="#" class="dropdown-item">
Modifiers
</a>
<a href="#" class="dropdown-item">
Grid
</a>
<a href="#" class="dropdown-item">
Form
</a>
<a href="#" class="dropdown-item">
Elements
</a>
<a href="#" class="dropdown-item">
Components
</a>
<a href="#" class="dropdown-item">
Layout
</a>
<hr class="dropdown-divider">
<a href="#" class="dropdown-item">
More
</a>
</div>
</div>
</div>
</section>
<footer class="modal-card-foot">
<button class="button is-success">Save changes</button>
<button class="button">Cancel</button>
</footer>
</div>
</div>
<button class="button is-primary is-large modal-button" data-target="modal-ter" aria-haspopup="true">Launch card modal</button>
</body>
</html>
There is a open Bulma issue for this logged at: https://github.com/jgthms/bulma/issues/936
I added a comment on the issue above with the codepen sample:
https://codepen.io/wayneye/pen/ZEyQzOx
The problem lies in what behavior you expect when the dropdown is open and the user starts scrolling. Should the dropdown change position? And what should happen when the dropdown button with "click me" is not visible anymore because the user scrolled it out of sight. If the dropdown should also change position then you would get weird situations. So I made this example of how this problem could be solved by hiding the dropdown menu when the user scrolls.
function contentScroll() {
document.querySelector(".dropdown-menu").style.display = "none";
}
function clickMe(button) {
const rectObject = button.getBoundingClientRect();
const marginBelowButton = 2;
const dropdownContent = document.querySelector(".dropdown-menu");
dropdownContent.style.display = "block";
dropdownContent.style.top = rectObject.top + marginBelowButton + rectObject.height + "px";
dropdownContent.style.left = rectObject.left + "px";
}
.dropdown-menu {
position: fixed !important;
z-index: 20;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.9.3/css/bulma.min.css">
</head>
<body>
<div id="modal-ter" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Modal title</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body" style="height: 188px" onscroll='contentScroll()'>
<div class="dropdown is-active">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu3" onclick="clickMe(this)">
<span>Click me</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
<div class="dropdown-menu" id="dropdown-menu3" role="menu">
<div class="dropdown-content">
<a href="#" class="dropdown-item">
Overview
</a>
<a href="#" class="dropdown-item">
Modifiers
</a>
<a href="#" class="dropdown-item">
Grid
</a>
<a href="#" class="dropdown-item">
Form
</a>
<a href="#" class="dropdown-item">
Elements
</a>
<a href="#" class="dropdown-item">
Components
</a>
<a href="#" class="dropdown-item">
Layout
</a>
<hr class="dropdown-divider">
<a href="#" class="dropdown-item">
More
</a>
</div>
</div>
</div>
</section>
<footer class="modal-card-foot">
<button class="button is-success">Save changes</button>
<button class="button">Cancel</button>
</footer>
</div>
</div>
<button class="button is-primary is-large modal-button" data-target="modal-ter" aria-haspopup="true">Launch card modal</button>
</body>
</html>
if you don't want to hide the dropdown menu when scrolling you can also update the position so it follows the button by changing the function contentScroll() to this:
function contentScroll() {
clickMe(document.querySelector(".button"));
}
But like I said this would arise weird situations
Remove overflow: auto; from this CSS class and it will display correctly:
.modal-card-body {
-webkit-overflow-scrolling: touch;
background-color: #fff;
flex-grow: 1;
flex-shrink: 1;
/* overflow: auto; */
padding: 20px;
}
This could perhaps have an unintended side effect for your other modals, but unfortunately per now there isn't a native CSS method to check for presence of a certain child element in a parent and then style the parent.
You could do this with JavaScript by overriding the parent class with an additional CSS class or an inline style tag if the dropdown is present (or add it only when it is shown, together with the display: block).
It is not suggested but you can use
position: fixed !important;
make sure to neutralize the top and left styles of bulma dropdown on this one:
left: unset !important;
top: unset !important;
.dropdown-menu {
position: fixed !important;
z-index: 20;
left: unset !important;
top: unset !important;
margin-top: 40px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.9.3/css/bulma.min.css">
</head>
<body>
<div id="modal-ter" class="modal is-active">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Modal title</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body" style="height: 188px">
<div class="dropdown is-active">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu3">
<span>Click me</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" id="dropdown-menu3" role="menu">
<div class="dropdown-content">
<a href="#" class="dropdown-item">
Overview
</a>
<a href="#" class="dropdown-item">
Modifiers
</a>
<a href="#" class="dropdown-item">
Grid
</a>
<a href="#" class="dropdown-item">
Form
</a>
<a href="#" class="dropdown-item">
Elements
</a>
<a href="#" class="dropdown-item">
Components
</a>
<a href="#" class="dropdown-item">
Layout
</a>
<hr class="dropdown-divider">
<a href="#" class="dropdown-item">
More
</a>
</div>
</div>
</div>
</section>
<footer class="modal-card-foot">
<button class="button is-success">Save changes</button>
<button class="button">Cancel</button>
</footer>
</div>
</div>
<button class="button is-primary is-large modal-button" data-target="modal-ter" aria-haspopup="true">Launch card modal</button>
</body>
</html>
note: for a better result, I suggest you to give the fixed position to the parent element of bulma dropdown.
this resolves my issue
.modal.has-overflow {
position: fixed ! important;
overflow: auto ! important;
}
.modal .modal-content,.modal .modal-card,.modal .modal-card-body {
overflow: visible ! important;
}
I'm creating a menu using Bulma CSS. I have the following logo:
And I would like to use it much like the Atlantic did, in the center of the page. However, I'm not sure how; I've tried margin-auto:0, but that didn't work out. I also tried messing with the margins, and flexbox and inline-block, but to no avail. Any help is appreciated.
Here is the page thus far (on Codepen): https://codepen.io/Refath/full/ZEQzOQX
Additional Information: The Navbar is currently using one of Bulma's Components, as follows in the snippet below:
<nav class="navbar" role="navigation" aria-label="main navigation">
<form id="demo-2">
<input type="search" placeholder="Search">
</form>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">
Math
</a>
<a class="navbar-item">
Science
</a>
<a class="navbar-item">
Politics
</a>
<a class="navbar-item">
Economics
</a>
<a class="navbar-item">
Education
</a>
<a class="navbar-item">
Literature
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
More
</a>
<div class="navbar-dropdown">
<a class="navbar-item">
About
</a>
<a class="navbar-item">
Jobs
</a>
<a class="navbar-item">
Contact
</a>
<hr class="navbar-divider">
<a class="navbar-item">
Report an issue
</a>
</div>
</div>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary">
<strong>Sign up</strong>
</a>
</div>
</div>
</div>
</div>
</nav>
Use margin: 0 auto; or margin: auto;
It will work like this,
margin: auto; will be margin automatic from all four sides, and in case of
margin: 0 auto;. it will be 0 from top and bottom and auto from left and right.
I have a set of social media icons in one row that keep aligning to the left on wider breakpoints.
I would like them to be in the middle of the page when on wide breakpoint.
Also, on smaller breakpoints they turn into a vertical column and appear on top of each other. Is there a way to align them in one row horizontally and centrally on the page on smaller break points as well?
I have tried the following but its still not helping.
#media screen and (min-width: 320px) {
#social {
display: inline-block;
}
}
The following is the html that I see in the template:
<div id="social">
<div class="container">
<div class="row centered">
<div class="col-lg-2">
<a href="url" title="linkedin" target="_blank">
<i class="fa fa-linkedin"></i>
</a>
</div>
<div class="col-lg-2">
<a href="url" title="twitter" target="_blank">
<i class="fa fa-twitter"></i>
</a>
</div>
<div class="col-lg-2">
<a href="url" title="skype" target="_blank">
<i class="fa fa-skype"></i>
</a>
</div>
<div class="col-lg-2">
<a href="url" title="instagram" target="_blank">
<i class="fa fa-instagram"></i>
</a>
</div>
</div><!-- --/row ---->
</div><!-- --/container ---->
</div>
Any suggestions? Thanks in advance!
Instead of aligning them in separate divs use unordered lists as follow:
HTML
<div id="social">
<div id="container">
<ul>
<li>
<a href="url" title="linkedin" target="_blank">
<i class="fa fa-linkedin"></i>
</a>
</li>
<li>
<a href="url" title="twitter" target="_blank">
<i class="fa fa-twitter"></i>
</a>
</li>
<li>
<a href="url" title="skype" target="_blank">
<i class="fa fa-skype"></i>
</a>
</li>
<li>
<a href="url" title="instagram" target="_blank">
<i class="fa fa-instagram"></i>
</a>
</li>
</ul>
</div>
</div>
And here is the CSS part
#social #container {
text-align: center;
}
#social #container ul {
float: left;
}
#social #container ul li {
float: left;
padding-left: 10px;
list-style-type: none;
}
And for making the image to be aligned horizontally even in a smaller screen you need to give a percentage width or height to not move down.
Let me preface this by saying I am relatively new to bootstrap and possibly not udnerstanding the row/column layouts properly.
The layout I am working on can be seen here: http://jsfiddle.net/5NFXY/ (code pasted below)
The 'sidebar' on the right is where the problem is occurring. I have a .col-md-9 and a .col-md-3 enclosed withing a .row, but for some reason the right side of the sidebar is not lining up properly with its container. After playing around with this for quite some time I have found that if I remove margin-right: -15px; from the .row the problem goes away, but surely this isn't' the proper solution and I have mucked something up along the way. My question is, have I done something wrong in my HTML or is the proper solution really to manually override that margin-right: -15px;?
HTML
<body>
<div class="container">
<div class="logo-header">
<h1>Header</h1>
<h4>Subheader</h4>
</div>
<div class="inner-container clearfix">
<!-- Static navbar -->
<div class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
Operations <b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-header">Get Started</li>
<li>Start New</li>
<li>View All</li>
<li class="divider"></li>
<li class="dropdown-header"> Settings</li>
<li>Manage Types</li>
<li>Manage Types</li>
</ul>
</li>
<li class="dropdown">
Utilities <b class="caret"></b>
<ul class="dropdown-menu">
<li>Forums</li>
<li class="divider"></li>
<li>Distance</li>
</ul>
</li>
<li class="dropdown">
Administration <b class="caret"></b>
<ul class="dropdown-menu">
<li>News</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Alts <b class="caret"></b>
<ul class="dropdown-menu">
<li>1</li>
<li>2</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
<div class="row">
<div class="col-md-9">
<div class="wrath-content-box news-post">
<h1>Title Bar</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="" role="button">View navbar docs »</a>
</p>
</div>
<div class="wrath-content-box news-post">
<h1>Title Bar</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="" role="button">View navbar docs »</a>
</p>
</div>
<div class="wrath-content-box news-post">
<h1>Title Bar</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="" role="button">View navbar docs »</a>
</p>
</div>
<div class="wrath-content-box news-post">
<h1>Title Bar</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="" role="button">View navbar docs »</a>
</p>
</div>
</div>
<div class="col-md-3 wrath-content-box">
<h1>Title Bar</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="" role="button">View navbar docs »</a>
</p>
</div>
</div>
<footer class="wrath-content-box">
Footer tagline ©
</footer>
</div> <!-- /inner-container -->
</div> <!-- /container -->
</body>
CSS
body {
padding-top: 20px;
padding-bottom: 20px;
background: url('../img/wh-background-1.jpg') center center no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.navbar {
margin-bottom: 20px;
}
.logo-header {
color: #FFF;
}
.logo-header h1 {
margin-bottom: 0;
}
.logo-header h4 {
margin-top: 0;
margin-bottom: 20px;
}
footer {
margin-top: 20px;
}
.inner-container {
background: rgba(119, 119, 119, .5);
border-radius: 6px;
padding: 20px;
}
.wrath-content-box {
border-color: #e7e7e7;
background-color: #f8f8f8;
border-radius: 6px;
padding: 15px;
}
.news-post {
margin-bottom: 20px;
}
Using: Bootstrap 3.0.3 + Jquery 1.10.1
You've combined your custom class wrath-content-box with the bootstrap col-md-3 class and the padding on your class is overriding the Bootsrap grid padding.
You just need to put your class in a separate <div> inside the bootstrap one like you did in the first column.
<div class="col-md-3">
<div class="wrath-content-box">
...
</div>
</div>
Demo