Bootstrap: How to force form-inline on mobile?

I am creating a simple web page using Bootstrap v3.3.1. I am stuck trying to force form-inline

in mobile. It doesn't turn into an inline form like I want.

How do I form-inline

also work with a mobile view?

Demo

My codes:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Hello World</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/style.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <!-- Page Content -->
    <div class="container full">
        <div class="row">
            <div class="col-md-12">
                <h1 class="text-center hero">Mauris risus nisi, hendrerit id orci non, tempor hendrerit enim</h1>
            </div>
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container -->

    <div class="container dropdown-section">
        <div class="row">
            <div class="col-md-6 col-md-offset-3 dropdown-wrapper">

                <form class="form-inline">
                    <div class="form-group">
                        <input type="email" class="form-control input-lg date-input" id="exampleInputEmail2" placeholder="Date">
                    </div>
                    <!-- Single button -->
                    <div class="btn-group">
                        <button type="button" class="btn btn-default btn-lg dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            Moving from <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#">Action</a>
                            </li>
                            <li><a href="#">Another action</a>
                            </li>
                            <li><a href="#">Something else here</a>
                            </li>
                            <li class="divider"></li>
                            <li><a href="#">Separated link</a>
                            </li>
                        </ul>
                    </div>
                    <!-- Single button -->
                    <div class="btn-group">
                        <button type="button" class="btn btn-default btn-lg dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                            Moving to <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#">Action</a>
                            </li>
                            <li><a href="#">Another action</a>
                            </li>
                            <li><a href="#">Something else here</a>
                            </li>
                            <li class="divider"></li>
                            <li><a href="#">Separated link</a>
                            </li>
                        </ul>
                    </div>
                    <button class="btn btn-primary btn-lg" type="submit">Search</button>
                </form>

            </div><!-- /col-md-6 col-md-offset-3 dropdown-wrapper -->
        </div><!-- /.row -->
    </div><!-- /.container -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

</body>
</html>

      

style.css

body {
    background: none;
}

.full {
    background: url(http://i.imgur.com/BwqePti.jpg) no-repeat center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    min-height: 400px;
    width: 100%;
    z-index: 1;
}

.text-center {
    text-align: center;
}

h1.hero {
    margin-top: 170px;
    color: #ffffff;
    text-shadow: 2px 2px 2px rgba(150, 150, 150, 0.8);
    font-family: 'Arvo', serif;
    font-size: 30px;
}

.dropdown-section{
    width: 100%;
    background-color: #000000;
}

.dropdown-wrapper{
    margin-top: 20px;
    margin-bottom: 20px;
}

.date-input{
    width: 220px !important;
}

      

Desktop: enter image description here

Mobile view:

enter image description here

+3


source to share


2 answers


Your form elements are inline (more likely inline-block), but their combined width is larger than the mobile view. If you want to limit them to one line (which doesn't seem like a great idea given the available space), you need to set the width on them. I would recommend interest. Whitespace between items will cause problems with this method if you don't comment on it or factor it into your measurements.



I think your problem is pushing you in the right direction. On such a small screen, the input data is better distributed this way. If I were you, I would expand the Search button and input date to 100% on mobile, and reset the width with a media query on desktop / large tablets.

+3


source


You can add custom CSS to these input and button elements. Add display: inline-block

to these and you can remove the inline form.



0


source







All Articles