rearranging 3 divs with css

穿精又带淫゛_ 提交于 2019-12-23 01:43:07

问题


I want to change the order of two divs. The HTML:

<div>container
<div> Navigation backwards </div>
<div> Social buttons </div>
<div> Navigation forwards </div>
</div>

Looks like this on a big screen: <-- [social] -->

I need to change that for small (mobile) devices to:
<-- -->
[social]

Is this possible with pure css? I could just add some HTML and solve it with display: none, but that's an ugly solution imo.


回答1:


So @acudars is right... but there's some things to consider here. One thing is that the order of your markup will make it tricky to achieve this... so by adding the social buttons at the bottom you can assure this will be easier to achieve.

I went ahead and made a jsFiddle: Demo

HTML

<div class="navCont">
  <div class="arrowPrev">&larr;</div>
  <div class="arrowNext">&rarr;</div>
  <div class="socialButtons">Social Buttons</div>
</div>

CSS

.navCont {
    background: #f6f6f6;
    border-radius: 5px;
    clear: both;
    overflow: hidden;
    padding: 5px 10px;
}

.arrowPrev {
    float: left;
}

.socialButtons {
    text-align: center;
}

.arrowNext {
    float: right;
}


@media (max-width: 320px) {
  .socialButtons {
    float: none;
    clear: both;
  }
}

So lets say that you are targeting mobile devices at 320px width... just go ahead and resize the fiddle to see this in action.

The CSS is very straight forward and I just added a little style to make it clear.




回答2:


/* Large desktop */
@media (min-width: 1200px) { ... }

/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) { ... }

/* Landscape phone to portrait tablet */
@media (max-width: 767px) { ... }

/* Landscape phones and down */
@media (max-width: 480px) { ... }



回答3:


You might find this useful.

This link shows different types of css styles depending on the media (depending on the size of the view screen). http://css-tricks.com/resolution-specific-stylesheets/

:)



来源:https://stackoverflow.com/questions/17875645/rearranging-3-divs-with-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!