music1996taro
@music1996taro

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

HTML&CSS メディアクエリ

メディアクエリ内にレイアウト用の記述を追加すればスマートフォンで見たときだけサイドバーを隠して1カラムにすることもできるとは、どういう記述をすれば良いのでしょうか?出典先は、そろそろ常識?
マンガでわかるHTML&CSSです。
赤松公太郎著
です。その第6章の所です。その6章最後のページです。教えて頂けると幸いです。
respon.html
〈!DOCTYPE html〉
〈html lang=″ja″〉
〈head〉
〈meta charset=″utfー8″〉
〈meta name=″viewport″ content=″width=deviceーwidth,initialーscale=1″〉
〈title〉Campus Art〈/title〉
〈link rel=″stylesheet″ href=″style.css″〉
〈/head〉
style.css
@media (maxーwidth: 599px){

main{
width: 90%;
}
main img
width: 100%;
}
}
です。メディアクエリに関するのは。教えて頂けると幸いです。スマートフォンの幅は、400〜600pxと書いてあるのですが、画面幅が、最小600pxと仮定し、ブレークポイントを599pxにしているで、なぜ、最小になっているのでしょうか?最大の間違いだと思うのですが。あなた様はどう思いますか?すみません。話がズレました。ですが、追加で書かれていたのです。

0

2Answer

To hide the sidebar and make it a single column layout when viewed on a smartphone (for screens with a width of 599px or less), you can modify your CSS with the correct media query. Here's how you should do it:

First, ensure that your HTML structure includes both a main content area and a sidebar, like this:

html

Now, update your style.css to hide the sidebar when the viewport width is 599px or smaller and adjust the layout to make it single-column:

css
@media (max-width: 599px) {
main {
display: block; /* Ensure the main element becomes a block */
width: 90%;
}

.sidebar {
display: none; /* Hide the sidebar on small screens */
}

.content {
width: 100%; /* Content will take up the full width */
}
}
This media query ensures that when the screen width is 599px or smaller (which is common for smartphones), the sidebar is hidden, and the content section takes up the full width, effectively creating a single-column layout.

Regarding the breakpoint of 599px:
The reason why a max-width of 599px is used in media queries for smartphones is because the screen width of smartphones generally ranges from 400px to 600px. Setting the breakpoint to 599px helps target devices with smaller screens, but it is not about the "minimum" screen width. The reason it's written as "max-width: 599px" is to target any screen smaller than or equal to 599px, so devices within the range (e.g., phones) get the single-column layout while larger screens, like tablets or desktops, will maintain their multi-column layouts.

Your concern is understandable, but the breakpoint is commonly set like this to accommodate phones with smaller screens, ensuring that they have a user-friendly, responsive design

0Like

Your answer might help someone💌