我有一個差距正好低於我的第一個預標籤我無法刪除它。無法刪除保證金引導
我已經試過
pre {
margin: 0 0 0;
}
而且
pre {
margin: 0 0 0 !important;
}
但仍顯示
問題:怎麼可能正確刪除邊緣或填充 剛剛低於第一個預先?
注:剛剛發現是與nl2br的控制器功能如下
我用笨和Ajax生成預覽。
CSS
<style type="text/css">
body {
background-color: #F0F0F0;
}
pre {
display: block;
padding: 9.5px;
margin: 0 0 0 !important;
font-size: 13px;
line-height: 1.42857143;
color: #333;
word-break: break-all;
word-wrap: break-word;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
}
hr {
background-color: #dedede !important;
height: 1px !important;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0;
padding: 0;
font-family: Roboto,"Helvetica Neue",Helvetica,Arial,sans-serif;
margin-top: 0;
}
</style>
腳本
<script type="text/javascript">
$('#preview-question').on('click', function (e) {
$.ajax({
url: "<?php echo base_url('question/preview');?>",
type: 'POST',
data: {
title: $('#title').val(),
question: $('#question').val(),
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
},
dataType: 'json',
success: function(response){
if (response.success) {
$('#preview').html(response.question);
$('#preview pre br').remove();
var str = $('#preview pre').html();
$('#preview pre').html(str.replace(/</g, "<").replace(/>/g, ">"));
$('pre').each(function(i, block) {
hljs.highlightBlock(block);
});
} else {
}
}
});
e.preventDefault();
});
</script>
功能
public function preview() {
$data = array('success' => false, 'question' => '');
if ($_POST) {
$data['question'] = nl2br($this->input->post('question'));
$data['success'] = true;
}
echo json_encode($data);
}
FULL HTML
<?php echo form_open_multipart('question/create', array('id' => 'question_create', 'class' => 'form-horizontal', 'role' => 'form'));?>
<div class="container">
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title"></h1>
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-lg-2">Title</label>
<div class="col-lg-10">
<input type="text" name="title" id="title" class="form-control" placeholder="Title" />
</div>
</div>
<div class="form-group">
<label class="col-lg-2">Question</label>
<div class="col-lg-10">
<textarea name="question" id="question" class="form-control" rows="10"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-lg-2"></label>
<div class="col-lg-10">
<div id="preview"></div>
</div>
</div>
</div>
<div class="panel-footer">
<div class="text-center">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="button" id="preview-question" class="btn btn-default">Preview</button>
<button type="button" class="btn btn-warning">Clear Textarea</button>
<a href="" class="btn btn-danger" role="button">Cancel</a>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$('#preview-question').on('click', function (e) {
$.ajax({
url: "<?php echo base_url('question/preview');?>",
type: 'POST',
data: {
title: $('#title').val(),
question: $('#question').val(),
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
},
dataType: 'json',
success: function(response){
if (response.success) {
$('#preview').html(response.question);
$('#preview pre br').remove();
var str = $('#preview pre').html();
$('#preview pre').html(str.replace(/</g, "<").replace(/>/g, ">"));
$('#preview pre').each(function(i, block) {
hljs.highlightBlock(block);
});
} else {
}
}
});
e.preventDefault();
});
</script>
<?php echo form_close();?>
它與控制器功能上的nl2br有關 – user4419336
您能否給我在瀏覽器中元素的HTML? – djl
@djl我注意到它與控制器 – user4419336