This question already has answers here:
What is the best way to move an element that's on the top to the bottom in Responsive design
(4 answers)
Closed 9 years ago.
I'm wondering if there is a way to change the order of HTML content depending on screen size.
This is the main website header, it shows correctly on every media query.
<h1>title</h1>
<nav>inline list items</nav>
<h2>subtitle</h2>
Basicly it looks like this:
H1 TEXT
H2 TEXT-----------------LIST ITEMS
(or check out http://www.jeroenduijker.nl/test/ and resize the screen)
As soon as the media query steps in (#media only screen and (max-width: 480px) {})
, the h2 gets squished, and i'd prefer to put the nav bar above the h1.
Is there an easy way to make the html go:
-----------------LIST ITEMS
H1 TEXT
H2 TEXT
Hopefully i've explained it well enough, i hope you can help me out, i'd appreciate it!
You could write two nav bars and have one hidden and the other visible, and then just switch that based on the media query.
HTML:
<nav class="show-mobile">
...
</nav>
<h1>title</h1>
<nav class="hide-mobile">
...
</nav>
<h2>subtitle</h2>
CSS:
#media only screen and (max-device-width: 480px) {
.show-mobile {
display: block;
}
.hide-mobile {
display: none;
}
}
#media only screen and (min-device-width: 481px) {
.show-mobile {
display: none;
}
.hide-mobile {
display: block;
}
}
Or two H1 elements, one before the nav and one after and have them switch visibility based on the media query.
<h1 class="hide-mobile"></h1>
<nav>
...
...
</nav>
<h1 class="show-mobile">Title</h1>
<h2>subtitle</h2>
Or you could tell the nav to have absolute positioning at the top when the mobile media query is active.
#media only screen and (max-device-width: 480px) {
nav {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 44px
}
}
Related
I'm trying to add a banner ad to run along the left side of my blog post.
However my attempts so far have resulted in it appearing above the content pushing the blog post content down the page.
Live link: https://www.moneynest.co.uk/pension-crisis-uk/
Added into head:
<div id=”LeftFloatAds”><img src="https://www.moneynest.co.uk/wp-content/uploads/2018/12/160x600b.png" alt="PensionBee sidebar ad"></div>
Added into CSS
#media only screen and (min-width: 1400px) and (max-width:500px) {
#LeftFloatAds{
left: 0px;
position: fixed;
text-align: center;
top: 200px;
}
}
FYI I followed this guide.
First of all, replace the position of ... move it inside your main content wrapper.
Then apply this css,
As you want to show this only on wider screen then use this,
#media only screen and (min-width: 1400px) {
#LeftFloatAds {
position: fixed;
display: block;
overflow: hidden;
left: 0;
top: 200px;
}
}
This will hide the banner on the screen smaller than 1400 pixels.
#media only screen and (max-width: 1399px) {
#LeftFloatAds {
display: none;
}
}
First, be careful with the div id quotes.
<div id=”LeftFloatAds”> should be <div id="LeftFloatAds">
Then, with that media query you are giving those properties to the element only when the screen is at least 1400px but less than 500px, which is impossible. Try it like this:
#media only screen and (min-width: 500px) and (max-width:1400px)
could you please tell me how to make logo at center in using css.Actually I am using media query for mobile view .In desktop my html is working fine , but in mobile view
I want to show logo on center and have two menu option side by side (see below image).
here is my code
#media screen and (max-width: 480px) and (min-width:320px) {
.header{
background: #00B7FF;
flex-direction: column;
}
}
https://stackblitz.com/edit/js-wcvzbw?file=style.css
Assuming you want to center it vertically, adding margin: auto; should do the trick in a flex column layout.
You could make the container width to 100%.
#media screen and (max-width: 480px) {
.container {
width: 100%;
}
}
And then align the header to center.
#media screen and (max-width: 480px) {
.header{
text-align: center;
}
}
You can see the example here.
I am currently creating a website that has media queries. I already have a normal navigation however when the webpage size reduces to a mobile size, I would like for the navigation to switch to another navigation bar which I have created, which includes icons which makes it easier for mobile users
#media only screen and (min-width : 50px) {
<div class = "navbar">
<img src="Images/houseicon.png"/>
<img src="Images/educationicon.png"/>
<img s**strong text**rc="Images/contactmeicon.png"/>
</div>}
You don't need to add html to media query...
Html is part of html page
You just need to set below css with media query in your css file or in your tag.
#media only screen and (max-width : 767px) { .navbar a img{ width:50px !important; height:50px !important;}}
Use below code to show navigation properly on responsiveness mobile view.
Code::
`#media only screen and (min-width: 320px) and (max-width: 480px) {
.nav img {
height: 100px;
width: 100px;
}
} `
Note:: height: 100px; and width: 100px;
100px, is just for reference, please update height and width with your actual image size.
My website is https://salesportalasia-testsite.azurewebsites.net
When view using mobile there is white space at header.
I have check the margin-top code in css but not success.
Can someone please help me solve this problem...
You have a inlined style padding-top: 211px on div with id="page". Remove it, and this white space will disappear.
Assign padding-top:0px !important; in mediaqueries
#media (max-width: 767px){
.wrapper {
padding-top:0px !important;
}
}
If you inspect the page in mobile view, you will see that some inline styling is being applied to <div id="page" style="padding-top: 160px"></div>.
It looks like it is being set in custom.min.js in the setNavigationOffset function.
I hope that helps.
I noticed you have padding-top:160px in top.
element.style {
padding-top: 160px;
}
In the page it looks like hardcoded inside theme page,
Its possible you have different padding-top in different mobile devices so please check that and resolve it according the device. That will helpful.
Use this css code for removing the padding top which results in the white space.
#page{
padding-top:0px !important;
}
Problem you are facing due to multiple positioning of navigation element.
#media (max-device-width: 800px) and (orientation: portrait)
#media (max-width: 767px)
style.css?ver=4.7.5:7526
.navigation {
position: relative!important;
}
This above class overwrite your fixed position class value.
.navigation-fixed-top .navigation {
top: 0;
position: fixed; /* This not work
bottom: inherit;
}
Here if you want to overcome. Just simply remove relative class
TO REMOVE
#media (max-device-width: 800px) and (orientation: portrait)
#media (max-width: 767px)
style.css?ver=4.7.5:7526
.navigation {
position: relative!important;
}
Otherwise if you want to use above class. Remove ! important keyword.
Change like this.
#media (max-device-width: 800px) and (orientation: portrait)
#media (max-width: 767px)
style.css?ver=4.7.5:7526
.navigation {
position: relative;
}
So navigation element automatically get the fixed class value based on priority..
Hops it helps.!
I am working on taking my desktop site and scaling it down for mobile. The site is incredibly static, so the process shouldn't take long. I'm not used to scaling down to mobile though, so I am in a bit of a learning curve and was seeking some help. I have my menu in place where the mobile menu displays and the desktop menu hides when the screen is sized down:
#media (min-width: 220px) and (max-width: 568px) {
#menu ul, #logo, #header{
display: none;
}
vice-versa goes for when the desktop is in place and it hides the mobile nav:
#media (min-width: 569px) {
.navbar{
display: none;
}
}
However, when I am tweaking my CSS to alter my mobile view, my first run-in is with simply just displaying my content (in this case my 'about' content) to fit the screen. My fluidity in desktop isn't ideal, but it works as needed on all displays from tablets and beyond. I bare-boned the About page to just have my text and a horizontal break being displayed in order to troubleshoot the issue, but the text still follows the rules set by the CSS for the desktop version. Here is the #media rule to size for mobile:
#media (min-width: 220px) and (max-width: 568px) {
#menu ul, #logo, #header{
display: none;
}
.about_text{
width: 100%;
}
.about_text h2{
font-size: 3em;
padding-bottom: 1%;
}
.breaker-about{
clear: both;
border-bottom: 3px solid #cccccc;
margin: 5px 0px 12px 0px;
width: 90%;
}
}
#media (min-width: 569px) {
.navbar{
display: none;
}
}
Do I need to encompass the entire CSS in the #media (min-width: 569px) media query from here on out? Or does that act as a single standalone 'if/then' rule?
Here's my fiddle. Using bootstrap for top nav, so that's why the resize down to size doesn't stylize on fiddle.
https://jsfiddle.net/qu4851wq/1/
You don't need the (min-width: 220px) for mobile, just the (max-width: 568) is enough. If you're using Bootstrap, you can just put your entire contents into a grid and it will automatically scale for mobile.
<div class="container">
<div class="row">
<div class="col-md-12">
<!-- All your content after the nav -->
</div>
</div>
</div>
You don't have to place the entirety of your CSS in a min-width for the non-mobile portion of the site.
Or you can just use bootstrap default navigation and style it like you want.
bootstrap nav