CSS: div different position in mobile view - html

My desktop webpage has the following design:
---------------------
|elem1|elem2|tabs |
| | |-------|
| | |t1 | t2|
| | | |
---------------------
Tabs is a container provided by Bootstrap (http://getbootstrap.com/javascript/#tabs); t1 and t2 are some tabs inside that container.
Now I want to create a responsive design, so if the user switches to the mobile view the website should look the following (portrait mode):
-------------
|elem2 |
|-----------|
|tabs |
|-----------|
|elem1|t1|t2|
-------------
So basically I want that elem1 (left in the desktop) moves into my tab container and becomes a tab itself (or at least the content of a tab that is only visible in the mobile view). Is this even possible with a CSS-only solution?
First I thought about putting creating the elem1 twice and display the correct one depending on the screen size but I don't like that solution due to maintenance.

Related

Wrap text consistently in table cells

I have an HTML table with a column of cells containing two parts e.g.
| Cat (meow) |
+---------------------------+
| Long-dinosaur-name (roar) |
There are also other columns not shown. My users' browsers have unknown widths. On a wide one, I wish to show the cell as one line, as above. If it gets too narrow, I'm fine with wrapping
| Cat |
| (meow) |
+----------+
| Long- |
| dinosaur-|
| name |
| (roar) |
but if one line wraps, all lines must also wrap:
| Cat |
| (meow) |
+---------------------+
| Long-dinosaur-name |
| (roar) |
Without using Javascript, is it possible to do this?
I know I can use <td nowrap> to prevent wrapping, or <br> to force a wrap, but how can I make one cell depend on another?
Try using media query(CSS) with breakpoints. I know you said, the user browsers width's are unknown, but you can anticipate for different width's etc

Responsive column layout with CSS/HTML

I'm trying to achieve following layout with HTML/CSS, where the navigation elements "A" and "C" are situated above the main content "B" on small screen and distributed corresponding to the left "A" and right "C" on larger screens.
My goal is to use constant HTML-elements and only change CSS-styles based on media-queries.
How to achieve this?
Mobile Desktop
(small screen) (large screen)
+-------------------+ +-----------------------------------+
| A | C | | A | B | C |
+-------------------+ +---------+ +---------+
| B | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+-------------------+ +---------------+
HTML
<div>
<div>A</div>
<div>B</div>
<div>C</div>
</div>
I think flexbox would help here:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Set a display: flex on the container div and play a bit with the alignment as described in the linked article.
Use media queries on css.
#media (max-width: 600px) {
//Display as u want the tables or divs for small devices
//Change width as desired
}
#media (min-width: 601px) {
//Display as u want the tables or divs for big devices or desktop
//Change width as desired
}
Using HTML and CSS only, we can't achieve this requirement. If you use bootstrap in your code. You can able to achieve.
In bootstrap, we have responsive utilities concept is there using that you can build your above requirement
For your reference

Creating a responsive navbar with two rows

I am trying to create a responsive Bootstrap 3 based navbar with two rows. However, I am having trouble with the structure of the HTML and the collapse functionality.
Below is a visual description of the desired result, and I was hoping someone could point me in the right direction in terms of HTML/CSS (with as much default Bootstrap functionality as possible).
DESKTOP :
|---------------------------------------------------------------|
| LOGO | (MD DROPDOWN MENU)| | A-Option1 | A-Option2 |
|---------------------------------------------------------------|
| | B-Option1 | B-Option2 |
|---------------------------------------------------------------|
MOBILE
|----------------------------------------|
| LOGO | |A-Option1|A-Option2 |
|----------------------------------------|
| (MD DROPDOWN MENU)| HaMBuRGER |
|----------------------------------------|
Thanks a lot for your help

Dynamic width with fixed column

I am trying to create a page that has a width that adjusts to the screen with a fixed width column on the right. So for example:
| | |
|-------Content------|--Column--|
| | |
| | |
|---Content---|--Column--|
| | |
| | |
|-----Content----|--Column--|
| | |
http://www.reddit.com/ would be a good example of this.
Thanks
This blog is pretty useful for grabbing complex layouts.
ultimate-2-column-right-menu-pixels
this is essentially what reddit does: http://jsfiddle.net/pxfunc/rCG84/
the side div 1.) is above content in the html, 2.) is set to float:right;, and 3.) given a specific width (width:300px)
<div id="side"></div>
<div id="content"></div>
the content div will adjust with the window size

right-align and left-align to the center column

This is a tricky question, but I will do my best to ask it:
I have a middle column of content and I want to add columns to the left and right of it, but I want them to "hug" the middle column. How can I center the middle column always and have the other two columns "hug" it?
The columns have a fixed width of 750px and basically when the viewport is maximized it should be something like this on a big monitor:
-------------------------------------
| | | | | |
| | | | | |
| | left | mid | right | |
| | | | | |
| | | | | |
-------------------------------------
and when the window is not wide enough, the left and right columns should get cut-off, but the middle column should still be centered and visible (assuming they don't make it too small horizontally):
-------------
| | | |
| | | |
le|ft | mid | ri|ght
| | | |
| | | |
-------------
Where "le" and "ght" are off-screen and not visible in the viewport.
I'm interested in any ways of accomplishing this. Currently I'm using
margin-left: auto;
margin-right: auto;
to center the middle column, but if there are ways to accomplish this without that, by all means =)
Thanks for reading this tricky question. I hope I got my idea across.
(If you can think of a better question title, feel free to edit it. I wasn't sure what to put)
P.S. Each column is actually made up of a few divs itself, (blocks that make up a column), I'm not sure if that makes the problem any easier to solve, or if that totally changes the problem...
Something like this ? http://jsfiddle.net/ndtLX/
i'm using an absolute positioned div above 2 floated divs, each large 50% of the container.
the problem is that on the left and right columns, the off-screen happen on the other side, and not on the same side as you asked...
You could also try floats to see if that gives you what you want
.divLeftCol
{
float: left;
}
.divRightCol
{
float: right;
}
<div class="divLeftcol"></div>
<div class="divCenter"></div>
<div class="divRightcol"></div>