Centering a slideshow with HTML and CSS - html

I am attempting to develop a website to better my web development understanding and have run into an issue implementing a website. I am struggling figuring out how to neatly center my slideshow I have implemented for the home screen so i can develop my header, footer and nav bar around it. Any help on this end would be greatly appreciated. the HTML code used looks like this.
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0px;
}
slider {
display: block;
width: 1280px;
height: 50%;
background-color: #1f1f1f;
overflow: hidden;
position: absolute;
margin: 0px auto;
}
slider>* {
position: absolute;
display: block;
width: 50%;
height: 50%;
background: #1f1f1f;
animation: slide 12s infinite;
overflow: hidden;
margin: 0px auto;
}
slide:nth-child(1) {
left: 0%;
animation-delay: -1s;
background-image: url(1.jpg);
background-size: cover;
background-position: center;
}
slide:nth-child(2) {
animation-delay: 2s;
background-image: url(2.jpg);
background-size: cover;
background-position: center;
}
slide:nth-child(3) {
animation-delay: 5s;
background-image: url(3.jpg);
background-size: cover;
background-position: center;
}
slide:nth-child(4) {
left: 0%;
animation-delay: 8s;
background-image: url(4.jpg);
background-size: cover;
background-position: center;
}
slide p {
font-family: Comfortaa;
font-size: 70px;
text-align: center;
display: inline-block;
width: 100%;
margin-top: 340px;
color: #fff;
}
#keyframes slide {
0% {
left: 100%;
width: 100%;
}
5% {
left: 0%;
}
25% {
left: 0%;
}
30% {
left: 0%;
}
30.0001% {
left: -100%;
width: 0%;
}
100% {
left: 100%;
width: 0%;
}
}
<slider>
<slide>
<p>Slide 1</p>
</slide>
<slide>
<p>Slide 2</p>
</slide>
<slide>
<p>Slide 3</p>
</slide>
<slide>
<p>Slide 4</p>
</slide>
</slider>

As far as I understand, you want to center the slider in the body. If so, you need to change absolute by relative of position of slider.
slider {
display: block;
width: 1280px;
height: 50%;
background-color: #1f1f1f;
overflow: hidden;
position: relative;
margin: 0px auto;
}

You can center-align the slider by many ways. Like using the center tag although it is not recommended.
Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center
You can change your css code to this:
slider {
display: block;
margin-left: auto;
margin-right: auto;
// margin: 0 auto;
}
Or you can enclose slider in a div and add text-align: center to the div (aka wrapper or container) and add display: inline-block to slider
If you want to keep your position: absolute, then you can write your css like this.
slider {
position: absolute;
left: 50%;
margin-left: 640px; //half of the width
// you can also use:
// transform: translate(-50%, 0px);
// instead of margin-left
}
Also see these two for more ways and explanation:
https://www.w3schools.com/css/css_align.asp
https://www.freecodecamp.org/news/how-to-center-things-with-style-in-css-dc87b7542689/

Related

html CSS boostrap 5 responsive on larger screen some elements looks different

