I'm having trouble making my layout responsive
basically I only have one header and when I'm at lower resolutions the screen is completely buggy
the background which is 100vh and 100vw does not work
image:
in desktop resolution:
code:
function App() {
return (
<div className="Wrapper">
<div className="Header">
<div className="navtop Container">
<div className="LogoHeader">
<a>
<img className="img" src={Logo} />
</a>
</div>
<div className="SearchWrapper">
<form className="form">
<input className="input" />
</form>
</div>
<nav className="NavWrapper">a</nav>
</div>
</div>
</div>
);
}
css:
html,
body {
margin: 0;
padding: 0;
border: 0;
height: 100vh;
}
#root {
height: 100vh !important;
margin: 0 !important;
padding: 0 !important;
}
.Wrapper{
height: 100% !important;
background: red;
display: flex;
flex-flow: row wrap;
}
.Header{
width: 100%;
height: 140px;
color: rgb(255, 255, 255);
background: rgb(113, 89, 193);
transition: all 0.2s ease 0s;
}
.navtop{
height: 100%;
display: flex;
flex-direction: row;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
background:yellow;
}
.Container{
max-width: 1140px;
padding: 0px 30px;
margin: 0px auto;
}
.LogoHeader {
background: red;
display: flex;
align-items: center;
padding: 0 15px;
height: 100%;
min-width: 10em;
}
.img {
width: 150px;
}
.SearchWrapper {
background: yellow;
height: 100%;
display: flex;
align-items: center;
}
.input {
min-width: 200px;
}
.input:focus {
min-width: 300px;
}
.NavWrapper {
background: black;
height: 100%;
}
i really tried every possible solution i know i could change that with media queries
but i know i did something wrong in my css so i'm having this
I'm not exactly sure what you're aiming at, but there are at least 3 elements that are causing your header to not be able to shrink down fully to a mobile width below 440px.
Adjusting these 3 elements will get you going in the right direction, like so:
.LogoHeader {
background: red;
display: flex;
align-items: center;
padding: 0 15px;
height: 100%;
/*min-width: 10em;*/ /*REMOVE THIS LINE*/
width: 100%; /*ADD THIS*/
max-width: 10em; /*ADD THIS*/
}
.img {
/*width: 150px;*/ /*REMOVE THIS LINE*/
width: 100%; /*ADD THIS*/
max-width: 150px; /*ADD THIS*/
height: auto; /*ADD THIS */
}
.input {
/*min-width: 200px;*/ /*REMOVE THIS LINE*/
width: 100%; /*ADD THIS*/
max-width: 200px; /*ADD THIS*/
min-width: 50px; /*ADD THIS*/
}
Or you could adjust these elements in a media query, like so:
#media (max-width: 480px) {
.LogoHeader {
min-width: unset;
width: 100%;
max-width: 10em;
}
.image {
width: 100%;
max-width: 150px;
height: auto;
}
.input {
width: 100%;
max-width: 200px;
min-width: 50px;
}
}
Of course, you may want to adjust the values as needed and make some other modifications, but this should at lease allow the header to shrink down to mobile width.
The point here is that .img had a fixed with 150px and the input had a min-width of 200px, and the .LogoHeader had a min-width of 10em so those fixed widths and min-widths along with the padding of the .Container and .LogoHeader was not allowing your entire Header to shrink below 440px.
Related
I'm trying to create a menu inside CSS, and this is how my HTML skeleton looks like:
<body>
<div class="menu-container">
<ul class="menu-list">
<li class="menu-item">Item1</li>
<li class="menu-item">Item2</li>
<li class="menu-item">Item3</li>
</ul>
</div>
</body>
This is the part of CSS I'm focusing on:
.menu-container {
background-color: #e5e5e5;
width: 100%;
height: 4rem;
position: fixed;
bottom: 0;
display: flex;
align-items: center;
}
.menu-list {
margin: 0 auto;
}
.menu-item {
display: inline-block;
}
.menu-item:not(:last-child) {
margin-right: 5vw;
}
.menu-item:hover {
background-color: red;
}
Basically, what I'm trying to achieve is setting the background color of each element to red, on element hover (<li>). The problem is, the background color seems not to fill the whole height of its parent (the menu-container), although this is what I actually want to do.
I tried setting the menu-item padding to 100%, but it just fills the whole screen. It isn't relative to menu-container's height.
To be more precise, this is how it looks like:
But I want the red background's height all over the div, like this:
What can I do, in order to achieve that? Thank you.
So, Instead of giving a fixed height to parent div. I adjust this using by adding padding from the top and bottom to each lielement.
Made some changes on CSS Have a look the snippet below:
.menu-container {
background-color: #e5e5e5;
width: 100%;
position: fixed;
bottom: 0;
display: flex;
align-items: center;
}
.menu-list {
margin: 0 auto;
}
.menu-item {
display: inline-block;
padding: 1.25rem 0;
}
.menu-item:not(:last-child) {
margin-right: 5vw;
}
.menu-item:hover {
background-color: red;
}
<body>
<div class="menu-container">
<ul class="menu-list">
<li class="menu-item">Item1</li>
<li class="menu-item">Item2</li>
<li class="menu-item">Item3</li>
</ul>
</div>
</body>
Just add height:100% to both menu-list and menu-item. In case you want the item to be centered instead of sticking to the top you can use a display: flex and align-items: center, justify-content:center
.menu-container {
background-color: blue;
width: 100%;
height: 4rem;
position: fixed;
bottom: 0;
display: flex;
align-items: center;
justify-content:center;
}
.menu-list {
height: 100%;
background-color:yellow;
display:flex;
align-items: center;
justify-content:center;
}
.menu-item {
display: flex;
align-items:center;
justify-content:center;
height:100%;
background-color:green;
}
.menu-item:not(:last-child) {
margin-right: 5vw;
}
.menu-item:hover {
background-color: red;
}
You can make your CSS like this,
Giving the height to 100% will take 100% height of the parent element.
I am trying to fix your css, please check my solution -
.menu-container {
background-color: #e5e5e5;
width: 100%;
height: 4rem;
position: fixed;
bottom: 0;
display: flex;
align-items: center;
}
/* at first you inline the whole ul */
.menu-list {
margin: 0 auto;
display: flex;
list-style: none;
}
/* then center the options & set full height */
.menu-item {
display: flex;
align-items: center;
height: 4rem;
cursor: pointer;
padding: 0 1rem;
}
.menu-item:not(:last-child) {
margin-right: 5vw;
}
.menu-item:hover {
background-color: red;
}
Solution 2
.menu-container {
background-color: #e5e5e5;
width: 100%;
position: fixed;
bottom: 0;
display: flex;
align-items: center;
}
/* set full height */
.menu-list {
margin: 0 auto;
height: 100%;
}
/* set full height also */
.menu-item {
display: inline-block;
padding: 1.25rem 0;
height: 100%;
}
.menu-item:not(:last-child) {
margin-right: 5vw;
}
.menu-item:hover {
background-color: red;
}
I have a div with a text on the left part of it:
* {padding: 0%;margin: 0%;}
body {background-color: brown;}
.content_box {
height: 100%;
display: flex;
flex-direction: row;
background-color: brown;
padding: 1em;
border-radius: 0.5rem;
}
.content_box div {
display: flex;
flex-direction: column;
overflow: hidden;
margin-right: 1rem;
}
.content_box img {
object-fit: cover;
width: 30%;
/*height: 100%;
width: auto;
max-width: 100%;*/
}
.content_box .credentials {color: beige;}
.content_box .left {margin-left: auto;}
.content_box .right {margin-right: 100px;}
<div class='content_box'>
<div class='left'>
<div class='credentials'>Username</div>
<p>Posted message</p>
<div class='credentials'>01/01/2021</div>
</div>
<div class='right'>
...
</div>
</div>
I want to add an image on the right part of it. But it has to be set to the size of text(so if we have three lines of text image will be bigger than if we had one line of text, even if the image with 3 lines is 30x30 pixels, and 1 line text is 1024x1024 pixels)
I would love it if someone could edit my question because I'm not too good at English...
You could position the .content_box relative and the .right div absolute. So you can give it the height of it's parent. Finally give the image a max-height of 100%:
.content_box {
position: relative;
height: auto;
}
.right {
position: absolute;
height: 100%;
width: auto;
top: 0;
right: 0;
background-color: red;
}
.right img {
max-height: 100%;
width: auto;
}
I am creating a social site and people can upload images. When they upload those image it is inside of a div. How do I fill the whole div up so i don't see white spaces on the sides ?
This is how it looks now:
First Example
Second e.g
My code:
.postedImageDiv {
max-width: 500px;
overflow: hidden;
max-height: 400px;
border-radius: 10px;
border: 1px solid gray;
background: #fff;
margin-bottom: 1em;
}
.profilePostedImage img {
max-height: 450px;
max-width: 450px;
display: block;
margin: 5px auto;
}
.postedImage img {
align-self: center;
object-fit: contain;
max-height: 600px;
max-width: 600px;
display: block;
margin: 5px auto;
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
You might try these:
max-width: 100%;
max-height: 100%;
display: block;
.outside {
max-width: 500px;
overflow: hidden;
max-height: 400px;
border-radius: 10px;
border: 1px solid gray;
background: #fff;
margin-bottom: 1em;
}
.img-inside{
width: 100%;
height: 100%;
display: block;
}
<!-- vertical image example -->
<div class="outside">
<img class="img-inside" src="https://i.guim.co.uk/img/media/86c3481516dce247943ac2978b4f48d16a3ac265/0_170_5120_3074/master/5120.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=637dc5731d52754675ef36344a6af3c8">
</div>
<!-- landscape image example -->
<div class="outside">
<img class="img-inside" src="https://www.straight.com/files/v3/styles/gs_standard/public/images/15/03/shutterstock_grizzlybear_0.jpg?itok=vz6hpl50">
</div>
this is what I have:
.thumbnail {
height: 600px;
width: 60%;
overflow: hidden;
}
.thumbnail img {
height: 600px;
width: auto;
}
the width of the image can be any size, maybe larger then the container div. how can I center it?
Use Flex for simple, as your question, assume image free size (No CSS set)
.thumbnail {
height: 600px;
width: 60%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.thumbnail {
height: 600px;
width: 60%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
<div style="width: 300px;">
<div class="thumbnail"><img src="https://homepages.cae.wisc.edu/~ece533/images/airplane.png" /></div>
</div>
try adding this
.thumbnail img {
height: 600px;
width: auto;
display:block;
margin: 0 auto;
}
I have a layout wherein the container has a fixed height and width of 640px x 480px. Inside this container are 3 divs, top, mid and bot. I want this 3 divs to fit inside the container provided that they will not overflow the container. The top and bot div doesn't have fixed height while the mid should fit the space between and push top and bot.
What I've already tried was like this:
HTML
<div class="main">
<div class="top">
</div>
<div class="mid">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Chestnut-breasted_Malkoha2.jpg/593px-Chestnut-breasted_Malkoha2.jpg" />
</div>
<div class="bot">
</div>
</div>
CSS
.main {
padding: 10px;
width: 640px;
height: 480px;
display: inline-block;
background: #000;
position: relative;
}
.top {
width: 100%;
height: 50px;
display: block;
background: #eee;
}
.mid {
width: 100%;
height: 100%;
display: block;
background: #333;
}
img {
max-width: 100%;
max-height: 100%;
margin: 0 auto;
display: block;
}
.bot {
width: 100%;
height: 50px;
display: block;
background: #ccc;
}
FIDDLE HERE
Now my problem is the mid push the bot outside the container. How can i make them fit inside the container without using overflow: hidden? Thanks in advance.
NOTE : the image should fit inside the mid container.
UPDATE top and bot div can contain paragraphs so it's not fixed height.
Check this sample:
http://jsfiddle.net/J6QTg/8/
.main {
padding: 50px 0px;
width: 640px;
height: 480px;
display: block;
background: #000;
position: relative;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.top {
width: 100%;
height: 50px;
display: block;
background: #eee;
position: absolute;
top : 0;
left : 0;
}
.mid {
width: 100%;
height: 100%;
display: block;
background: #333;
}
img {
max-width: 100%;
max-height: 100%;
margin: 0 auto;
display: block;
}
.bot {
width: 100%;
height: 50px;
display: block;
background: #ccc;
position: absolute;
bottom : 0;
left : 0;
}
Update:
It is also possible to use tables, to have more flexible boxes.
http://jsfiddle.net/jslayer/U3EaZ/
HTML:
<div class="box">
<div class="h"> Hello<br/>Cruel<br/>World </div>
<div class="m">
<img src="http://goo.gl/a1smCR" alt="" />
</div>
<div class="b"> Omg </div>
</div>
CSS:
.box {
display: table;
width: 640px;
height: 480px;
background: red;
}
.h, .m, .b {
display: table-row;
}
.h {
background: yellow;
height: 0;
}
.m {
background: green;
}
.m img {
max-width: 100%;
height: 100%;
max-height: 100%;
margin: 0 auto;
display: block;
}
.b {
background: blue;
height: 0;
}
I would use JavaScript/JQuery: FIDDLE
I've used JQuery for simplicity, but it can probably be done with just JavaScript...
var totalheight = eval($('.main').height() - $('.top').outerHeight(true) - $('.bot').outerHeight(true))
$('.mid').outerHeight(totalheight);
Try to set the height of mid based on the container.
.mid {
width: 100%;
height: 383px;
display: block;
background: #333;
}
FIDDLE
If the container has a fixed height and width, then you can set the height to 79.25% like this:
.mid {
max-width: 100%;
height: 79.25%;
display: block;
background: #333;
}
demo