I have a row of divs that I am trying to build a gallery row with.
Despite using align: auto; on the images, They still seem to align to the left.
I was wondering if I am missing something.
here is my fiddle: http://jsfiddle.net/82nrw19x/
here is my code:
CSS:
.galleryRow{
}
.galleryIconOuter{
background-color: gray;
width: 20%;
height: 70px;
border-radius: 5px;
}
#wrapper {
min-width:100%;
min-height:100%;
border: 4px gainsboro solid;
margin: 0auto;
position: relative;
}
#im {
margin: 0 auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: url("https://s31.postimg.org/x8rd1797f/product1.png");
background-repeat: no-repeat;
background-size: contain;
}
HTML:
<section id="products" class="about">
<div class="container">
<div class="info col-lg-12 text-center">
<h2>Products</h2>
<div class="galleryRow w3-row">
<div class="galleryIconOuter w3-col">
<div id="wrapper">
<div id="im">
</div>
</div>
</div>
<div class="galleryIconOuter w3-col">
<div id="wrapper">
<div id="im">
</div>
</div>
</div>
<div class="galleryIconOuter w3-col">
<div id="wrapper">
<div id="im">
</div>
</div>
</div>
<div class="galleryIconOuter w3-col">
<div id="wrapper">
<div id="im">
</div>
</div>
</div>
<div class="galleryIconOuter w3-col">
<div id="wrapper">
<div id="im">
</div>
</div>
</div>
</div>
</div>
</div>
</section>
any help or advice is appreciated.
Thank you in advance.
You are including the img as backgrounds, then you just need to set
background-position to center:
Try this:
#im {
margin: 0 auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: url("https://s31.postimg.org/x8rd1797f/product1.png");
background-repeat: no-repeat;
background-size: contain;
/* ADD THIS LINE*/
background-position:center;
}
Or the shorthand:
background: url("https://s31.postimg.org/x8rd1797f/product1.png") no-repeat center/contain;
Updated Fiddle
Do you mean like this?
.galleryRow{
position: relative;
width: 80%;
left: 10%;
right: 10%;
}
Is that what you mean by wanting them to "align to middle?"
Related
I have 3 divs inside a section. The divs position is absolute because I want a really small gap between the 3 divs, but when I want to horizontal the divs nothing happens. What should I do?
#columnL {
width: 412px;
height: 705px;
position: absolute;
left: 0;
}
#columnM {
width: 412px;
height: 705px;
right: 0;
left: 0;
position: absolute;
}
#columnR {
width: 412px;
height: 705px;
position: absolute;
right: 0;
}
<section id="blabla">
<div id="columnL">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
<div id="columnM">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
<div id="columnR">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
</section>
Make a parent div with a relative positioning rule. Like this:
#blabla {
position: relative;
}
Indicate the margin: auto for each card - #columnL, #columnM and #columnR.
And push the width: 100% for the img tag. Like this:
img {
width: 100%;
}
But why do you need absolute positioning?
#blabla {
position: relative;
}
#columnL {
width: 412px;
height: 705px;
position: absolute;
left: 0;
margin: auto;
}
#columnM {
width: 412px;
height: 705px;
right: 0;
left: 0;
position: absolute;
margin: auto;
}
#columnR {
width: 412px;
height: 705px;
position: absolute;
right: 0;
margin: auto;
}
img {
width: 100%;
}
<section id="blabla">
<div id="columnL">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
<div id="columnM">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
<div id="columnR">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
</section>
Solution with flex and absolute positioning.
The absolute in this solution is an additional parent block, with a class of .absolute, as well as a flexible rule that sets the indentation by the gap rule.
#blabla {
position: relative;
}
.absolute {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: space-between;
gap: 30px;
}
#columnL {
width: 412px;
height: 705px;
}
#columnM {
width: 412px;
height: 705px;
}
#columnR {
width: 412px;
height: 705px;
}
img {
width: 100%;
}
<section id="blabla">
<div class="absolute">
<div id="columnL">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
<div id="columnM">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
<div id="columnR">
<div id="afbeeldingL">
<img src="https://www.spiralex.nl/wp-content/uploads/2021/01/110-14018-b-Petronas-V2017.jpg">
</div>
<div id="tekstL">
<h1 id="hoofdstuk1">TEXT</h1>
</div>
</div>
</div>
</section>
I have a button with position: fixed at the bottom of a web page. How do I make it so that the page content scrolls behind the button?
Here's an image with more detail on what I mean:
Here's some code I tried:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#content {
height: 150px;
width: 100%;
background-color:lightpink;
padding:25px;
margin:20px;
}
#header{
color:white;
width:100%;
height:40px;
left:0;
top:0;
position:fixed;
background-color:black;
}
#sidebar{
top:0;
left:0;
width:90px;
height:100%;
position:fixed;
color:white;
background-color:steelblue;
}
.btn-bottom-center {
position: fixed;
left: 50%;
bottom: 20px;
transform: translate(-50%, -50%);
margin: 0 auto;
}
</style>
</head>
<body>
<div id="defaultFragment" fragment="defaultFragment">
<div id="header"> <center><h3>Header</h3></center> </div>
<div class="main-container container-fluid">
<div class="page-container">
<div id="sidebar" th:replace="fragments/sidebar :: sidebarFragment"></div>
<div class="page-content">
<div class="page-body">
<div id="content" layout:fragment="content"></div>
<div id="content" layout:fragment="content"></div>
<div id="content" layout:fragment="content"></div>
<div id="content" layout:fragment="content"></div>
</div>
</div>
</div>
<div th:replace="fragments/footer :: footerFragment"></div>
</div>
</div>
<!--Get Started-->
<input id="get_started" type="button" class="btn-bottom-center" value="GET STARTED" />
</body>
</html>
The dimensions are not really important. I just need to know the logic of how to make a div scroll behind a button with a fixed position at the bottom of a web page. I tried adding a margin-bottom to the page content but it didn't work. Thanks already
Wrap the button in a fixed-position div that has a defined height, left: 90px;, right: 0, bottom: 0 and a non-transparent background:
html,
body {
margin: 0;
}
#content {
height: 150px;
width: 100%;
background-color: lightpink;
padding: 25px;
margin: 20px;
}
#header {
color: white;
width: 100%;
height: 40px;
left: 0;
top: 0;
position: fixed;
background-color: black;
}
#sidebar {
top: 0;
left: 0;
width: 90px;
height: 100%;
position: fixed;
color: white;
background-color: steelblue;
}
.btn-bottom-center {
position: fixed;
left: 50%;
bottom: 20px;
transform: translate(-50%, -50%);
margin: 0 auto;
}
.bottom {
height: 80px;
background: green;
position: fixed;
bottom: 0;
left: 90px;
right: 0;
}
<div id="defaultFragment" fragment="defaultFragment">
<div id="header">
<center>
<h3>Header</h3>
</center>
</div>
<div class="main-container container-fluid">
<div class="page-container">
<div id="sidebar" th:replace="fragments/sidebar :: sidebarFragment"></div>
<div class="page-content">
<div class="page-body">
<div id="content" layout:fragment="content"></div>
<div id="content" layout:fragment="content"></div>
<div id="content" layout:fragment="content"></div>
<div id="content" layout:fragment="content"></div>
</div>
</div>
</div>
<div th:replace="fragments/footer :: footerFragment"></div>
</div>
</div>
<!--Get Started-->
<div class="bottom">
<input id="get_started" type="button" class="btn-bottom-center" value="GET STARTED" />
</div>
I have an issue. I'm trying to make bootstrap grid system with 4 rows, but the problem some rows are overlapped. I don't know from where comes this problem.
this fiddle shows my issue
html, body{
width: 100% !important;
height: 100% !important;
padding:0;
position: relative;
}
#header-sec{
position: absolute;
/*top: 0;*/
width: 100%;
background-color: green;
height : 15%;
min-height: 30px;
}
#footer-sec{
position: absolute;
bottom: 0;
width: 100%;
background-color: black;
height : 5%;
}
#data-viewer{
height : 60%;
}
#zone-geog{
height : 20%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container-fluid">
<div id="header-sec" class="row">
<div class="col-sm-12">header</div>
</div>
<div id="zone-geog" class="row">
<div class="col-sm-12">
zone geog
</div>
</div>
<div id="data-viewer" class="row bg-primary">
<div class="col-sm-9">map</div>
<div class="col-sm-3">idica evolu</div>
</div>
<div id="footer-sec" class="row">
<div class="col-sm-12">footer</div>
</div>
</div>
</body>
if you have any ideas please help me solve this issue.
You need to remove position: absolute
html, body{
width: 100% !important;
height: 100% !important;
padding:0;
position: relative;
}
#header-sec{
width: 100%;
background-color: green !important;
height : 15%;
min-height: 30px;
}
#footer-sec{
position: absolute;
bottom: 0;
width: 100%;
background-color: black;
height : 5%;
}
#data-viewer{
height : 60%;
}
#zone-geog{
height : 20%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container-fluid">
<div id="header-sec" class="row">
<div class="col-sm-12">header</div>
</div>
<div id="zone-geog" class="row">
<div class="col-sm-12">
zone geog
</div>
</div>
<div id="data-viewer" class="row bg-primary">
<div class="col-sm-9">map</div>
<div class="col-sm-3">idica evolu</div>
</div>
<div id="footer-sec" class="row">
<div class="col-sm-12">footer</div>
</div>
</div>
</body>
I don't know how to make background-image opacity 0.5 and the content full opacity.
.about-section {
height: 100%;
padding-top: 50px;
text-align: center;
/*background: #eee;*/
background: url(../images/about.jpg);
background-repeat: no-repeat;
background-size: contain;
background-position: center;
opacity: 0.3;
}
<section id="about" class="about-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="head">About Us</h1>
</div>
</div>
</div>
</section>
Is this the sort of thing you're after?
.about-section {
height: 100%;
padding-top: 50px;
text-align: center;
}
.background {
height: 100%;
width: 100%;
position: absolute;
background: url(https://ichef-1.bbci.co.uk/news/976/media/images/83351000/jpg/_83351965_explorer273lincolnshirewoldssouthpicturebynicholassilkstone.jpg);
background-repeat: no-repeat;
background-size: contain;
background-position: center;
opacity: 0.3;
}
<section id="about" class="about-section">
<div class="background">
</div>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="head">About Us</h1>
</div>
</div>
</div>
</section>
You can use pseudo elements to get it
just like following
.about-section {
height: 100%;
padding-top: 50px;
text-align: center;
/*background: #eee;*/
background: url(http://lorempixel.com/400/200/);
background-repeat: no-repeat;
background-size: contain;
background-position: center;
position: relative;
}
.about-section::after {
content: '';
height: 100%;
width: 100%;
background: rgba(255, 255, 255, 0.5); /*Change as your need */
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
<section id="about" class="about-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="head">About Us</h1>
</div>
</div>
</div>
</section>
You can use the ::beforeĀ“-pseudo-element.
.about-section {
position:relative; /* Notice this */
height: 100%;
padding-top: 50px;
text-align: center;
}
.about-section::before {
content:'';
position:absolute;
width:100%;
height:100%;
left:0px;
top:0px;
background: #000; /* change to whatever you want */
opacity:0.3;
}
<section id="about" class="about-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="head">About Us</h1>
</div>
</div>
</div>
</section>
For the moment, CSS does not offer that possibility (unless your background is just a colour, in which case you can use rgba()).
To achieve this, you can place your .about-section in position: relative; and create a <div> inside it (preferably as the first child, or even better, as a ::before pseudo-element) absolutely positioned, with full width and height. You can then tweak its opacity as you wish without affecting the content.
I have a fixed header and a image below the header.
The image has a property position: fixed.
Now for some devices the image is not in the center as It should be.
Here's the fiddle for it.
The left side has more spaces than the right hand side.
Also above the image, I want to add a p tag which is not showing up for some reason.
Please let me know what's wrong here.
<div class="content-wrapper new-class">
<div class="container">
<div class="row">
<div class="col-xs-12 ">
<div class="center-logo description">
<img src="http://i.imgur.com/ECTLTbK.png" alt="" class="img-responsive">
<P class="step1description" See price</p>
</div>
</div>
</div>
</div>
</div>
Checkout this solution:
body, html {
margin:0;
padding:0;
}
.content-wrapper {
position: relative;
overflow: hidden;
width: 100%;
background-color: #333230;
}
.content-wrapper .center-logo {
position: fixed;
width: 100%;
top: 125px;
left:0;
text-align: center;
margin: 5px 0 15px;
z-index: 1001;
background-color: #333230;
}
.content-wrapper .center-logo img {
margin: 0 auto;
}
.center-logo p.step1description {
position: relative;
top: -30px;
width: 220px;
text-align: center;
color: #fff;
font-size: 12px;
margin: 0 auto;
}
.description {
margin:30px 0 30px 0 !important;
}
.content-wrapper .content {
text-align: center;
width: 100%;
}
.new-class{
padding-bottom: 134px;
top: 134px;
}
<div class="content-wrapper new-class">
<div class="container">
<div class="row">
<div class="col-xs-12 ">
<div class="center-logo description">
<img src="http://i.imgur.com/ECTLTbK.png" alt="" class="img-responsive">
<p class="step1description"> See price</p>
</div>
</div>
</div>
</div>
</div>
You have some typos on html and css! - Here you can find a working fiddle: http://jsfiddle.net/sebastianbrosch/cxumhp9k/1/
Add left:0 on .content-wrapper .center-logo
.content-wrapper .center-logo { left:0;}