1
Does anyone know how I can make an element with position: fixed;
be responsive. That is, the contents on the left remain on the left and the contents on the right, when resized, remain on the right off-canvas
?
That’s a sketch of what I’m trying to do:
HTML
<header>
<div class="content">
<img src="http://seeklogo.com/images/L/Light_Logomarca-logo-0C4DF9D65C-seeklogo.com.gif" alt="logo" />
<ul class="menu">
<li>menu-item</li>
<li>menu-item</li>
<li>menu-item</li>
</ul>
</div>
</header>
<main>
<div class="content">
<h1>Conteúdo</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illum cupiditate nisi minus quis, excepturi corrupti repellat magni error rem possimus et mollitia at sunt, numquam, omnis expedita. Rem libero, officiis!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illum cupiditate nisi minus quis, excepturi corrupti repellat magni error rem possimus et mollitia at sunt, numquam, omnis expedita. Rem libero, officiis!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illum cupiditate nisi minus quis, excepturi corrupti repellat magni error rem possimus et mollitia at sunt, numquam, omnis expedita. Rem libero, officiis!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illum cupiditate nisi minus quis, excepturi corrupti repellat magni error rem possimus et mollitia at sunt, numquam, omnis expedita. Rem libero, officiis!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illum cupiditate nisi minus quis, excepturi corrupti repellat magni error rem possimus et mollitia at sunt, numquam, omnis expedita. Rem libero, officiis!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illum cupiditate nisi minus quis, excepturi corrupti repellat magni error rem possimus et mollitia at sunt, numquam, omnis expedita. Rem libero, officiis!</p>
</div>
</main>
CSS
header {
position: fixed;
top: 0;
width: 100%;
min-width: 700px;
border: 1px solid black;
background-color: #ccc;
}
.logo {
display: inline-block;
}
img {
float: left;
width: 70px;
height: 70px;
max-width: 100%;
}
.menu {
float: right;
}
.menu li {
display: inline-block;
border: 1px solid black;
padding: 5px;
}
.content {
width: 700px;
margin: 0 auto;
}
main {
margin-top: 150px;
}
I achieved the desired effect by changing the position: fixed;
for position: absolute;
, only that header does not get fixed at the top of the screen.
CODEPEN with the editable code.
Post the code of what you’ve done so far
– Bia
@Bia in the question description has a link to the codepen.io with the code done so far. You are at this link http://codepen.io/luandacostadf/pen/mVmyYd?editors=110
– Luan da Costa Silva
@Luandacostasilva read it several times, but I couldn’t understand what you want to do, be more specific, I’ll try to help you.
– Tamiris
@Luandacostasilva Welcome to SOPT! Try not to refer your code to another site, put it in here even with the method
code
. In response to your post, in case you want a "responsive menu" I am correct? If yes, I will try to help you.– Lucas Henrique
@Tamiris I added an image trying to explain the problem better
– Luan da Costa Silva
@Luandacostasilva have you ever heard of media queries? See my amendment here https://jsfiddle.net/f3t4foL0/ - Remembering that this is an expressed "solution" that serves more to make you understand what Media Queries are and what is Responsive.
– Lucas Henrique
Where is the code? The site has tool for posting codes, it is not recommended to post externally, unless as additional information to a code already posted here.
– user28595
@Lucashenrique Thanks for the tip, in the next post I put the code here in the stack, so I can not have a responsive menu, the idea is that the horizontal scroll bar exists, but as shown in the image the header content does not accompany this bar, to understand better see: https://jsfiddle.net/LuanCostaSilva/xqkytsbn/, now resize the page until you create a horizontal bar, now slide the horizontal bar to the end, see? you do not see the contents of the menu, now switch from Fixed to Absolute and do the same thing, the content appears but the header does not always stay at the top. Some solution?
– Luan da Costa Silva
@Luandacostasilva you read Lucas Henrique’s comment?
– Renan Gomes