I have a header which looks like this :
I found an example of what I wan. On small screen i need the search bar to go underneath.:
The issue is that i have no idea how this is done. I tried changing the position to relative when i reach a certain screen width but this didn't help.
<div className="header">
<div className="header__logo">
<img src={logo} alt=""></img>
</div>
<div className="header__search">
<SearchBar />
</div>
<div className="header__right">
<FiUser className="header__icon" />
<Cart />
</div>
</div>
/*
header
*/
.header {
width: 100%;
height: 60px;
border-bottom: 1px solid #e4e4e4;
display: flex;
justify-content: center;
}
.header__logo {
width: 120px;
height: 60px;
line-height: 65px;
}
.header__logo img {
width: 120px;
background-size: contain;
}
.header__search {
width: 50%;
height: 60px;
line-height: 60px;
margin: 0 20px 0 20px;
text-align: center;
}
.header__right {
width: 120px;
height: 60px;
line-height: 60px;
display: flex;
justify-content: space-between;
}
.header__icon {
height: 30px;
width: 30px;
margin-top: 15px;
cursor: pointer;
}
I dont need you to code it for me i'm fine doing that myself, I just have no clue how to go on about this.
One option would be to create two search bars in the same file. And hide one and show other depending on screen sizes.
Somthing like this:
<select class="for-desktop"> ... </select>
<select class="for-mobile"> ... </select>
Then CSS would look like following:
#media(max-width:768px){
.for-desktop{
display:none;
}
}
#media(min-width:768px){
.for-mobile{
display:none;
}
}
This way you don't need to think too much other stuff. This will simpy do it.
Other way is to use CSS-Grid for the Entire Header. And show the select on the bottom (Need to write some code efficiently)
You can do one quick hack also. Set position:relative on the parent and position:absolute; for the select only when screen size is smaller and adjust your select accordingly.
Something Like the below example.
.header {
position:relative;
}
.header__search {
position:absolute;
bottom: -60px;
left:0;
right:0;
}
(You may need to do small adjustments with positioning of search item)
If you are interested in a little css refactor, you can use CSS grid to change the position of this search bar
For more info i would recommend this link
Cheers!
-- UPDATE ---
if not, you can hide this bar when your screen side reach some point and then show a new "div" or a "copy" right below (I think it can be cool and
easier to create animations)
or even use javascript to append this element to the desired position
Related
After spending all day long trying to found how to make a nice tumblr-like grid for my website, I'm posting here to find help.
here's the page: http://alexis.gargaloni.free.fr/main.html
In order to access to my project there's a grid of images displayed. At the moment it looks OK, but now that I need to add something new, it starts to look really bad. screenshot
As you can see, there's a white gap. I've tried many things and there's every time a gap (even when it's not supposed to be there).
Here's an example of what I want to achieve: http://alexgargaloni.tumblr.com
here's my HTML code (included filter):
<div id="myBtnContainer">
<button class="btn active" onclick="filterSelection('all')"> TOUT</button>
<button class="btn" onclick="filterSelection('imprime')"> IMPRIMÉ</button>
<button class="btn" onclick="filterSelection('digital')"> NUMERIQUE</button>
<button class="btn" onclick="filterSelection('picture')"> PHOTO</button>
</div>
<div class="pic"> <img class="filterDiv picture" src="images/ego5-4.jpg" alt="ego graphique" style="width:40% "> <img class="filterDiv imprime" src="images/ihp1_1.jpg" alt="affiches pour l'institut henri poincaré" style="width:25%"> <img class="filterDiv imprime" src="images/jpogat17.png" alt="portes ouvertes lycée du gué à tresmes 2017" style="width:25%"><img class="filterDiv imprime" src="images/detailbook1.jpg" style="width:35%"> <img class="expav filterDiv digital" src="images/expavstatic.png" alt="expérience de la durée" style="width:35%" ></div>
and CSS:
html {
position: relative;
min-height: 100%;
}
body {
background: white;
font-size: 20px;
font-family: Helvetica, Arial, sans-serif;
line-height: 25px;
margin: 0 0 900px; /* bottom = footer height */
padding: 25px;
}
.img{
margin: 20px;
}
/* FILTER */
.container {
overflow: hidden;
}
.filterDiv {
float:left;
/*color: #ffffff;*/
width: 100px;
line-height: 100px;
text-align: center;
margin: 13px;
display:none; /* Hidden by default */
}
.show {
display: block;
}
.pic
{
max-width: 100%;
}
I'm new to HTML and CSS, and I know that my code is not a 100% clean and it could be way more simplified, but I'm working on it.
Excuse my English, I'm French
Thank for your help!
EDIT #ben_fluleck
Thank you. There’s a problem with “height: 100%”, because it modifies the aspect ratio of my pic. If I change height and width with max-width and max-height, the white gap is back. I also need to keep “display: none” on. filterDiv to make the filter function work (something with javascript). And also I’m having a problem with filter now, it still works, but pics are not getting how they’re supposed to (before:picture after:picture, it's like elements filtered create a white space instead of disappearing). I’ve tried to do something with the tumblr html, but it didn’t seem to work. Simple things are super tricky to do… I really need something that trick the size itself like tumblr theme, because when I’ll ad new things on my website, I feel like it’s going to be a mess again.
Yes, my footer is not really well implemented, I’ve checked online a way to make it because it’s really tricky, and how I did was the only way I was able to make it work. Thank a lot for you help! We can see the footer later, for the moment I really need to focus on this grid
Sorry, the picture in my Css above should be pic since you have named them you can constrain the pics giving them a width property. I would remove the inline styling for width and use percentages in the Css.
I have constructed a fiddle you could expand upon but it should give you a better idea of the layout.
.container {
display: flex;
justify-content: center;
align-items: center;
}
.box {
flex: 1 1 auto;
color: white;
font-size: 50px;
text-align: center;
padding: 10px;
}
/* Colours for each box */
.box1 {
background: #1abc9c;
}
.box2 {
background: #3498db;
}
.box3 {
background: #9b59b6;
}
https://jsfiddle.net/sLjuLjoc/1/
Try these CSS Layouts they will get your pics in order
Flexbox or Grid
set a viewport height in the body and work of that
body{
background: white;
font-size: 20px;
font-family: Helvetica, Arial, sans-serif;
line-height: 25px;
/* margin: 0 0 900px; */
padding: 25px;
height: 100vh;
display: flex;
flex-direction: column;
}
.pic {
display: grid;
grid-template-columns: repeat(4,1fr);
grid-gap: 10px;
}
.filterDiv {
float: left;
width: 100%;
line-height: 100px;
text-align: center;
height: 100%; /*optional if you want them to be all the same same */
}
.show {
/* display: block; */
}
Based upon the screen size, the whitespace increases/decreases between the image and blog title:
How can I make them touch at all times?
HTML
<img class="main-image" src="/assets/walking.jpg">
<div class="overlay-image">
<div class="blog-caption">
A DAILY BLOG ABOUT THE
JOURNEY & CHALLENGES
</div>
<%= render 'subscribes/subscribe.html.erb' %>
</div>
<div class="blog-page">
Blog post title & text.
</div>
css
main-image {
width: 100%;
position: relative;
}
.overlay-image {
position: relative;
text-align: center;
margin-top: -47%; # I think this is the main culprit, but I don't know how to edit without altering the position of the things on the image
height: 201px;
}
.blog-caption {
text-align: center;
font-size: 18px;
color: white;
margin-top: 0px;
margin-bottom: 18px;
padding-top: 8px;
background-color: rgba(44,62,80, 0.8);
padding-bottom: 8px;
}
.blog-page {
#media (max-width: 992px) {
padding-top: 0px;
margin-top: -40px;
}
}
Yes, as you already suspected: First remove the negative margin from .overlay-image. Then add position: absoulte to .blog-caption and adjust its position with the top and left settings.
Maybe you should look at z-index.
Then you can put the image into the container for the fancy text which is in the class .overlay-image yet.
With this, you get rid of those -x% margin. Maybe this can help you figure out the problem.
Still developing my html5/css3 mobile site, I have trouble adjusting the height of a div to its parent.
http://jsfiddle.net/1eg2cwLs/
The fiddle doesn't exactly look like this because I'm using webfonts (saved offline though as I'm not going to have internet connection on the target system). But the problem remains the same.
You might be seeing what the problem is right from the spot, if not: I would like the green and red bar (.itemclass) always have the same size as the content of its parent (.item).
Depending on font, its size (still playing around with it) and the overall height of each item, I have to precisely adjust the negative margin. Otherwise it looks like in the screenshot. The negative margin I just mentioned is in the CSS-class .itemclass: (marked with an arrow also in the fiddle)...
.itemclass {
height: 100px;
width: 50px;
background-color: #27ae60;
vertical-align: middle;
text-align: center;
color: white;
font-size: 2em;
margin-top: -27px; /* <=== */
display: inline-block;
}
This cannot be the solution. I tried a lot of stuff and I only got it "working" the way I mentioned.
Any better idea how to make it look clean without a hack?
As well, tips for other improvements regarding my html/css are well appreciated.
Sorry for appending the entire code into the fiddle. I don't know whether it was representative if I was going to remove stuff.
Best regards
I'd probably go this route:
.item {
position: relative;
...
}
.itemclass {
position: absolute;
top: 0;
bottom: 0;
...
}
.itemcontent {
margin-left: 50px;
...
}
Demo
Really big font demo
Consider a reasonable min-width for the body to prevent .tagline from overlapping, etc.
You can set .item's margin-top to 0, and instead adjust the margin-top of .vcenter:before. This way you're just adjusting the text and not the div.
Or you could drop the static height and width of .itemclass altogether. Now the .itemclass will scale.
http://jsfiddle.net/1eg2cwLs/5/
.item {
width: 100%;
height: auto;
background-color: #eeeeee;
border-bottom: 1px solid #cccccc;
overflow: hidden;
}
.itemclass {
height: 100%;
width: auto;
background-color: #27ae60;
vertical-align: middle;
text-align: center;
color: white;
font-size: 2em;
margin-top: 0;
display: inline-block;
}
As a fallback, you can set .item to not show overflow, and then adjust the line-height of :
.item {overflow:hidden}
overflow: hidden; is your best friend in this case! It hides any overflow content from view outside of .item
Add it into .item {} declaration.
http://jsfiddle.net/1eg2cwLs/1/
I am very new to CSS, so excuse my naive mistakes.
Goal: Trying to make a simple and responsive layout. I am able to make the #container and #content responsive, but the fixed #header remains in-place and overflows when resizing the browser window. If you resize the browser window by pushing it to the left, you will see what I am talking about.
Also, side question: If I were to add an Image in the header, would the same (potential) solution apply? If you're curious about this kind of lay-out, I am trying to edit my "Tumblr" layout and I want to make it responsive (it's a private tumblr blog that I experiment on, I am not trying to make it responsive on cell phones / tablets – yet.)
Here is this JSFIDDLE: http://jsfiddle.net/yrbvw473/2/
HTML
<div id="container">
<div id="header">This Is The Header</div>
<div id="content">
<div class="post">A</div>
<div class="post">A</div>
<div class="post">A</div>
</div>
</div>
CSS
#container {
border: 0px solid;
max-width: 640px;
padding-left: 50px;
padding-right: 50px;
margin: auto;
display: block;
overflow-x: hidden;
}
#header {
margin-top: 0px;
margin-bottom: 0px;
position: fixed;
background-color: grey;
width: 640px;
z-index: 1;
text-align: center;
display: block;
}
#content {
width: 100%;
overflow-x: hidden;
clear: both;
border: 1px solid;
margin-top: 50px;
}
.post {
margin-bottom: 45px;
width: 100%;
border: 1px solid;
margin-top: 50px;
text-align: center;
}
Thank you for all the help! Again, I am new too this...
Comment or remove this position: fixed; on #header. And change width to max-width: 563px;
bcause u put the value of header width, that's why the header cannot flexible following browser width. use width:100% instead
SEE FIDDLE
I'm trying to make a menu bar centered horizontally in the header of my page. For some reason, i can't get the centering to work. I made a little test page roughly displaying the problem: JSFiddle. The inner div has to be 5px away from the bottom, that's whatI use the position: absolute for.
I've tried searching on the web alot, but everything I find gives me the same result, or none at all. Most problems I found were when text-align: center wasn't in the container div, but even with it, it still doesn't work.
I removed two css attributes and it work.
position: absolute;
bottom: 5px;
Check this Fiddle
5px from bottom. Fiddle
This is not a perfect way, but it's still kind of useful. I first think of this idea from this Q&A.
You'll have to make some change to your HTML:
<div id="container">
<div id="wrapper-center"> <!-- added a new DIV layer -->
<div id="inner_container">
TEXT ELEMETNES IN THIS THING!!!!
</div>
</div>
</div>
And the CSS will change to:
#container {
background: black;
width: 100%;
height: 160px;
position: relative;
}
#inner_container {
display: inline-block;
width: auto;
color: white;
background-color: #808080;
padding: 5px;
position: relative;
left:-50%;
}
#wrapper-center {
position:absolute;
left:50%;
bottom:5px;
width:auto;
}
Demo fiddle
The trick is to place the wrapper at the given top-bottom position, and 50% from left (related to parent), and then make the true content 50% to left (related to the wrapper), thus making it center.
But the pitfall is, the wrapper will only be half the parent container's width, and thus the content: in case of narrow screen or long content, it will wrap before it "stretch width enough".
If you want to centre something, you typically provide a width and then make the margins either side half of the total space remaining. So if your inner div is 70% of your outer div you set left and right margins to 15% each. Note that margin:auto will do this for you automatically. Your text will still appear to one side though as it is left-aligned. Fix this with text-align: centre.
PS: you really don't need to use position absolute to centre something like this, in fact it just makes things more difficult and less flexible.
* {
margin: 0;
padding: 0;
}
#container {
background: black;
width: 100%;
height: 160px;
}
#inner_container {
color:red;
height:50px;
width: 70%;
margin:auto;
text-align:center;
}
If you don't want a fixed width on the inner div, you could do something like this
#outer {
width: 100%;
text-align: center;
}
#inner {
display: inline-block;
}
That makes the inner div to an inline element, that can be centered with text-align.
working Ex
this CSS changes will work :
#container {
background: black;
width: 100%;
height: 160px;
line-height: 160px;
text-align: center;
}
#inner_container {
display: inline;
margin: 0 auto;
width: auto;
color: white;
background-color: #808080;
padding: 5px;
bottom: 5px;
}
Try this:
html
<div id="outer"><div id="inner">inner</div></div>
css
#outer {
background: black;
width: 100%;
height: 160px;
line-height: 160px;
text-align: center;
}
#inner{
display: inline;
width: auto;
color: white;
background-color: #808080;
padding: 5px;
bottom: 5px;
}
example jsfiddle
You may set the inline style for the inner div.
HTML:
<div id="container">
<div align="center" id="inner_container" style="text-align: center; position:absolute;color: white;width:100%; bottom:5px;">
<div style="display: inline-block;text-align: center;">TEXT ELEMETNES IN THIS THING!!!!</div>
</div>
</div>
Here is working DEMO