How to make rows in a grid stack without grid-template-row? - position

I'm trying to make .item-1 and .item-2 stack nicely on top of each other in a grid, just like in this snippet:
.grid {
display: grid;
gap: 10px;
grid-template-columns: repeat(6, 1fr);
grid-template-rows: auto 1fr;
}
.item {
padding: 10px;
border: 1px solid black;
}
.item-1 {
grid-column: 1 / 3;
}
.item-2 {
grid-column: 1 / 3;
}
.item-3 {
grid-column: 3 / 7;
grid-row: 1 / 3;
padding: 80px 20px;
}
<div class="grid">
<div class="item item-1">
item-1
</div>
<div class="item item-2">
item-2
</div>
<div class="item item-3">
item-3
</div>
</div>
This is a simplified example, and the implementation I'm stuck on has more rows of items in different places.
For example: large item first, or no large item at all.
Which is why grid-template-rows seems to be off the table, and I cannot find a way to stack them nicely without.
I've tried many different things, from grid-auto-rows to the various grid-* and align-*, to height and margins set to auto and fit-content, without success.
Here's the same snippet without grid-template-rows, where you can see the default behavior of .item-1 and .item-2 being separated / getting the same height:
.grid {
display: grid;
gap: 10px;
grid-template-columns: repeat(6, 1fr);
}
.item {
padding: 10px;
border: 1px solid black;
}
.item-1 {
grid-column: 1 / 3;
}
.item-2 {
grid-column: 1 / 3;
}
.item-3 {
grid-column: 3 / 7;
grid-row: 1 / 3;
padding: 80px 20px;
}
<div class="grid">
<div class="item item-1">
item-1
</div>
<div class="item item-2">
item-2
</div>
<div class="item item-3">
item-3
</div>
</div>
Here's an image of the snippets, showing the desired layout:

Try this
.grid {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 10px;
}
.item {
border: 1px solid #000;
padding: 10px;
}
.box1 {
display: flex;
flex-direction: column;
gap: 10px;
}
.item2 {
flex: 1;
}
.item3 {
padding: 80px 20px;
}
<div class="grid" >
<div class="box1">
<div class="item" >item 1</div>
<div class="item item2" >item 2</div>
</div>
<div class="item item3" >item 3</div>
</div>

.grid {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 10px;
}
.item {
border: 1px solid #000;
padding: 10px;
}
.box1 {
display: flex;
flex-direction: column;
gap: 10px;
}
.item1 {
flex: 1;
}
.item2 {
flex: 1;
}
.item3 {
padding: 80px 20px;
}
<div class="grid" >
<div class="box1">
<div class="item item1" >item 1</div>
<div class="item item2" >item 2</div>
</div>
<div class="item item3" >item 3</div>
</div>

Related

why is flexbox not vertically and horizontally not working?

Hi I'm trying to vertically and horizontally center a grid div by using flexbox inside a another div with a background image. It goes to the top left.
.flex_center {
display: flex;
align-items: center;
justify-content: center;
background-color: coral;
opacity: 0.7;
width: 1300px;
height: 485px;
z-index: 0;
}
.grid {
display: grid;
grid-gap: 10px;
grid-template-rows: 161px 161px 161px;
grid-template-columns: 360px 940px;
background-color: coral;
}
<section class="hero">
<div class="flex_center">
<div class="grid">
<div class="grid-item-1"><img src="images/logo_hero.png" class="logo_center"></div>
<div class="grid-item-2">
<p class="center">KIA'PALANO SEAFOODS</p>
</div>
<div class="grid-item-3">
<p class="squamish">A Squamish tribal-owned seafood company <br> located along the Squamish River, B.C</p>
</div>
<div class="grid-item-4">
<div class="button">COME ON IN</div>
</div>
</div>
</div>
</section>

CSS - ul items not in one line

