How to display an element underneath another element? - html

I am trying to place my social and email links found with a ul additional-menu, to be displayed under my site's logo and tagline. I seem to be struggling getting it underneath. At the moment it looks like this:
The code below is like so:
.additional-menu {
list-style-type:none;;
margin: 0;
position:relative;
clear:both
}
.additional-menu li{
display:inline-block;
}
.ast-header-html-1{
position:relative;
clear:both;
}
<div class="ast-site-title-wrap">
<h1 class="site-title" itemprop="name">
<a href="https://puffpastrydelights.com/" rel="home" itemprop="url">
Pastry Delights
</a>
</h1>
<p class="site-description" itemprop="description">
Made with love, served with pride
</p>
</div>
<div class="ast-builder-layout-element ast-flex site-header-focus-item ast-header-html-1" data-section="section-hb-html-1">
<div class="ast-header-html inner-link-style-">
<div class="ast-builder-html-element">
<ul class="additional-menu">
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</div>

Wrap the whole thing with div that has display:flex and flex-direction: column
.wholeThing {
display: flex;
flex-direction: column;
border: 1px solid red;
}
.firstBit {
display: flex;
border: 1px solid blue;
}
<div class="wholeThing">
<div class="firstBit">
<div class="logo"><img src="http://placekeanu.com/250" /></div>
<div class="tagline">Keanu is breath taking</div>
</div>
<div class="social">
social one two three
</div>
</div>
`

Related

Why aren't all the product cards within the list wrapper?

Question is straightforward. Why aren't the product cards "flowing" to the right? The second product card isn't within the list-wrapper.
Extra question (maybe related): is there anything wrong with my choice of where to put my divs?
.list-wrapper {
display: inline-flex;
flex-wrap: wrap;
left-margin: 5em;
border: 2px solid grey;
justify-content: space-evenly;
width: 100%;
}
.product-card {
display: flex;
border: 1px dotted grey;
margin: 20px 10px 20px 10px;
padding: 5px;
width: 30%;
height: 200px;
}
<div>
<div class="list-wrapper">
<div class="product-card">
<ol>
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
</div>
<div class="product-card">
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
</div>
</ol>
</div>
</div>
I believe there are some nesting errors in your html.
The <ol> right in product-card is never properly closed and the last three closing tags (</ol> and 2x </div>) are loose and dont have a opening counterpart.
In addition you're defining an ordered list using <ol> but never use the list-item tags inside (<li>). See this on details but heres how list markup in general should look:
<ol>
<li>Mix flour, baking powder, sugar, and salt.</li>
<li>In another bowl, mix eggs, milk, and oil.</li>
<li>Stir both mixtures together.</li>
<li>Fill muffin tray 3/4 full.</li>
<li>Bake for 20 minutes.</li>
</ol>
(Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol)
As it seems the ol element isnt neccessary for what youre trying to achieve, therefore i removed it.
Also i fixed the nesting and moved the second product-card element inside the list-wrapper element too.
.list-wrapper {
display: inline-flex;
flex-wrap: wrap;
left-margin: 5em;
border: 2px solid grey;
justify-content: space-evenly;
width: 100%;
}
.product-card {
display: flex;
border: 1px dotted grey;
margin: 20px 10px 20px 10px;
padding: 5px;
width: 30%;
height: 200px;
}
<div>
<div class="list-wrapper">
<div class="product-card">
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
<div class="product-card">
<div class="wrapper">
<div class="product-name">Product Name</div>
<div class="product-basic-description">Comes in many colors and sizes</div>
<div class=product-price>300.00 $</div>
<div class=product-image><img src="" alt="{{ image-description }}"></div>
</div>
</div>
</div>
</div>

margin: 0 auto; not centering div in parent

I have the following div arrangement, with the below css. Everywhere online seems to say you need margin:0 auto; for centering, but the text still goes to the top right,
Any help appreciated.
.menu_item {
margin: 0 auto;
}
<div style='position:absolute;width:110%;height:110%;left:-5%;top:-5%;background-color:white;z-index:7;overflow:none;'>
<div id='menu_but' style='width:36px;height:36px;'>
<div class='menu_line' />
<div class='menu_line' />
<div class='menu_line' />
</div>
<div id='menu'>
<div class='menu_item'>HOME</div>
<div class='menu_item'>ABOUT US</div>
<div class='menu_item'>CONTACT US</div>
<div class='menu_item'>PORTFOLIO</div>
</div>
</div>
First of all, <div> is not a self-closing tag so you have to write </div> instead of <div class='menu_line'/>
Then, you could simply do:
<style>
.menu_item{
display: inline-block;
}
#menu {
position: relative;
text-align: center;
}
</style>
<div id="menu">
<div class="menu_item">HOME</div>
<div class="menu_item">ABOUT US</div>
<div class="menu_item">CONTACT US</div>
<div class="menu_item">PORTFOLIO</div>
</div>
maybe use flexbox ?
.parent {
display:flex;
justify-content:center;
align-items:center;
}
All of the child elements will be centered

Position div in navbar vertically center and to the right

I have a lot of links in a navbar. Most of the links are positioned to the left. I want to position some of the links to the right (right-side-login-cart). The part that is giving me trouble is that I can get the links to the right, but then cannot get the links to vertically align.
I've tried a bunch of different things to get it to work. For instance, I have float:right;, used transform to translate Y, and tried to used vertical align.
Some different attempts:
HTML
<div class="links-at-top">
<div class="links-div">
<a href="/">
<img src="example.com/img">
</a>
Link1
Link2
</div>
<div class="right-side">
<div class="positioning">
<a id="right-link-1">RightLink1</a>
<a id="right-link-2">RightLink2</a>
</div>
</div>
</div>
Attempt 1:
CSS:
.right-side {
padding-right: 50px;
display: inline-block;
}
.positioning {
position: absolute;
right: 0;
transform: translateY(-50%);
}
Attempt 2:
CSS:
.right-side {
padding-right: 50px;
display: inline-block;
}
.positioning {
vertical-align: middle;
}
Add your .right-side div into the same div as your other links so that they'll be on the same line. Then you can just float right.
.links-div {
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="links-at-top">
<div class="links-div">
<div>
Link1
Link2
</div>
<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png" alt="" />
<div>
<a id="right-link-1">RightLink1</a>
<a id="right-link-2">RightLink2</a>
</div>
</div>
</div>
You can consider using flex-box
.links-at-top{
display: flex;
justify-content:space-between;
align-items:center;
}
<div class="links-at-top">
<div class="links-div">
Link1
Link2
</div>
<div class="right-side">
<div class="positioning">
<a id="right-link-1">RightLink1</a>
<a id="right-link-2">RightLink2</a>
</div>
</div>
</div>
make .links-div and .right-side both display:inline-block, and float the right-side to right.
<div class="links-at-top">
<div class="links-div">
Link1
Link2
</div>
<div class="right-side">
<ul class="positioning">
<li> <a id="right-link-1">RightLink1</a></li>
<li> <a id="right-link-2">RightLink2</a></li>
</ul>
</div>
.right-side {
display: inline-block;
float:right;
}
.links-div{
display:inline-block;
}

How to put a header in between of two images on the same line (using the <div> blocks)?

I am trying to create a webpage for an imaginary pizzeria as practice. I want to insert the header of the webpage in between two images(same) such that the three(image, header, image) elements are in line. But with the code below I am getting a screen like this. How do I get them all on one line?
<body>
<div style='float:left'>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='font-family:amita; font-size:20px;'>
<h1 align='center' style='margin-bottom:5px;'>Ralph's Pizzeria</h1>
</div>
<div style='float:right'>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<hr style='clear:both;' />
</body>
This can be done using display: flex and justify-content: space-between:
.header {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
<div class="header">
<div>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='font-family:amita; font-size:20px;'>
<h1 align='center' style='margin-bottom:5px;'>Ralph's Pizzeria</h1>
</div>
<div>
<img src='body.png' style='width:100px; height:100px;'>
</div>
</div>
I've added a container div and given it the class header and applied the flexbox to it.
You can simply do this :
header {
text-align: center;
}
h1 {
font-size: 25px;
display: inline-block;
vertical-align: top;
margin-top: 25px;
}
img {
display: inline-block;
width: 100px;
height: 100px;
margin:0 10px;
}
<header>
<img src='https://lorempixel.com/100/100/'>
<h1>Ralph's Pizzeria</h1>
<img src='https://lorempixel.com/100/100/'>
</header>
<hr>
Here's another solution if you want to continue to work with float.
Simply move the 2nd image to before the title.
<body>
<div style='float:left'>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='float:right'> <!-- Just moved this up here -->
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='font-family:amita; font-size:20px;'>
<h1 align='center' style='margin-bottom:5px;'>Ralph's Pizzeria</h1>
</div>
<hr style='clear:both;'/>
</body>
However, I suggest using flex-box if you don't have to support older browsers.

trying to resize list items so they are all equal size

I am trying to make my list items all the same width. I've tried setting the widths in the css and nothing changes. Can anyone figure this out?
Here is an image to show what I am talking about:
HTML:
<body>
<div class="content-wrapper" id="container">
<header>logo
<nav>navigation</nav>
</header>
<div class="clear-fix"></div>
<div id="body">
<section class="main-content">
<section class="leftPane">
<h2>Categories</h2>
</section>
<section class="rightPane">
<div class="checkout">
<h1>Checkout</h1>
<ul class="steps">
<li><a href="http://localhost:59213/Cart">
<div id="step0" class="arrow_box_grey">
Shopping Cart</div>
</a>
</li>
<li><a href="http://localhost:59213/Cart/Student">
<div id="step1" class="arrow_box_grey">
Student</div>
</a>
</li>
<li><a href="http://localhost:59213/Cart/Delivery">
<div id="step2" class="arrow_box_grey">
Delivery</div>
</a>
</li>
<li>
<div id="step3" class="arrow_box_green">Payment</div>
</li>
<li>
<div id="step4" class="arrow_box_blue">Finish</div>
</li>
</ul>
</div>
</section>
<div class="clear-fix"></div>
</section>
</div>
</div>
And here if my fiddle with the code: http://jsfiddle.net/M74Em/
You need to change this style:
.main-content .checkout ul.steps li div {
display: inline;
width: 1000px;
}
You can't set widths for inline elements so try this:
.main-content .checkout ul.steps li div {
display: inline-block;
width: 100px;
}
Example
From twBootstrap, applied to <ul>'s (demo):
.ul-justified {
display: table;
width: 100%;
table-layout: fixed;
border-collapse: collapse;
}
.ul-justified > li {
display: table-cell;
float: none;
width: 1%;
}
and slap .ul-justified to any ul-list you want aligned, and you get equal width <li>'s automatically fit parent ul's width.