i'm practicing making a web page and i was using boostrap 5. my website is already responsive for mobile devices using the #media but when i try to see my webpage on larger screen sizes some divs - sections - row are out of its place and others remain perfect on their place. How can i make the whole column be center no matter the screen size.
when it's on my resolution it looks perfect
enter image description here
but when i zoom out it moves to the left
enter image description here
HTML
<div class="contaier">
<div class="card">
<div class="row">
<div class="col-12 col-md-8">
<div class="circle"> </div>
<div class="col-6 col-md-4"></div>
<h1>TOKEN</h1>
</div>
<div class="content1">
<p>The token will be launched in phase 2, which will serve as a passive reward for each of our DIVERS and as a token for the metaverse economy that is being built for the third phase.</p>
</div>
<img src="http://luxtopia.org/wp-content/uploads/2022/02/haseowo.gif">
</div>
</div>
</div>
</div>
CSS
* {
padding: 0;
margin: 0;
box-sizing: border-box;
scroll-behavior: smooth;
text-decoration: none;
text-shadow: #000000 0px 0 14px;
}
body{
background-image: url(http://luxtopia.org/wp-content/uploads/2022/03/ffinal.png);
height: 100%;
width: 100%;
background-size: auto;
background-position: bottom center;
font-family: 'Varela', sans-serif;
overflow-x: hidden ;
background-size: 100% 102.5%;
background-attachment: scroll;
background-repeat: no-repeat;
resize: both;
color: var(--font-color);
}
.cards .container{
object-fit: contain;
display:inline-block;
width: 100%;
padding: 1% 15%;
}
.card{
position: relative;
bottom: 850px;
left:230px;
width: 400px;
height: 300px;
background:#335bb7;
border-radius: 100px;
display: flex;
align-items: center;
transition: 0.5s;
border-style: none;
}
.card h1{
position:absolute;
left: 148%;
font-size: 30px;
bottom: 50%;
}
.card2 h1{
position:absolute;
right: 115%;
font-size: 30px;
bottom: 50%;
}
.card3 h1{
position:absolute;
left: 93%;
font-size: 30px;
bottom: 50%;
}
.card4 h1{
position:relative;
right: 46%;
font-size: 30px;
top: 5%;
}
.card .circle{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 20px;
overflow: hidden;
}
.card .circle::before{
content:'';
position: absolute;
top:0;
left:0;
width: 100%;
height: 100%;
background: #335bb7;
clip-path: circle(120px at center);
transition:0.05s;
display:hidden;
}
.card:hover .circle:before
{
background: #00fcf3;
clip-path: circle(400px at center);
height: 250px;
border-radius: 20px;
}
.card img{
position: absolute;
top:50%;
left: 50%;
transform: translate(-50%,-50%);
height: 250px;
width: 250px;
pointer-events: none;
transition:0.05s;
}
.card:hover img{
left: 2%;
top: 35%;
height: 400px;
width: 400px;
}
.card .content1
{
position: absolute;
width: 50%;
left: 10%;
padding:10px 0px 0px 20px;
transition: 0.5s;
opacity: 0;
visibility: hidden;
}
.card:hover .content1
{
left: 0;
opacity: 1;
visibility: visible;
left: 40%;
padding: 65px 20px;
}
thank you all who took the time to read my post, i apreciate any kind of help :')
You have got a typo in your first <div> class-name (contaier -> container).
Add a few flex-attributes:
.card{
justify-content: center;
}
You can alternatively also use the bootstrap classes instead:
<div class="card justify-content-center"></div>
This centers the child-elements of card. In your case: <div class="row">
Not sure if your rows or columns are the problem, since you only posted a snippet of your code. If you have trouble with the centering of your columns, just add this bootstrap class to the respective div: <div class="row justify-content-center">

Div Moving Around

Okay so I have been trying everything I can think of to get this div to stay where it is on any browser and I thought I would turn to you wonderful people to try to help me (I am sure its an easy fix that I have overlooked)
No matter what I do it seems to mess things up elsewhere.
I have tried to put all divs (and the body) into fixed position (and this seems to have worked to an extent)
I have also tried to make the whole page flex in the hope that if I allow flex to work then it will flex around the offending items.
I have literally spent 2 days bashing my head against a wall with this and I could really use another set of eyes on my code to show me where I am going wrong.
Thankyou so much for your responses
I have updated my code to now run without images and with colours instead. I have managed to sort some of the issues out I was having but now when I move the page from bottom up the blue door shrinks
#opening {
background-color: red;
min-width: 100%;
max-width: 100%;
max-height: 100%;
min-height: 100%;
margin-left: 0;
margin-right: 0;
background-attachment: fixed;
}
.wrap {
background-color: purple;
background-position: fixed;
min-height: 140px;
max-height: 140px;
max-width: 360px;
min-width: 360px;
color: #fff;
position: fixed;
margin: 20vh;
margin-left: 42%;
padding: 30% 2% 0% 0%;
}
div.left {
background-color: blue;
text-align: center;
max-width: 34vh;
max-height: 62vh;
min-width: 34vh;
min-height: 62vh;
/* background-image:url("door.png") ; */
background-position: fixed;
background-repeat: no-repeat;
margin-left: 42.1%;
margin-top: 12.5%;
animation-name: open-left;
animation-duration: 10s;
animation-easing-function: cubic-bezier(.06, .63, 0, 1);
animation-iteration-count: 1;
animation-fill-mode: forwards;
animation-delay: 10s;
position: fixed;
top: 0;
left: 0;
}
#-webkit-keyframes open-left {
from {
-webkit-transform: perspective(500) rotateY(0deg);
-webkit-transform-origin: 0% 20%;
}
to {
-webkit-transform: perspective(500) rotateY(89deg);
-webkit-transform-origin: 0% 20%;
}
}
button {
background-color: #000000;
max-width: 70%;
max-height: 20;
border: white;
border-style: double;
color: white;
text-align: center;
text-overflow: unset;
font-size: 20px;
margin-left: 1%;
}
<body id="opening">
<div class="wrap">
<span class="animated rubberBand infinite">
<div>
<div>
<button onclick="location.href = 'https://www.google.com';"class="button"> And the Gunslinger followed </button>
</div>
</div>
</span>
<div class="left">
</div>
</div>
</body>
this gives me an output of this on a full screen
Full size page, no shrink
and this is the output when I shrink the screen to the left
Div position moves
Is this what you are after?
html,
body {
display: flex;
background: #000 url('https://keiraj87.github.io/website/backg.png') top center no-repeat;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#door-wrap {
height: 295px;
width: 175px;
margin: 150px auto 0 auto;
perspective: 420px;
transform-style: preserve-3d;
}
#door {
height: 100%;
width: 100%;
background: url('https://keiraj87.github.io/website/door.png') top center no-repeat;
background-size: 175px;
animation: open-left 10s cubic-bezier(.06, .63, 0, 1) 0s 1 forwards;
margin-left: -88px;
}
#keyframes open-left {
from {
transform: rotateY(0deg) translateX(88px);
}
to {
transform: rotateY(-85deg) translateX(88px);
}
}
<div id="door-wrap">
<div id="door">
</div>
</div>

