Removing blank spaces on window.print()

时间:2018-07-24 10:13:59

标签: html css

I am trying to remove blank spaces which showing only on window.print();

here

Blank spaces are inputs hidden with css class like this:

@media screen {
    .hide-from-screen {
        display: none;
    }
}
@media print {
    .hide-from-printer {
        display: none;
    }  
}

So they are hidden which is good, but instead of hidding blank spaces are added. Is there some solution for this?

2 个答案:

答案 0 :(得分:0)

尝试增加高度和相同的高度!

@media print {
    .hide-from-printer {
        display: none !important;
        height: 0px;
    }  
}

答案 1 :(得分:0)

我尝试了您的CSS和一些HTML,效果很好。 您应该class="hide-from-printer"<div>隐藏<div>,这不需要显示。

如果要显示一些@media print { #printOnly { display : block; } } ,请使用CSS波纹管:

def my_model(features, labels, mode):
    # define simple dense network
    net = tf.layers.dense(features['x'], units=8, activation=tf.nn.tanh)
    net = tf.layers.dense(net, units=8, activation=tf.nn.tanh)
    net = tf.layers.dense(net, units=8, activation=tf.nn.tanh)
    net = tf.layers.dense(net, units=8, activation=tf.nn.tanh)
    net = tf.layers.dense(net, units=8, activation=tf.nn.tanh)
    net = tf.layers.dense(net, units=8, activation=tf.nn.tanh)
    net = tf.layers.dense(net, units=8, activation=tf.nn.tanh)
    net = tf.layers.dense(net, units=8, activation=tf.nn.tanh)

    # output layer
    predictions = tf.layers.dense(net, units=1, activation=tf.nn.tanh)

    if mode == tf.estimator.ModeKeys.PREDICT:
        # define output message for tensorflow serving
        export_outputs = {'predict_output': tf.estimator.export.PredictOutput({"predictions": predictions})}

        return tf.estimator.EstimatorSpec(mode=mode, predictions={'predictions': predictions}, export_outputs=export_outputs)
    elif mode == tf.estimator.ModeKeys.EVAL:
        # for evaluation simply use mean squared error
        loss = tf.losses.mean_squared_error(labels=labels, predictions=predictions)
        metrics = {'mse': tf.metrics.mean_squared_error(labels, predictions)}

        return tf.estimator.EstimatorSpec(mode, loss=loss, eval_metric_ops=metrics)
    elif mode == tf.estimator.ModeKeys.TRAIN:
        # train on mse with Adagrad optimizer
        loss = tf.losses.mean_squared_error(labels=labels, predictions=predictions)
        optimizer = tf.train.AdagradOptimizer(learning_rate=0.1)
        train_op = optimizer.minimize(loss, global_step=tf.train.get_global_step())

        return tf.estimator.EstimatorSpec(mode, loss=loss, train_op=train_op)
    else:
        raise ValueError("unhandled mode: %s" % str(mode))


def main(_):
    # prepare training data
    default_batch_size = 50
    examples = [{'x': x, 'y': math.sin(x)} for x in [random.random()*2*math.pi for _ in range(10000)]]

    estimator = tf.estimator.Estimator(model_fn=my_model,
                                       config=tf.estimator.RunConfig(model_dir='sin_model',
                                                                     save_summary_steps=100))

    # function converting examples to dataset
    def dataset_fn():
        # returns a dataset serving batched (feature_map, label)-pairs
        # e.g. ({'x': [1.0, 0.3, 1.1...]}, [0.84, 0.29, 0.89...])
        return tf.data.Dataset.from_generator(
            lambda: iter(examples),
            output_types={"x": tf.float32, "y": tf.float32},
            output_shapes={"x": [], "y": []}) \
            .map(lambda x: ({'x': [x['x']]}, [x['y']])) \
            .repeat() \
            .batch(default_batch_size)

    # function to export model to be used for serving
    feature_spec = {'x': tf.FixedLenFeature([1], tf.float32)}
    def serving_input_fn():
        serialized_tf_example = tf.placeholder(dtype=tf.string, shape=[default_batch_size])

        receiver_tensors = {'examples': serialized_tf_example}
        features = tf.parse_example(serialized_tf_example, feature_spec)
        return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)

    # train, evaluate and export
    train_spec = tf.estimator.TrainSpec(input_fn=dataset_fn, max_steps=1000)
    eval_spec = tf.estimator.EvalSpec(input_fn=dataset_fn,
                                      steps=100,
                                      exporters=[tf.estimator.FinalExporter('sin', serving_input_fn)])

    tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

if __name__ == '__main__':
    tf.app.run(main)