我有一个css媒体查询,它可以调整和重新定位div。在我的html中,div有2行,但在较小的屏幕上,我希望它显示为1行。
有没有办法确保我有:
Website Visitors: <?php echo $data; ?>
<div class="fb-like"></div>
代替:
Website Visitors: <?php echo $data; ?>
<br/>
<div class="fb-like"></div>
当屏幕小于固定数量(在本例中为460px)时?
我想使用php或css,因为它们是我在cs.php文件中使用的样式。
删除<br/>
并将其添加到css中(值可以是您想要的任何值):
.fb-like {
margin-top: 10px;
}
以及在您的媒体查询中:
.fb-like {
margin-top: 0px;
}
不可能使用完整的PHP,您可能也需要使用Javascript!!您可以尝试以下代码来获取屏幕宽度和高度!!!
<?php
session_start();
if(isset($_SESSION['screen_width']) AND isset($_SESSION['screen_height'])){
echo 'Screen resolution: ' . $_SESSION['screen_width'] . 'x' . $_SESSION['screen_height'];
} else if(isset($_REQUEST['width']) AND isset($_REQUEST['height'])) {
$_SESSION['screen_width'] = $_REQUEST['width'];
$_SESSION['screen_height'] = $_REQUEST['height'];
header('Location: ' . $_SERVER['PHP_SELF']);
} else {
echo '<script type="text/javascript">window.location = "' . $_SERVER['PHP_SELF'] . '?width="+screen.width+"&height="+screen.height;</script>';
}
?>