Text disappears behind image slidebar

I have a problem: I made a slidebar that shows the pictures. Now I want to continue underneath by putting text and other things on the page, but if I try to just insert a text below, for example, the text will not be written under the slideshow but under the slideshow.
Here is the code I hope you can help me.
div.slider {
display: flex;
width: 92%;
height: 750px;
margin-bottom: 20px;
margin-left: 4%;
margin-right: 4%;
margin-top: 20px;
background-color: #1f1f1f;
overflow: hidden;
position: absolute;
}
div.slider > * {
position: absolute;
display: flex;
widows: 100%;
height: 100%;
background: #1f1f1f;
animation: slide 12s infinite;
overflow: hidden;
}
div.slide:nth-child(1) {
left: 0%;
animation-delay: -1s;
background-image: url(https://wowslider.com/sliders/demo-7/data/images/amsterdam.jpg);
background-size: cover;
background-position: center;
}
div.slide:nth-child(2) {
left: 100%;
animation-delay: 2s;
background-image: url(https://wowslider.com/sliders/demo-7/data/images/barpark.jpg);
background-size: cover;
background-position: center;
}
div.slide:nth-child(3) {
left: 100%;
animation-delay: 5s;
background-image: url(https://wowslider.com/sliders/demo-7/data/images/florence.jpg);
background-size: cover;
background-position: center;
}
div.slide:nth-child(4) {
left: 100%;
animation-delay: 8s;
background-image: url(https://wowslider.com/sliders/demo-7/data/images/gate.jpg);
background-size: cover;
background-position: center;
}
div.slide p {
font-size: 70px;
text-align: center;
display: inline-block;
width: 100%;
margin-top: 340px;
color: #fff
}
#keyframes slide {
0% { left: 100%; width: 100%;}
5% { left: 0%;}
25% { left: 0%;}
30% { left: -100%; width: 100%;}
30.0001% { left: -100%; width: 0%;}
100% { left: 100%; width: 0%;}
}
<html>
<body>
<div class="slider">
<div class="slide"><p>Slide1</p></div>
<div class="slide"><p>Slide2</p></div>
<div class="slide"><p>Slide3</p></div>
<div class="slide"><p>Slide4</p></div>
</div>
<div>
<p>Text that should appear under the slideshow.</p>
</div>
</body>
</html>
Change position of div.slider to relative

Attach multiple divs and make them responsive

Hellow Guys,
I'm creating a loading animation with HTML and CSS. As I'm not really skilled in responsive front-end, I'm really struggling with making the text and the circle responsive.
What I really want is to attach the div with the background image and the text to the bar and make them responsive in order not to move and remain at the same position.
This is what I want to achieve:
Here's the code of what I have at the moment. I've tried attachment fixed and stuff like that, but the main problem is that the image keeps scaling when I use a max height/width and the text moves to the right depending on the width of the website.
Hope you can help me, thanks in advise.
body {
background: #111 url("");
background-size: 25vmin;
background-repeat: no-repeat;
background-position: center 40%;
height: 100vh;
margin: 0;
}
.logo {
background: url("https://openclipart.org/download/256338/whitecircle.svg");
background-size: 25vmin;
background-repeat: no-repeat;
position: absolute;
left: 28%;
bottom: 10vh;
height: 25vh;
width: 100px;
max-width: 150px;
}
h1 {
color: #fff;
position: absolute;
bottom: 20vh;
left: 35%;
}
.progress {
width: 400px;
max-width: 85vw;
height: 8px;
position: absolute;
bottom: 20vh;
left: 50%;
background: rgba(255, 255, 255, 0.5);
transform: translate(-50%, -50%);
overflow: hidden;
}
.progress:after {
content: '';
display: block;
width: 100%;
height: 8px;
background: #fff;
animation: load 5s linear;
}
#-moz-keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#-webkit-keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#-o-keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
<div class="logo"> </div>
<h1 class="title"> Loading </h1>
<div class="progress"> </div>
What I normally do to make an item responsive and many parts need to work closely together is, create a container which holds all items that are related. Then within the container I align item using % so they scale nicely. The main container (in my example called loader) I use width and height using the vh and vw units.
Here's one way you can solve this. I've also replaced the SVG with a circle made using css. This way you don't need to load the image. It will make your page less resource heavy. Let me know if you specifically want to use the SVG and I can update the example.
NOTE: I added a light border to the loader div so you can see how it resized when you resize the window. Remove it when you copy it to your page.
body {
height: 100vh;
margin: 0;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
}
.loader {
position: relative;
height: 30vh;
width: 50vw;
min-width: 200px;
min-height: 100px;
border: 1px solid #444; // added to see the responsiveness
}
.circle {
width: 55px;
height: 55px;
bottom: calc(40% - 27.5px);
left: -2px;
position: absolute;
border: 5px solid white;
border-radius: 50%;
}
h1 {
color: #fff;
position: absolute;
left: 75px;
bottom: 32%;
}
.progress {
position: absolute;
width: calc(100% - 60px);
height: 8px;
bottom: 40%;
left: 60px;
background: rgba(255, 255, 255, 0.5);
overflow: hidden;
}
.progress:after {
content: '';
display: block;
width: 100%;
height: 8px;
background: #fff;
animation: load 5s linear;
}
#-moz-keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#-webkit-keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#-o-keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
#keyframes load {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
<div class="loader">
<!--<div class="logo"> </div>-->
<!--<img class="img-logo" src="https://openclipart.org/download/256338/whitecircle.svg">-->
<div class="circle"></div>
<h1 class="title">Loading</h1>
<div class="progress"></div>
</div>

Issue to center a div horizontally

I'm trying to center my div .down-arrow horizontally but without success. The DIV is absolute positioned but margin:0px auto; does not seem to be working. What is the issue? thanks
http://jsfiddle.net/7UNrP/
HTML:
<header>
<div class="down-arrow">arrow</div>
</header>
CSS:
header {
position: relative;
width: 100%;
height: 600px;
min-height: 300px;
margin-right: auto;
margin-left: auto;
background-image: url('http://lorempixel.com/output/nature-q-c-1020-711-1.jpg');
background-size: cover;
background-position: center center;
background-color: rgb(222, 222, 222);
}
.down-arrow {
position: absolute;
margin:0px auto;
bottom: 20px;
display: inline;
padding: 10px;
color: #FFF;
border: 0;
font-weight: 400;
font-size: 12px;
background: red;
-webkit-animation: icon 1.2s infinite;
}
#-webkit-keyframes icon {
from {
opacity: 1;
bottom: 20px;
}
to {
opacity: 0;
bottom: 10px;
}
}
The problem is that you haven't told the arrow div where to be except bottom:20px so it defaults to left:0;
JSfiddle Demo
You need to add this to your arrow CSS
left:50%; /*push the div halfway over*/
-webkit-transform:translateX(-50%); /* bring it back by half its own width */
transform:translateX(-50%);
You might want to refer to this post which had much the same issue. I go into further detail regarding this solution.
Reference Question
The issue is due to using margin:0 auto with the display:inline and position: absolute. You can easily center it by applying text-align:center to the header as your inner content has an inline layout.
Example
You could use
text-align:center;
in header css like this
header {
position: relative;
width: 100%;
height: 600px;
min-height: 300px;
margin-right: auto;
margin-left: auto;
background-image: url('http://lorempixel.com/output/nature-q-c-1020-711-1.jpg');
background-size: cover;
background-position: center center;
background-color: rgb(222, 222, 222);
text-align: center;
}
EDIT:
This aligns the .down-arrow div in the center horizontally and keep it 20 pixel away from the bottom side of the its container
.down-arrow {
position: absolute;
margin-left: 50%;
/* bottom: 20px; */
/* display: inline; */
padding: 10px;
color: #FFF;
border: 0;
font-weight: 400;
font-size: 12px;
background: red;
-webkit-animation: icon 1.2s infinite;
}