it has been some time since I made my last webpage and it seems that I have forgot much. I cant resolve why the last item from the #menu ul goes to the next line while the #menu div is wide enough to contain all the list elements plus the logo div, it has margin and padding set to 0.
I used to do menus in such way before but have probably forgot something.
I searched for the solution however I cant make the things working right.
The question is..why arent the li items in one line? Whats causing the 850 px overlap when they all together should be 802px wide?
html, body {margin:0; padding:0}
body {background-image: url("./gfx/background.png"); background-position: 50%; background-repeat: no-repeat;text-align:center; background-color:#fff; font-family:Arial, Helvetica;width:100%}
.main-wrap {width:1000px; margin:0 auto}
#header {height:150px;width:1000px}
#logo {
display: block;
width: 150px;
height: 150px;
overflow: hidden;
color: #424242;
float:left;
margin: 0;
padding:0;
}
#logo span {
background: url("./gfx/logo-small.png");
z-index: 5;
display: block;
width: 150px;
height: 150px;
}
.wrap::before {
content: " ";
display: table;
}
.wrap::after{
clear: both;
content: " ";
display: table;
}
/*menu*/
#menu {width:849px;margin:0 0 0 0; padding:0px 150px 0 0}
#menu ul li {list-style: none;}
#menu ul li a {
z-index: 5;
position: relative;
float:left;
display: inline;
height: 31px;
overflow: hidden;
text-decoration: none;
color:#336699;
font-size: 20px;
margin: 0;
padding:0
}
#menu li a:hover,
#menu li a:focus {
height: 31px;
margin-top: 0;
color:#fff;
}
#menu li a span {
position: absolute;
top: 0;
left: 0;
display: block;
z-index: -1;
height: 31px;
cursor: pointer;
}
#menu li a:hover span,
#menu li a:focus span {
background: url("./gfx/menu-a.png");
background-repeat: no-repeat;
color:#fff;
}
#menu-1,
#menu-1 span {
background-position: 0 0;
width:119px;
}
#menu-1:hover span,
#menu-1:focus span {
background-position: 0px 0px;
}
#menu-2,
#menu-2 span {
width: 112px;
}
#menu li a#menu-2:hover span,
#menu li a#menu-2:focus span {
background-position: -119px 0px;
}
#menu-3,
#menu-3 span {
width: 128px;
}
#menu li a#menu-3:hover span,
#menu li a#menu-3:focus span {
background-position: -231px 0px;
}
#menu-4,
#menu-4 span {
width: 184px;
}
#menu li a#menu-4:hover span,
#menu li a#menu-4:focus span {
background-position: -359px 0px;
}
#menu-5,
#menu-5 span {
width: 149px;
}
#menu li a#menu-5:hover span,
#menu li a#menu-5:focus span {
background-position: -543px 0px;
}
#menu-6,
#menu-6 span {
width: 110px;
}
#menu li a#menu-6:hover span,
#menu li a#menu-6:focus span {
background-position: -692px 0px;
}
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>New web</title>
<link rel="stylesheet" href="main.css" type="text/css" />
</head>
<body>
<div class="main-wrap"> <!-- hlavni -->
<div class="wrap">
<div id="header">
<div id = "logo"><a href = "new_web/">
<span> </span>
</a></div>
<div id="menu">
<ul>
<li><a id="menu-1" href="new_web/about-us.html">About Us<span></span></a></li>
<li><a id="menu-2" href="new_web/services.html">Services<span></span></a></li>
<li><a id="menu-3" href="new_web/insurance.html">Insurance<span></span></a></li>
<li><a id="menu-4" href="new_web/meet-our-team.html">Meet Our Team<span></span></a></li>
<li><a id="menu-5" href="new_web/latest-news.html">Latest News<span></span></a></li>
<li><a id="menu-6" href="new_web/contact.html">Contact<span></span></a></li>
</ul>
</div>
</div>
</div>
<div id = "slider">
</div>
<div id = "main">
<!-- first page only -->
<div class="wrapper">
<div id="smart-boxes">
<div id="smart-box-1">
<p>"Change your thoughts and you chagne your world." <span>Norman Vincent Peale</span>
</p>
</div>
<div id="smart-box-2">
<p>High quality psychological services <a>read more...</a>
</p>
</div>
<div id="smart-box-3">
<p>We are a multidisciplinary treatment center <a>read more...</a>
</p>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="wrapper">
<div id="footer-address">
<p>
</p>
</div>
<div id = "footer-links-1">
<p>
Contact Us<br />
FAQ <br />
</p>
</div>
<div id = "footer-links-2">
<p>
Terms of use<br />
Insurance<br />
Our Team<br />
</p>
<p class="ext-links">
</p>
</div>
</div>
</div>
</div>
</body>
</html>
Thank you for your advices.
Allright, basic mistake: when positioning two elements using float property just beside each other one must have float:left (#logo) and the other muset go to right simple adding float:right to #menu did the thing (also removed the 150px padding-right).

column of icons in bootstrap v4

I have a simple column of icons using flexbox in bootstrap v4. It comes up fine, but if you then click on an icon, the position changes slightly. Seems to happen only in chrome. Here is a fiddle:
https://jsfiddle.net/lenb/shr8bk89/10/
`
HTML:
<body>
<div id='no'>
<div id='minus' class="icon" title="Not special.">
<a href="#" id="nHeart">
<img class="img icon" src="http://gps-photo.org/images/Not.svg" />
</a>
</div>
<div id='plus' class="icon" title="Loving it!">
<a href="#" id="heart1">
<img class="img" src="http://gps-photo.org/images/red-304570-1.svg" />
</a>
</div>
<div id='comment-button-div' class="icon" title="Click for comments">
<a class="comment-page" data-toggle="modal">
<img class="img" id='comment-button' src="http://gps-photo.org/images/comments-97860-3.svg" />
</a>
</div>
<div id='info-div1' class="icon" title='Information'>
<a class="info-page" data-toggle="modal">
<img id="info1" class="img" src="http://gps-photo.org/images/information-39064-2.svg" />
</a>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
</body>
CSS:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
#removal {
border-color: black;
border-top: 10rem;
}
html,
body {
width: 100%;
height: 100%;
}
#no {
padding: 1rem;
display: flex;
display: -webkit-flex;
flex-wrap: nowrap;
-webkit-flex-wrap: nowrap;
justify-content: space-between;
-webkit-justify-content: space-between;
align-items: center;
-webkit-align-items: center;
align-content: space-between;
-webkit-align-content: space-between;
flex: 1 1 auto;
-webkit-flex: 1 1 auto;
}
.icon {
margin: auto;
flex-grow: 1;
flex-basis: auto;
}
/* // next is for images */
.img {
width: 8vmin;
}
/* // stuff living in #no */
#info-div1 {
order: 3;
-webkit-order: 3;
}
#minus {
order: 0;
-webkit-order: 0;
}
#plus {
order: 1;
-webkit-order: 1;
}
#comment-button-div {
order: 2;
-webkit-order: 2;
}
#no {
flex-direction: column;
-webkit-flex-direction: column;
height: 100%;
max-width: 10rem;
order: 0;
-webkit-order: 0;
}
I see no reason why the positioning should change.
Can someone tell me what is wrong.
Using normalize.css as the 1st to load helps to normalize vertical alignment for Chrome

Flexbox equal width problems

Dear fellow stackoverflowers,
I'm having a peculiar problem I can't seem to find the solution for.
I'm trying to apply the width of the largest div to the smaller divs, so that they appear equal in width, through flexboxing. Unfortunately, all the solutions so far have been futile efforts. Do you have any idea why the different divs in the example I've linked to won't display the same width as the largest element? I know the boxes get their width from the content, but I just can't seem to make them behave the way I want.
HTML
<section id="contact" class="wrapper bgfixed">
<div>
<h1>Contact</h1>
<div id="contactholder">
<a href="#">
<div>
<h1 class="icon-mail"></h1>
<h2>EMAIL</h2>
<p>someonesprofessionalemail#gmail.com</p>
</div>
</a>
<a href="#">
<div>
<h1 class="icon-old-phone"></h1>
<h2>TELEPHONE</h2>
<p>39 88 49 92 91</p>
</div>
</a>
<a href="#">
<div>
<h1 class="icon-facebook2"></h1>
<h2>FACEBOOK</h2>
<p>www.facebooooooooooooooooooook.com/snowman</p>
</div>
</a>
<a href="#">
<div>
<h1 class="icon-soundcloud"></h1>
<h2>LOREM IPSUM</h2>
<p>www.loremipsumyesyesyesblahblabhlabh.com</p>
</div>
</a>
</div>
</div>
</section>
CSS
a{text-decoration: none;}
#contact
{
width: 100%;
height: 82vh;
color: whitesmoke;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
background: #34495e;
}
#contactholder
{
display: flex;
justify-content: space-between;
font-size: 80%;
}
#contactholder div
{
flex: 1;
flex-grow: 1;
font-size: 0.5rem;
}
#contactholder div h1
{
padding: 3rem;
letter-spacing: 0;
display: inline-block;
background-image: linear-gradient(white, 1%, #3498db);
border-radius: 100rem;
box-shadow: 0 1px 1px grey;
transition: 0.3s;
margin-bottom: -0.5rem;
}
#contactholder a:hover h1
{
background-image: linear-gradient(white, 1%, #00A4EB);
text-shadow: 0 1px 1px;
}
Hoping for some brilliant minds!
Best wishes,
Lodott1

Problems with z-index,positions and float

I have a problem with 2 pictures staying one aboce the other. I am trying to make the plane stay above the cloud. But, even if I have set the position and z-index, they stil stay one near the other.
How can I make the plane stay above the cloud?
Thank you!
HTML:
<html>
<body>
<div id="main">
<div id="header">
<img id="logo" src="images/logo.png" />
<ul>
<li>Home</li>
<li>Oferte Turism</li>
<li>Despre noi</li>
<li>Contact</li>
</ul>
</div>
<div id="body">
<div id="leftup">
<img id="cloud" src="images/cloud.png" />
<img id="plane" src="images/plane.png" />
</div>
<div id="form"></div>
<div id="offers"></div>
</div>
<div id="body2"></div>
<div id="footer"></div>
</div>
</body>
</html>
CSS:
body {margin:0;
padding:0;
}
#body {height: 900px;
background-image: url('images/headerbg.png');
}
#main {width: 960px;
margin: 0px auto;
}
#header {height: 80px;
background-image: url('images/hd.png');
background-repeat: no-repeat;
}
ul { list-style-type: none;
font-family: Verdana;
font-size: 14px;
}
li { display: inline;
padding:20px;
float:left;
margin-left: 35px;
}
li a { text-decoration:none;
color:white;
font-style:bold; <!-- NO BOLD -->
}
li a:hover { text-decoration:underline;
}
#logo {margin-left: 30px;
float:left;
}
#leftup {clear:both;
float:left;
margin-top:50px;
}
#cloud {width:250px;
position:relative;
z-index:1;
}
#plane {width:250px;
position:relative;
z-index:10;
}
#form {float:right;
border: solid 1px blue;
height:200px;
width: 100px;
margin-right:30px;
}
#offers {border: solid 1px yellow;
clear:both;
margin: 100px auto;
height: 300px;
width: 500px;}![enter image description here][2]
#body2 { height:600px;
background-image: url('images/bodybg.png');
}
#footer {height: 100px;
background-image: url('images/footerbg.png');
}

Resources