I'm having a problem with my flex container basically just leaving the page and going like this:
I tried setting display to table and using <td> elements to put my things in, but it stayed out of the frame. I want it to be a flex container that will contain the first <div>, and the <header>s.
HTML:
<div class="presen">
<div class="tisane"> <!--overlap d'images-->
<img id="img1" src="images/herbal-tea-cup-png-images-35.png" alt="Tasse d'infusion de millepertuis" />
<img id="img2" src="images/noircontourthe.png" alt="" />
</div>
<header>
</header>
</div>
CSS of relevant elements:
.tisane {
display: inline-flex;
}
.tisane img#img1 {
display: block;
margin-left: auto;
margin-right: auto;
width: 300px;
height: 220px;
position: absolute;
top: 300px;
left: 140px;
z-index: 2;
}
.tisane img#img2 {
display: block;
margin-left: auto;
margin-right: auto;
width: 330px;
height: 230px;
position: absolute;
top: 298px;
left: 130px;
z-index: 1;
}
header h1 {
text-align: center;
}
.presen {
display: flex;
flex-direction: column;
top: 298px;
padding: 0;
}
Thanks.
You need to set the height of your body and presen class.
.tisane {
display: inline-flex;
}
.tisane img#img1 {
display: block;
margin: 0 auto;
width: 300px;
height: 220px;
position: absolute;
top: 300px;
left: 140px;
z-index: 2;
}
.tisane img#img2 {
display: block;
margin-left: auto;
margin-right: auto;
width: 330px;
height: 230px;
position: absolute;
top: 600px;
left: 130px;
z-index: 1;
}
header h1 {
text-align: center;
}
.presen {
display: flex;
flex-direction: column;
top: 298px;
padding: 0;
height: 100%; //The height of a flexbox can be also set to a percentage
}
body {
height: 100vh;
}
<div class="presen">
<div class="tisane"> <!--overlap d'images-->
<img id="img1" src="https://via.placeholder.com/250" alt="Tasse d'infusion de millepertuis" />
<img id="img2" src="https://via.placeholder.com/250" alt="" />
</div>
<header>
</header>
</div>
Related
I have 2 parent containers in my code below. The first one is just for reference for what I want my second container to look like. The difference between the two is the first one I used absolute positioning and flex display but the second one is grid display. What I'm stuck on is understanding how to center class .item1 and position class .item2 all the way to the right just how it's like on the first parent container i.e class .topAdCon. My specific questions are 1) how to center .item1
2) how to set .item2's position all the way to the right (right: 0%)
3) on the first parent container I just set top: 0% to align it all the way to the top because it has absolute positioning how can I set the positioning of the second parent container where ever I want currently I'm using margin-top for top positioning is that the way to go or what is the right way?
4) Lastly how do I set the height for the second container because height isn't responding as it does on the first container?
Note: I commented out things I tried in order to achieve these things but they aren't working.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.topAdCon {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0%;
width: 100%;
height: 18%;
background-color: pink;
}
.topAdCon .adCon {
width: 40%;
height: 100%;
}
.topAdCon .adCon img {
width: 100%;
height: 100%;
}
.topAdCon .sideInfo {
display: flex;
text-align: center;
width: 17%;
height: 100%;
position: absolute;
right: 0%;
border: 1.5px solid #000000;
}
.topAdCon .sideInfo p {
font-size: 0.9vw;
margin: auto;
}
.wrapper {
display: grid;
align-items: center;
justify-content: center;
/*position: relative;
top: 20%;*/
margin-top: 20%;
grid-template-columns: 40% 17%;
width: 100%;
height: 18%;
/*height not responding*/
background-color: gold;
}
.item1 {
/*align-self: center;*/
width: 100%;
height: 100%;
}
.item1 img {
width: 100%;
height: 100%;
}
.item2 {
display: flex;
text-align: center;
/*align-self: flex-end*/
width: 100%;
height: 100%;
border: 1.5px solid #000000;
}
.item2 p {
font-size: 1.5vw;
margin: auto;
}
<div class="topAdCon">
<div class="adCon">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="sideInfo">
<p>this is test statement 1</p>
</div>
</div>
<div class="wrapper">
<div class="item1">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="item2">
<p>this is test statement 2</p>
</div>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.topAdCon {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0%;
width: 100%;
height: 18%;
background-color: pink;
}
.topAdCon .adCon {
width: 40%;
height: 100%;
}
.topAdCon .adCon img {
width: 100%;
height: 100%;
}
.topAdCon .sideInfo {
display: flex;
text-align: center;
width: 17%;
height: 100%;
position: absolute;
right: 0%;
border: 1.5px solid #000000;
}
.topAdCon .sideInfo p {
font-size: 0.9vw;
margin: auto;
}
.wrapper {
display: grid;
margin-top: 20%;
grid-template-columns: 30% 40% 12% 18%;
grid-template-areas: 'item item1 item2 item3';
width: 100%;
height: 18vh;
background-color: gold;
}
.item1 {
width: 100%;
height: inherit;
}
.item1 img {
width: 100%;
height: 100%;
}
.item3 {
display: flex;
text-align: center;
justify-content: end;
width: 100%;
height: inherit;
border: 1.5px solid #000000;
}
.item3 p {
font-size: 1.5vw;
margin: auto;
}
<div class="topAdCon">
<div class="adCon">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="sideInfo">
<p>this is test statement 1</p>
</div>
</div>
<div class="wrapper">
<div class="item"></div>
<div class="item1">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="item2"></div>
<div class="item3">
<p>this is test statement 2</p>
</div>
</div>
I have a navbar with a scrollable dropdown item(cart view) to the right side of it.
The problem is that if there are more than one item in the cart, the top part of the dropdown it is not visible anymore.
Could you please tell me where is the problem?
This is the html:
<body>
<div id="root">
<div class="App">
<nav>
<div class="links">
Something, something
</div>
<div class="asd">
bla
</div>
<div class="grand-parent">
<div class="bro">
bla
</div>
<div>
</div>
<div class="dropdown">
<div class="dropdown-content">
</div>
</div>
</div>
</nav>
</div>
</div>
</body>
And this is the CSS:
.App {
padding: 0;
margin: 0;
color: #1D1F22;
}
nav {
display: flex;
position: fixed;
justify-content: space-between;
z-index: 9990;
top: 0;
width: 100%;
background-color: white;
font-size: 1.2rem;
margin-left: 70px;
height: 80px;
}
.links {
justify-self: flex-start;
position: relative;
}
.asd {
align-self: center;
position: relative;
}
.grand-parent {
right: 100px;
text-align: center;
position: relative;
height: 90vh;
}
.bro {
position: relative;
padding: 0;
height: 3px;
width: 6px;
margin-right: 170px;
margin-top: 30px;
}
.dropdown {
position: absolute;
display: inline-block;
height: 90vh;
}
.dropdown-content {
margin-top: 0px;
display: flex;
flex-direction: column;
position: absolute;
right: 0;
width: 325px;
z-index: 9999;
border: 1px solid black;
justify-content: center;
align-items: center;
max-height: 90vh;
overflow-y: auto;
background-color: white;
overflow-x: hidden;
}
The project is done in ReactJS, but I think that this is not so important.
Thank you!
You centered vertically your elements in .dropdown-content with justify-content: center;
To fix it, you need to change it to justify-content: flex-start; and normally it'll works.
Here's my code for my small project (I'm very new to this):
body {
background-color: #242424;
}
.page-wrap {
width: 90%;
margin: 0 auto;
height: 98vh;
}
.buildings-wrap {
width: 95%;
margin: 0 auto;
height: 100%;
text-align: middle;
}
.rectangle {
height: 650px;
background-color: lightblue;
width: 215px;
}
.add_btn {
border-radius: 50%;
background-color: lightcyan;
text-align: center;
line-height: 150px;
height: 150px;
width: 150px;
margin: 0 auto;
font-size: 100px;
font-weight: 900;
position: fixed;
top: 85%;
}
<div class="page-wrap">
<div class="buildings-wrap">
<br/>
<div class="rectangle"></div>
<hr style="position: fixed;top: 80%;color: white;width: 84%;" />
<button class="add_btn">+</button>
</div>
</div>
Here's what it looks like. The arrow show where I would like them to be.
I can't figure out how to do this:
In order to align the rectangle above the hr tag, you can simply give it a display of block and a margin of auto. This will center the rectangle relative to the container.
As for aligning the add button to the center while keeping it fixed, you can wrap the button in a div, give that div a position of fixed and a width of 100%. Then give it a display of flex and justify-content of center. This will center align any children that are in the div.
Depending on how low you want the add button, you can set the bottom property for the newly create div. At the moment I have it at -125px. It's also better to use bottom and pixels as the units because the other elements have fixed sizes.
body{
background-color: #242424;
}
.page-wrap {
width: 90%;
margin: 0 auto;
height: 98vh;
}
.buildings-wrap{
width: 95%;
margin: 0 auto;
height: 100%;
text-align: middle;
}
.rectangle{
height: 650px;
background-color: lightblue;
width: 215px;
display: block;
margin:auto;
}
.add_btn{
border-radius: 50%;
background-color: lightcyan;
text-align: center;
line-height: 150px;
height: 150px;
width: 150px;
margin: 0 auto;
font-size: 100px;
font-weight: 900;
}
hr{
margin: 0 auto 0 auto;
}
<div class="page-wrap">
<div class="buildings-wrap">
<br/>
<div style="display: flex; margin: auto;"><div class="rectangle"></div></div>
<hr/>
<div style="width: 100%; display:flex; justify-content: center;position: fixed; bottom: -125px; left: 0;"><button class="add_btn">+</button></div>
</div>
</div>
Please view in full-page view
Hope this helps
body {
background-color: #242424;
}
.page-wrap {
width: 90%;
margin: 0 auto;
height: 98vh;
}
.buildings-wrap {
width: 95%;
margin: 0 auto;
height: 100%;
text-align: center;
display: flex;
justify-content: center;
}
.rectangle {
height: 81vh;
background-color: lightblue;
width: 200px;
}
.add_btn {
border-radius: 50%;
background-color: lightcyan;
text-align: center;
line-height: 50px;
height: 16vh;
width: 120px;
margin: 0 auto;
font-size: 100px;
font-weight: 600;
position: fixed;
top: 84%;
}
<div class="page-wrap">
<div class="buildings-wrap">
<br/>
<div class="rectangle"></div>
<hr style="position: fixed;top: 80%;color: white;width: 84%;" />
<button class="add_btn">+</button>
</div>
</div>
I am currently attempting to make my website responsive i.e. images scale up and down with page resizing, content stacks above each other, etc. I was under the impression that I had taken the appropriate steps, but the elements are still stretching in size when resizing and the contents are not staying in their original positions.
How can I achieve this result while keeping all of my elements intact?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-image: url(img/food-background.jpg);
background-attachment: fixed;
height: 100%;
}
.main-content {
display: flex;
flex-wrap: wrap;
}
.container {
margin-left: auto;
margin-right: auto;
width: 1140px;
}
.Navbar {
text-align: center;
display: block;
margin-top: 2%;
}
#center-logo {
width: 100%;
max-width: 200px;
height: auto;
text-align: center;
}
#Navbar_Link-Toggle {
display: none;
}
img {
width: 40%;
}
.links {
text-decoration: none;
font-size: 13px;
color: black;
font-weight: bold;
padding: 25px;
}
.links:hover {
color: #f58300
}
a:visited {
color: black;
}
.header {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
margin-top: 3%;
height: auto;
background-color: yellow;
}
#food {
height: 65vh;
width: 100%
}
.footer {
margin-top: 100%;
bottom: 0;
width: 100%;
text-align: center;
font-size: 10px;
margin-left: auto;
margin-right: auto;
background-color: #f7f7f7;
}
.top {
float: left;
width: 100%;
}
#olive-green {
margin-top: 5%;
position: absolute;
right: 50px;
max-width: 450px;
}
#coral {
max-width: 450px;
position: absolute;
left: 50px;
margin-top: 5%;
}
#teal {
max-width: 450px;
position: absolute;
left: 50px;
margin-top: 50%;
}
#honey {
margin-top: 50%;
position: absolute;
right: 50px;
max-width: 450px;
}
.images {
content: "";
clear: both;
display: table;
}
#media screen and (max-width: 900px) {
.top {
width: 100%;
}
.bottom {
width: 100%;
}
}
<div class='main-content'></div>
<div id='Navbar_Link-Toggle' style='font-size: 20px'>
<i id='main' class='fas fa-bars'></i>
</div>
<div class='container'>
<div class='Navbar'>
<a class='links' href=''>FOOD</a>
<a class='links' href=''>FUN</a>
<img id='center-logo' src='img/SAMO.png'>
<a class='links' href=''>HISTORY</a>
<a class='links' href=''>LOCATION</a>
</div>
</div>
<div class='header'>
<img id='food' src='img/food.jpg'>
</div>
<div class='images'>
<div class='top'>
<img id='coral' src='img/coral.png'>
<img id='olive-green' src='img/olive-green.jpg'>
</div>
<div class='middle'>
<img id='teal' src='img/teal.jpg'>
<img id='honey' src='img/honey.jpg'>
</div>
</div>
</div>
<div class='footer'>
<p>200 Santa Monica Pier, Suite A Santa Monica, CA 90401</p><br>
<p>Questions? Drop us a message at: info#santamonicapier.org or 310-458-8900</p><br>
<p>All Rights Reserved © 2019 Santa Monica Pier</p>
</div>
You have an extra closing div on the first line of your HTML. So your .main-content element is actually being closed right away instead of wrapping around the rest of the elements.
How do I make the content take up the margin space when the browser is resized smaller?
http://jsfiddle.net/denWG/62/
Html:
<div class="jp-sleek jp-jplayer jp-audio">
<div class="jp-gui">
<div class="jp-controls jp-icon-controls">
<div class="jp-progress">
</div>
</div>
</div>
</div>
CSS:
.jp-jplayer {
min-width: 900px;
}
.jp-sleek .jp-gui {
height: 42px;
background-color: #e5e5e5;
position: relative;
}
.jp-sleek .jp-gui .jp-controls {
height: 100%;
position: relative;
margin: 0 auto;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
width: 50%;
}
.jp-sleek .jp-gui .jp-icon-controls .jp-progress {
background-color: green;
height: 100%;
width: 600px;
min-width: 240px;
position: relative;
}
Here's what it does at the moment:
I want the margins on the left and right to shrink down and for the green bar to get bigger and take up more margin space until it's 100% as the screen size gets smaller.
You need to set width: 100%; to .jp-jplayer and min-width: 450px to .jp-sleek .jp-gui .jp-controls:
.jp-jplayer {
width: 100%;
}
.jp-sleek .jp-gui {
height: 42px;
background-color: #e5e5e5;
position: relative;
}
.jp-sleek .jp-gui .jp-controls {
height: 100%;
position: relative;
margin: 0 auto;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
width: 50%;
min-width: 450px;
}
.jp-sleek .jp-gui .jp-icon-controls .jp-progress {
background-color: green;
height: 100%;
width: 600px;
min-width: 240px;
position: relative;
}
<div class="jp-sleek jp-jplayer jp-audio">
<div class="jp-gui">
<div class="jp-controls jp-icon-controls">
<div class="jp-progress">
</div>
</div>
</div>
</div>