So, I want this picture in the middle of the screen. slightly above the middle of the page. it works for other screen sizes but for this size 1024px it only stays at the top of the screen unless I use bottom: (some px height); but all of my other pages don't need it. I was wondering if anyone knew a way to move this to the middle of the screen but slightly higher than the exact middle of the screen without for example bottom: 140px. if not that fine also can someone show me how to optimize this I know my code is sloppy and can use some work and can be better equipped to handle different sizes of pages. 1024 or 2000px for example. Thank you
#media only screen and (max-device-width: 1024px){
#logo {
position: relative;
bottom: 700px;
}
#logo img{
position: relative;
width: 9%;
height: auto;
bottom: -20px;
}
#header_size{
width: 70%;
height: auto;
margin-left: auto;
margin-right: auto;
}
#border{
border-radius: 30px;
border: 10px;
border-color: black;
border-style: double;
width: 100%;
height: 100%;
}
.right_and_margin {
margin:0 auto;
width: 40%;
height: 20%;
}
.forum_styling{
height: 55px;
width: 600px;
font-size: 25pt;
}
p {
font-size: 22pt;
font-weight: bold;
color: white;
margin-top: 5%;
}
}
<div class="right_and_margin">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg/250px-Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg
" alt="Image" id="border">
<p>Thank you for the help</p>
</div>
if i correctly understand you here is a solution. In flexbox we trust :)
html,
body {
height: 100%;
margin: 0;
}
.right_and_margin {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
<div class="right_and_margin">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg/250px-Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg" alt="Image" id="border">
<p>Thank you for the help</p>
</div>
Have a look at flexbox for horizontal and vertical alignment. Should be simple to add the following properties to the right element for your needs:
display: flex;
justify-content: center;
align-content: center;
Ressource: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Related
I'm trying to create a banner that has two buttons on it:
.banner {
width: 100%;
display: flex;
flex-direction: column;
margin-top: -4%;
}
.banner img {
width: 100%;
/*image is 1232x317 by default and defines the size of the banner*/
}
.banner-buttons {
display: flex;
flex-direction: row;
margin-left: 6.2%;
position: absolute;
top: 10%;
}
.banner button {
display: flex;
font-size: 200%;
border: none;
border-radius: 5px;
font-weight: bold;
align-items: center;
padding: 5px 15px;
}
<div class="banner">
<img src="https://picsum.photos/1200/300">
<div class="banner-buttons">
<button>Assistir</button>
<button>Mais Informações</button>
</div>
</div>
but the problem is, the height of the buttons change based on the viewport, destroying the banner, how can I position it without ruining it?
I would personally avoid absolute positioning and use background image to create the layers.
You can set a min height on your banner if you desire.
I would also use em and media queries to reduce the font size when the screen resolution is smaller.
.banner {
background:url(https://picsum.photos/1200/300);
padding:10px;
}
.banner-buttons {
display: flex;
justify-content:center;
align-items: center;
}
.banner button {
font-size: 2em;
border: none;
border-radius: 5px;
font-weight: bold;
padding: 5px 15px;
margin:5px;
}
<div class="banner">
<div class="banner-buttons">
<button>Assistir</button>
<button>Mais Informações</button>
</div>
</div>
Actually what solved for me was adding position: relative to .banner, now the buttons are displayed at the exact same position at every screen size.
Been attempting to layer and image over the top left corner of a div container; iv achieved it once but it didn't stick to position if the page was adjusted!
^^ This is what im redesigning
^^ This is what ive managed to design myself
I have come across different posts and answers suggesting that I try to use:
display: block, relative
position: block, relative
margins, float: start
In the end I am stumped an have resorted to removing most displays besides for the p tags an its composed container:
This is the CSS I have been trying to use to make this happen
.roadmap__section__container {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
min-height: 100%;
max-height: 100%;
background-color: #383636;
align-items: center;
}
.roadmap__header {
font: 3rem "Nunito";
margin: 3% 50% 3% 50%;
}
.roadmap__phase__one {
width: 100%;
height: 100%;
}
.phase__one__img {
width: 10%;
position: absolute;
margin-left:10%;
}
.phase__one__data {
display: flex;
flex-direction: column;
width: fit-content;
height: fit-content;
align-items: flex-start;
justify-content: center;
text-align: center;
padding: 25px;
margin: 0% 5% 5% 15%;
box-shadow: 1px 1px 40px #ff00e6;
outline-color: #ff00e6;
outline-offset: 0px;
outline-style: solid;
outline-width: 3px;
border-radius: 25px;
}
.phase__one__data p {
font-size: 1.75rem;
color: #fff;
font-family: "Nunito", serif;
padding: 5px 10px;
}
Here is the HTML Code used for my redesign:
<section class="roadmap__section__container">
<h1 class="roadmap__header">Roadmap</h1>
<div class="roadmap__phase__one">
<img class="phase__one__img" src="images/CasinoWRLD__dice1" alt="">
<div class="phase__one__data">
<p>- Working To Perfect The NFT Artwork.</p>
<p>- Finalise The Marketing Plan.</p>
<p>- Plan And Develop Casino WRLD.</p>
</div>
</div>
</section>
.phase__one__img {
grid-column: 3;
width: 11%;
position: absolute;
top: 157.5%;
right: 32%;
}
.phase__zero__img {
grid-column: 1;
width: 11%;
position: absolute;
margin-left: 5%;
top: 119.75%;
}
I've found this to work currently but it is not a 100% answer, if the browser height is adjust the settings regarding ''top:157.5%'' needs to be adjusted accordingly or it will not line up with the top-left corner of the div container
The difference in the two is pertaining to it switches back and forth going down the page
on my website, I want to have 6 'image boxes' (3 in one 'row' and 3 in below 'row'). When I change the size of my screen/tab then these 6 image boxes should be always seen completely. They should always fit into the screen size. My code works somehow but not on the bottom. Only one part of the cards in the second row can be seen after decreasing screen size after a certain amount.
Also, I want my content to take 100% of the screen without a scroll bar popping up.
The web content is divided into 2 parts: The top layout and the imagebox.
this is basically my css-file:
* {
font: 18px Verdana;
font-size: 22px;
}
html{
height: 100%;
}
body {
font: 18px Verdana;
height: 100%;
margin-left: 30px;
margin-right: 30px;
margin-bottom: 30px;
margin-top: 30px;
overflow: hidden;
}
#topLayout {
height: 190px;
margin-bottom: 10px;
}
#imagebox {
height: 80%;
margin-bottom: 0px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.box{
cursor: pointer;
flex: 0 1 32.5%;
margin-top: 1.2%;
}
and this is my html code:
<body>
<div id="topLayout">
<div id="block1">
.....
</div>
<div id="block2">
....
</div>
</div>
// the images are appended to the imagebox tag in the .js file via a
function
<div id="imagebox"></div>
</div>
Thank you very much in advance.
Maybe it helps you. Try this
#imagebox {
position: absolute;
width: 100%;
top: 230px;
bottom: 0;
left: 30px;
right: 30px;
}
Here is a example
I have two elements that I want to place next to each other - one is a logo, the other is an "overflow" menu that will display a dropdown when clicked.
I want to have them scale so that the logo is at most 400px wide, and the menu button is always 1.5em wide and tall. The logo should stay vertically center aligned with the menu button, and the button should always be at the far right of the parent.
Tried using flexbox but I'm no CSS genius, I can't make it work. (btw, will we ever see CSS being more like the Android XML layout system? It'd be a breeze to use a LinearLayout with some gravity and weight to do something like this. With CSS it seems you always have to resort to hacks and hard-to-read solutions at some point)
So this is what it would look like when the logo is at it's maximum 400px width:
And here is what it would look like on a phone, where the logo needs to shrink to make room for the menu button:
Here's a solution using flexbox.
.header {
display: flex;
flex-direction: flex-end;
justify-content: space-between;
}
.logo {
background-image: url(http://placehold.it/400x50);
background-position: center;
background-repeat: no-repeat;
background-size: contain;
height: 50px;
max-width: 400px;
width: 100%;
}
.menu-toggle {
background-color: orange;
flex-shrink: 0;
height: 50px;
margin-left: 10px;
width: 50px;
}
<div class="header">
<div class="logo"></div>
<div class="menu-toggle"></div>
</div>
An easy way to do it is here.
.header{
margin:0px !important;
padding: 0px !important;
display: table;
width: 100%;
height: 1.5em;
overflow-y: hidden;
box-shadow: 0 1mm #aaa 5px;
vertical-align: middle !important;
position: relative;
}
#img-holder{
display: table-cell;
vertical-align: middle;
height : 100%;
background-color : blue;
max-width : 400px;
min-width : 250px;
padding: 0px !important;
}
#img {
display: table-cell;
max-width: 350px;
min-width: 150px;
height: 0.75em!important;
vertical-align: middle;
background-color: pink;
}
#menu-btn{
display: block;
margin: auto;
float: right;
height: 1.5em;
width: 1.5em;
background-color: orange;
border:none;
margin: 0px !important;
padding: none;
}
<div class="header">
<div id="img-holder"><span id="img"> Your Img</span></div>
<a id="menu-btn"></a>
</div>
I used line-height and vertical-align with calc.
html:
<div class="row">
<div class="menu-button"></div>
<div class="logo">
<img src="http://placehold.it/400x70">
</div>
</div>
css:
.menu-button {
background-color: #ffa200;
float: right;
height: 70px;
width: 70px;
}
img {
display: inline-block;
max-width: 100%;
vertical-align: middle;
}
.logo {
float: left;
height: 70px;
line-height: 70px;
max-width: calc(100% - 80px);
}
Demo: https://jsfiddle.net/sabeti05/1yg32uqo/
Below is a simple html web page that is responsive except for one div (goplay) that over lays other parts of the page when screen size is reduced, instead of dropping below the image.
Styling Sheet external
#wrapperlp {
width: 100%;
margin: auto;
}
#media screen and (max-width: 800px) {
#wrapperlp {
width: 90%;
min-width: 100px;
}
}
#headerlp {
font-size: 30px;
color: white;
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
}
#para {
font-size: 20px;
color: white;
text-align: center;
}
#game_img {
height: 250px;
width: auto;
margin-bottom: -30px;
position: relative;
display: inline-block;
float: left;
margin-top:-30px;
padding-top: 5px;
max-width: 100%;
}
#goplay {
position: relative;
display: inline-block;
float: right;
margin-top:-250px;
margin-left:80px
}
#spacer {
height: 40px;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 900px;
padding-top:20px;
}
Html which is set to call the above css
<div id="wrapperlp">
<div style="background-image: url(https://.jpg); height: 430px; width: 1000px; margin-left: auto; margin-right: auto; max-width: 100%;">
<div id="headerlp">Some Text</div>
<div id="para">More Text</div>
<div id="game_img"><a href="//www.youtube.com/" target="_blank"><br />
<img src="https://.png" height="auto"/></a></div>
</div>
</div>
<div id="goplay">----form----/div>
<div id="spacer">
<div style="position: relative; float: left">Text</div>
</div>
margin-top and left should in %. thats y its overlay becoz of px
First off, it looks like you're missing a couple of divs.
The goplay div doesn't have a closing tag, (well it's got one but not that works)
Also your bottom spacer looks like it's missing a closing tag as well. Not sure if it's supposed to wrap anything or what.
Perhaps you had some copy/paste errors?
Normally if you set a negative margin it will overwrite other divs. You should, for the most part, not have to use negative margins.