hope you all are doing well.
I am new to web development and I am coding along with https://www.youtube.com/watch?v=bFvfqUMjvsA&ab_channel=CodingLab and around 5:20 timestamp I am not getting the same result as the one in the video. Can anyone please help me understand what's wrong?
Edit: I tried changing to display: inline-flex; but I'm still not getting the same result.
Expected Result based on video:
Actual Result I am getting:
.sidebar header .image-text {
display: flex;
align-items: center;
}
<nav class="sidebar">
<header>
<!-- ===== Logo ===== -->
<div class="image-text">
<span class="image">
<img src="https://via.placeholder.com/100jpg" alt="candlestick logo">
</span>
</div>
<!-- ===== Logo Text ===== -->
<div class="text header-text">
<span class="name">TradeJournal</span>
<span class="creator">By RS</span>
</div>
</header>
</nav>
first of all, to make the code work you need that
1. the image 2. span (text)
to be inside the same parent element
so in his case, it would be .image-text but in your case is the <header>
you may think: "but I write the same CSS, why is not working?"
so yes, the problem is not in your CSS! instead is in HTML!
❌ your previous HTML code:
<nav>
<header>
<div class="image-text">
<!-- image tags code -->
</div>
<!-- text (error: you putted this outside the .image-text) -->
</header>
</nav>
✅ the code needs to be like this:
<header>
<div class="image-text">
<!-- image tags code -->
<!-- text -->
</div>
</header>
the CSS don't touch it, is ok!
good learning!
Add flex in Header
.sidebar header {
display: flex;
align-items: center; }
You are to set the flex on the parent element not child
.sidebar header{
display: flex;
align-items: center; }
.sidebar header {
display: flex;
align-items: center;
justify-content:center;
}
<nav class="sidebar">
<header>
<!-- ===== Logo ===== -->
<div class="image-text">
<span class="image">
<img src="https://via.placeholder.com/100jpg" alt="candlestick logo">
</span>
</div>
<!-- ===== Logo Text ===== -->
<div class="text header-text">
<span class="name">TradeJournal</span>
<span class="creator">By RS</span>
</div>
</header>
</nav>
Related
I am trying to move content within the first site-header-section child to the left as there is too much gap on the left hand side but I can't seem to shift it. What am I missing?
<div class="site-header-primary-section-left site-header-section ast-flex site-header-section-left">
<div class="ast-builder-layout-element ast-flex site-header-focus-item" data-section="title_tagline">
<div class="site-branding ast-site-identity" itemtype="https://schema.org/Organization" itemscope="itemscope">
<span class="site-logo-img"><img width="106" height="80" src="https://puffpastrydelights.com/wp-content/uploads/2021/04/puff-pastry-dellight.png" class="custom-logo" alt="Puff Pastry Delight" loading="lazy" srcset=""><img width="106" height="80" src="https://puffpastrydelights.com/wp-content/uploads/2021/04/puff-pastry-dellight-1.png" class="custom-logo" alt="" loading="lazy"></span>
<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>
<!-- .site-branding -->
</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>
</div>
CSS:
.site-header-section:first-child{
display: flex;
flex-direction: column;
justify-content: flex-start;
align-content: flex-start;
margin:0;
padding:0;
}
While it's not a completely responsive solution, you could resort to using
.site-header-section:first-child {
position: relative;
left: 0;
}
This should just move the div to be stuck against the left side of the screen. If that's to far left, try a higher value than 0 for the 'left' property, such as 10px.
You have padding-left: 20px in the div with this class names ast-primary-header-bar ast-primary-header main-header-bar site-primary-header-wrap site-header-focus-item ast-builder-grid-row-layout-default ast-builder-grid-row-tablet-layout-default ast-builder-grid-row-mobile-layout-default. If you cancel that, it would solve your problem.
I have no idea why my website cannot display to change flex (I mean, some element of text on the left side and the images on the right side), why it's not working?
.presentation {
display: flex;
width: 90%;
margin: auto;
min-height: 80vh;
align-items: center;
}
.introduction {
flex: 1;
}
.cover img {
height: 60vh;
}
<main>
<section class="presentation">
<div class="introduction">
<!--intro text..., -->
<div class="intro-text">
<h1>mac</h1>
<p>This is the latest laptop and this laptop is the best ever until nobody doubt that want to mac. This is very powerfull, strong and almost 8k</p>
</div>
<!--button ...,-->
<div class="cta">
<button class="cta-select">14-inch</button>
<button class="cta-add">Add Cart</button>
</div>
<!-- and images of laptop -->
<div class="cover">
<img src="https://bhrigu.me/images/mac.png" alt="laptop mac">
</div>
</div>
</section>
</main>
You have mistakenly used flex property in root directory. Which elements you want to apply flex property/display, you have to use flex property immediate on parent div.
For example:
You have to put flex on intro-text class.
CSS:
.intro-text {
display: flex;
}
<div class="intro-text">
<!--button ...,-->
<div class="cta">
<button class="cta-select">14-inch</button>
<button class="cta-add">Add Cart</button>
</div>
<!-- and images of laptop -->
<div class="cover">
<img src="https://bhrigu.me/images/mac.png" alt="laptop mac">
</div>
</div>
And if you want to place an element in the right position. Just use
.cover {
margin-left: auto;
}
Please take a look here:
https://codepen.io/ilazycoder/pen/jOWQvYj
I have an HTML template and I need to make his left sidebar fixed (no scrolling) without using position: fixed because it ruins all the template.
<div class="layout-w">
<!-- menu -->
<div class="menu">
<!-- elements here -->
</div>
<!-- content -->
<div class="content">
<!-- Elements here -->
</div>
</div>
And this the css
.layout-w {
display: flex;
}
.menu {
display: flex;
flex-direction: column;
}
.content {
flex: 1;
}
How can I accomplish this?
You could just put your menu div inside another div with height of 100% and background-color:transparent.
<div class="layout-w">
<!-- menu -->
<div class="menu-container">
<div class="menu">
<!-- elements here -->
</div>
</div>
<!-- content -->
<div class="content">
<!-- Elements here -->
</div>
and in css file:
.menu-container { height: 100%; background-color: transparent; }
.menu { postion: fixed }
I have three pieces of text, Events Find an Event and Post an event
Events is positioned correctly in the centre of the page, but Post An Event and Find An Event are positioned left of centre.
How do I put these two pieces of text next to each other (same line) and in the centre of the page?
Tried.
.postanevent {text-align : center! important; display:
inline-block! Important;}
.findanevent] text-align: center! Important; display: inline-
block! Important; }
Here is my html:
<div class="entry-content">
<div class="lasvegas">
Events
</div>
<div class="findanevent"><a
href="https://adsler.co.uk/find-an-event/"></p>
<div class="findanevent"><font size="3"><font
color="white">Find an Event</font></font></div>
<p></a></p>
<div class="postanevent"><a
href="https://adsler.co.uk/post-an-event/"></p>
<div class="postanevent"><font size="3"><font
color="white">Post an Event</font></font></div>
<p></a></p>
</div><!-- .entry-content -->
<footer class="entry-footer">
<span class="edit-link"><a class="post-edit-link"
href="https://adsler.co.uk/wp-admin/post.php?
post=6811&action=edit">Edit <span class="screen-
reader-text">"Events"</span></a></span> </footer><!--
.entry-footer -->
</article><!-- #post-## -->
</div><!-- #primary -->
Page: https://adsler.co.uk/events/
You need a wrapper around the two anchors to center them both in the same line:
.event_wrapper {
text-align: center;
}
<div class="event_wrapper">
<span id="findanevent" class="event">Find an Event</span>
<span id="postanevent" class="event">Post an Event</span>
</div>
don't use the font tag anymore, it is deprecated. You can just use the classes you already have or add a new one like I did.
Hope this helps!
You need to wrap your links inside a div the use display flex. there are many ways to do this but I prefer flex it easy.
<div class="entry-content">
<div class="links-wrapper">
<div class="lasvegas">
Events
</div>
<div class="findanevent">
Find an Event
</div>
<div class="postanevent">
Post an Event
</div>
</div>
</div><!-- .entry-content -->
<style type="text/css">
.entry-content{
width: 100%;
}
.links-wrapper{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.links-wrapper > div{
margin: 0 15px;
}
</style>
Wrap your findanevent and postanevent divs into a main wrapper like <div class="eventsWrap"> and put this in a display:flex property. So that the two divs will be in same line. Because by default the display:flex property shows the child element into same line like inline or rows. Next you have to add a property is justify-content:center;, align-items:center;, align-content:center; align-self:center;. Hope it may help you! Good luck.
.eventsWrap { display:flex; justify-content:center; align-items:center; align-content:center; align-self:center;}
you can take these 3 in flex box:
<div style=" display: flex;justify-content: center;">
<div Events></div>
<div Find an Event></div>
<div Post an event></div>
</div>
I hope this will help.
Try this one for set links
<div class="entry-content" style="text-align: center;">
<div class="lasvegas">
Events
</div>
<div class="findanevent">
<a href="https://adsler.co.uk/find-an-event/">
<div class="findanevent">
<font size="3">
<font color="black">Find an Event</font>
</font>
</div>
</a>
<div class="postanevent">
<a href="https://adsler.co.uk/post-an-event/">
<div class="postanevent">
<font size="3">
<font color="black">Post an Event</font>
</font>
</div>
</a>
</div>
<!-- .entry-content -->
</div>
<!-- #primary -->
</div>
<style>
.lasvegas{
display: inline-block;
}
.findanevent{
width: 100%;
}
</style>
I hope this one is helpful
i'm creating a HTML page with Bootstrap 4 from an image.
This is the image:
But i have no idea how to get this style with flexbox.
This is what i have done so far
html:
<section id="recursos">
<div class="container">
<h1 class="como-funciona text-center">Recursos disponíveis</h1>
<div class="text-center"><img src="img/linha.png" class="img-fluid">
<h3 class="ferramenta">Para turbinar o seu negócio no Instagram</h3>
</div>
<div class="container-center">
<div class="left">
<img src="img/icones/like.png">
<h3>teste</h3>
<p>description</p>
<img src="img/icones/comentario.png">
<h3>teste</h3>
<p>description</p>
<img src="img/icones/relatorio.png">
<h3>teste</h3>
<p>description</p>
</div>
<div class="center">
<!-- this is where i was going to put the phone image -->
</div>
<div class="right">
<!-- and here is equal to left elements -->
</div>
</div>
</div>
</section>
css
.container-center{
display:flex;
justify-content: center;
align-items: center;
}
.left{
width:33.33vw;
display: inline-grid;
}
.center{
background:gold;
width:33.33vw;
}
.right{
background:gray;
width:33.33vw;
}
Can you guys please help me solve this problem? I dont know how to place the h3 text along with the description like the image.
I'm able to do it using position absolute but i know its not the right way to do it.
Many thanks.
I don't want to provide the exact answer but, I did draw up something that may help you.
Basically, you just need to remember that you can nest flex box elements inside each other.